classMarkdownDocument
final class MarkdownDocument
Reads a definition written as Markdown cards and writes it back in the same form.
The YAML frontmatter holds the version and source; each top-level heading is an item ID followed by badges, a statement, quoted evidence and bold field sections. What the author chose beyond the data model, such as badge images and link targets, is remembered so that formatting reproduces it.
Methods§
public function __construct()Starts with nothing remembered; each read replaces what the previous one remembered.
Calls 1
- new Presentation line 44
public function read(
string $file,
array<string, mixed> $options,
string|null $directory = null,
): stdClassReads a Markdown definition into the same shape as a YAML definition.
Parameters
$file | string | The definition file |
$options | array<string, mixed> | The markdown options; experimental must be true |
$directory | string|null | The configuration directory that the source URI resolves against |
Returns
stdClass The definition with its itemsThrows
InvalidInputException When Markdown is not enabled or the document breaks the card syntaxJsonException When the source cannot be convertedParseException When the frontmatter is malformed YAMLTest cases 10
MarkdownDocumentTest::testReadReadsACardDefinitionWithoutASourcecallsMarkdownDocumentTest::testReadRejectsABodyThatIsNotUtf8callsMarkdownDocumentTest::testReadRejectsOptionsWithoutTheOptIncallsMarkdownDocumentTest::testReadRejectsUnknownMarkdownOptionscallsMarkdownDocumentTest::testReadResolvesTheSourceAgainstTheConfigurationDirectorycallsMarkdownDocumentTest::testReadResolvesTheSourceAgainstTheFileDirectoryByDefaultcallsMarkdownDocumentTest::testReferencesReturnsTheLinksOfTheLastReadcallsMarkdownDocumentTest::testRenderForgetsWhatAnEarlierReadRememberedcallsMarkdownDocumentTest::testRenderKeepsBadgeValuesWithSeparatorsAndUnicodecallsMarkdownDocumentTest::testRenderKeepsEmptyListsAndStructuredMetadatacalls
Called from 1
Calls 20
- new InvalidInputException line 63
- static-call Fields::keys() line 65
- new Presentation line 66
- method-call Frontmatter::read() line 68
- new Frontmatter line 68
- static-call Fields::mapping() line 70
- function-call
json_decodeline 70 - function-call
json_encodeline 70 - new Citation line 71
- static-call Source::from() line 71
- function-call
dirnameline 71 - new
Environmentline 73 - method-call
Environment::addExtension()line 74 - new
CommonMarkCoreExtensionline 74 - method-call
MarkdownParser::parse()line 76 - new
MarkdownParserline 76 - method-call DocumentSchema::validate() line 80
- new DocumentSchema line 80
- method-call CardReader::cards() line 81
- new CardReader line 81
public function references(): list<Reference>Returns the links to other items found by the last read.
Returns
list<Reference> The links, checked once every definition is loadedTest cases 1
public function render(stdClass $data): stringWrites a definition as Markdown cards, reusing what the last read remembered.
Parameters
$data | stdClass | The definition |
Returns
string The Markdown textThrows
InvalidInputException When a record cannot be written as a cardJsonException When a metadata value cannot be encodedTest cases 5
MarkdownDocumentTest::testReadResolvesTheSourceAgainstTheConfigurationDirectorycallsMarkdownDocumentTest::testRenderForgetsWhatAnEarlierReadRememberedcallsMarkdownDocumentTest::testRenderKeepsBadgeValuesWithSeparatorsAndUnicodecallsMarkdownDocumentTest::testRenderKeepsEmptyListsAndStructuredMetadatacallsMarkdownDocumentTest::testRenderWritesNewBadgesWithoutAReadcalls
Calls 2
- method-call CardWriter::render() line 107
- new CardWriter line 107
Private surface 2§
Implementation details, listed for orientation only.
private Presentation $presentationprivate ?Citation $source = nullTest cases 26§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 11
MarkdownDocumentTest::testReadReadsACardDefinitionWithoutASourcecallsMarkdownDocumentTest::testReadRejectsABodyThatIsNotUtf8callsMarkdownDocumentTest::testReadRejectsOptionsWithoutTheOptIncallsMarkdownDocumentTest::testReadRejectsUnknownMarkdownOptionscallsMarkdownDocumentTest::testReadResolvesTheSourceAgainstTheConfigurationDirectorycallsMarkdownDocumentTest::testReadResolvesTheSourceAgainstTheFileDirectoryByDefaultcallsMarkdownDocumentTest::testReferencesReturnsTheLinksOfTheLastReadcallsMarkdownDocumentTest::testRenderForgetsWhatAnEarlierReadRememberedcallsMarkdownDocumentTest::testRenderKeepsBadgeValuesWithSeparatorsAndUnicodecallsMarkdownDocumentTest::testRenderKeepsEmptyListsAndStructuredMetadatacallsMarkdownDocumentTest::testRenderWritesNewBadgesWithoutAReadcalls
Other tests reaching this symbol 15
MarkdownCommandTestcallsDefinitionReaderTestcallsDocumentReaderTest::testMarkdownIsTheGivenDocumentcallsLoaderTestcallsReferenceTestcallsSchemaValidatorTestcallsApplicationTestcallsCommandHandlerTestcallsCommandLineTestcallsExecutorTestcallsFormatterTestcallsAnalyzerTestcallsCoverageTestcallsSnapshotTestcallsVerifierTestcalls