Behaviour SwRS-MDOKFSTUDIO-FMSCHEMA-001
The frontmatter block is found by its fences and parsed as a YAML mapping
When a document starts with a `---` line, the extension SHALL take the lines up to the first later `---` or `...` line that stands alone on its line, with LF or CRLF endings, as the frontmatter block and show it as a properties table when it parses to a YAML mapping, or as one error row "Invalid frontmatter YAML: {parser message}" with an error badge of 1 when it does not, and render the Markdown body below the table or the error row in both cases.
Step 1 of path 1 in StRS-MDOKFSTUDIO-FMSCHEMA-001: from “A document starts with a `---` line and a YAML mapping” to “The properties table is shown”.
Scenarios 6
The situations the tests check; open one to read it.
nominalClosing with three dashes or three dots
Givena document starting with `---`, a line `title: Hello` and a closing line `...` followed by a heading
Whenthe preview is rendered
Thena properties table at the top lists the field title with the value Hello and the heading follows it
boundaryWhere the closing fence is recognised
| Input | Outcome |
|---|---|
| A frontmatter line `note: wait...` followed by a closing `---` line | The table lists the field note with the value `wait...`; the block closes at the `---` line, not at the dots inside the value |
| A closing `---` or `...` line followed by trailing spaces or tabs | The line still closes the block |
| A document whose opening fence, fields and closing fence all end with CRLF | The table lists the same fields and values as the LF form of the document |
| A CRLF document closed by a `...` line | The block closes at the `...` line and the table lists the fields above it |
| A document with only the two fence lines | The block is valid and empty; it parses to null and gets the not-a-mapping error row (see the scenario on a block that is not a mapping) |
refusalOpening fence without a closing fence
Givena document with `---`, the lines `title: Open` and `status: draft`, a heading and no closing fence line
Whenthe preview is rendered
a closing `---` line is inserted after the two fields and the preview refreshes
a closing `---` line is inserted after the two fields and the preview refreshes
Thenthe document has no frontmatter and no properties table is shown
the table appears with the fields title and status
the table appears with the fields title and status
refusalInvalid YAML
| Input | Outcome |
|---|---|
| A document whose frontmatter is the single line `k: [a` followed by a heading | The table holds one alert row starting with "Invalid frontmatter YAML:" and the badge reads 1 error |
| A broken frontmatter that also names a type with a schema | No schema is applied, no field row is listed and the single error row is shown |
refusalA block that is not a mapping
| Input | Outcome |
|---|---|
| A frontmatter block holding the two list items `- a` and `- b` | The table holds the error row "Invalid frontmatter YAML: Frontmatter is not a mapping." and the badge reads 1 error |
| A document whose frontmatter is only the two fence lines | The same error row is shown, because an empty block parses to null |
| A block that parses to a scalar | The same error row is shown |
nominalThe body renders when the YAML is invalid
| Input | Outcome |
|---|---|
| A document whose frontmatter is the single line `k: [a` followed by a heading | The heading is rendered below the error row |
| The same document with `markdownOkfSchemaStudio.frontmatter.propertiesTable` false | No error row appears and the heading is rendered |
Implemented in 3
Tested by 6
- test/core/frontmatter/diagReq.frontmatter.requirements.test.tsunit
- test/core/frontmatter/frontmatterFence.test.tsunit
- test/core/frontmatter/frontmatterParseOnce.test.tsunit
- test/core/frontmatter/okfFrontmatter.test.tsunit
- test/integration/previewEditing.test.tsintegration
- test/visual/scenarioDefinitions2.tsvisual
Known limits (4)
- a leading byte-order mark in the document text itself is not stripped, so such a text has no frontmatter (it is stripped only when a linked target is read).
- the parser message is the raw text of the YAML library, with line numbers relative to the frontmatter and caret markers.
- a YAML alias that expands more than 100 times fails the parse and is reported as invalid YAML, not as a mapping problem.
- an empty block is a valid fence but still gets the not-a-mapping error row.
Replaces
SwRS-MDOKFSTUDIO-FMSCHEMA-002A document without a closing fence has no frontmatter superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-001 Markdown file
SwRS-MDOKFSTUDIO-FMSCHEMA-003Frontmatter fences accept Windows line endings superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-001 Markdown file
SwRS-MDOKFSTUDIO-FMSCHEMA-017Invalid YAML gives one error row and an error badge superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-001 Markdown file
SwRS-MDOKFSTUDIO-FMSCHEMA-018Frontmatter that is not a mapping gives an error row superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-001 Markdown file
SwRS-MDOKFSTUDIO-FMSCHEMA-076Invalid YAML does not stop the body from rendering superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-001 Markdown file