Behaviour SwRS-MDOKFSTUDIO-GFM-009
GitHub alerts render as admonitions
When a block quote starts with [!NOTE], [!TIP], [!IMPORTANT], [!WARNING] or [!CAUTION] in any case, the extension SHALL render it as an admonition of that type with the default title and the quoted lines as Markdown body, using the text after the marker as the title and ending the admonition where its block quote ends under CommonMark, lazy paragraph continuation lines included.
Step 1 of path 2 in StRS-MDOKFSTUDIO-GFM-002: from “A block quote starts with [!NOTE], [!TIP], [!IMPORTANT], [!WARNING] or [!CAUTION]” to “The alert is drawn as an admonition, and the document holds a raw HTML table”.
Scenarios 11
The situations the tests check; open one to read it.
nominalEach alert type renders
refusalUnknown alert type
nominalTitle from the marker line
| Input | Outcome |
|---|---|
| `> [!WARNING] Read this` | the admonition title is Read this |
| `> [!WARNING]` alone | the title is the default Warning |
nominalLegacy bold markers
refusalBold marker with extra text
boundaryThe first body line never becomes the title
| Input | Outcome |
|---|---|
| `> [!NOTE]`, `> # h`, `> b` | the title is Note; `h` is a heading in the body, on line 2, before the paragraph `b` |
| `> [!NOTE]`, `> **Bold first**`, `>`, `> b` | the title is Note; `Bold first` is a bold paragraph in the body |
| `> [!WARNING] Read this`, `> ## h` | the title is Read this; `h` is a heading in the body |
| `> **Note**`, `> # h` | the title is Note; `h` is a heading in the body |
boundaryFences keep alert markers literal
| Input | Outcome |
|---|---|
| '> [!NOTE]' within a fenced code block | the marker stays literal code and no admonition is produced |
| a fenced block followed by a real alert | the fence content is literal and the alert after it is an admonition |
boundaryThe admonition ends where its block quote ends
An unquoted line continues the alert only as a lazy continuation line (CommonMark 0.31.2, section 5.1): the alert's last line leaves a paragraph open (the marker line counts) and the unquoted line is not blank and cannot start a block. On a lazy line the quote does not match, so any list marker starts a list there, while a quoted line keeps the paragraph rule (only `1.` or a bullet with text interrupts a paragraph). A lazy line stays paragraph text: it never underlines a setext heading, makes a table delimiter row or a MyST block break `+++`. This is how GitHub renders alerts. The same rule holds for an alert indented in a list item, read after the indentation. Lazy lines are read with the preview's MyST syntax, so other MyST-only block syntax on a lazy line (a comment `% c`, a target `(lbl)=`, a footnote definition `[^1]: n`, a math block `$$`) keeps its MyST meaning inside the admonition, where GitHub shows it as paragraph text.
| Input | Outcome |
|---|---|
| `> [!NOTE]`, `> a`, then the unquoted line `b` (or an indented ` b`) | `b` is inside the admonition, in the same paragraph as `a` |
| `> [!NOTE]` directly followed by an unquoted line | the line is inside the admonition |
| `> [!NOTE]`, `> a`, `b`, `c`, `> d` | one admonition; `a b c d` is one paragraph (quoted lines resume after lazy lines) |
| an alert followed by a blank line and a paragraph | the paragraph is outside the admonition and later source line numbers are unchanged |
| an alert whose paragraph is followed directly by a list item of any marker or number, an empty one included (`- item`, `1. item`, `2. x`, `-`, `1) b`), a heading, a code fence (backticks or tildes), a colon fence, a thematic break or an HTML block that can interrupt a paragraph | that block is outside the admonition |
| `> [!NOTE]`, `> a`, then the quoted line `> 2. x` | `2. x` stays text of the paragraph (a quoted `2.` item cannot interrupt it) |
| `> [!NOTE]`, `> a`, then an unquoted `===`, `--` or `=` | the line is inside the admonition as paragraph text (`a ===`); the admonition keeps its default title and no heading is made |
| `> [!NOTE]`, `> a`, then an unquoted `+++` (or `+++ {"a": 1}`), then `b` | the line is inside the admonition as paragraph text (`a +++ b`); no block break is made and the document renders |
| `> [!NOTE]`, `> | a | b |`, then an unquoted delimiter row `| - | - |` (or `a | b`, then `--|--`) | the row is inside the admonition as paragraph text; no table is made |
| an unquoted line after a quoted heading, a quoted fenced or indented code block, a blank quoted line `>`, a quoted thematic break, a quoted table (a header row and a delimiter row with as many cells) or a quoted HTML block that is still open | the line is outside the admonition (no open paragraph to continue) |
| `> [!NOTE]`, `> <!-- c -->` (or any HTML block of CommonMark kinds 1 to 5 closed by its end marker), `> text`, then `lazy` | the HTML block ends on its end marker, so `lazy` continues the paragraph `text` inside the admonition |
| `> [!NOTE]`, `> a`, `> <custom-x>` (a lone tag, which cannot interrupt a paragraph), then `lazy` | `lazy` is inside the admonition; after a blank quoted line the same tag starts an HTML block and `lazy` is outside |
boundaryEvery block keeps the lines of the document
The alert is rewritten into an admonition of more lines before parsing; the source lines of the blocks (`data-line`, `data-end-line`, which the block editor opens, saves, cuts and moves) are still the lines of the file as written; the rule is that of SwRS-MDOKFSTUDIO-CORE-003, and the rows below are its alert cases.
| Input | Outcome |
|---|---|
| two consecutive alerts (lines 1-2 and 4-6), then a heading on line 8 and a paragraph on line 10 | the admonitions carry lines 1-2 and 4-6, their paragraphs 2 and 5-6, the heading 8 and the paragraph 10 |
| any alert type, a bold marker or a titled alert, an alert ending the file without a final line break, a CRLF document | the admonition starts on its marker line and ends on the alert's last line (quoted or lazy); every other block keeps its own lines |
| an alert followed directly by a lazy continuation line, then a blank line and a paragraph | the admonition and its paragraph end on the lazy line; the paragraph after keeps its own line |
| an alert followed directly by a list item | the admonition ends on its last quoted line; the list keeps its own lines |
| an alert after a frontmatter block, inside a list item, a grid card, a tab item or between context tags (also kept as one raw HTML block) | the same, counted in the whole file |
| an unclosed fence after an alert | the warning and the opening line shown as code carry the line of the fence |
| alert markers inside a fenced code block | they stay literal and later lines are unchanged |
boundaryAlerts inside a colon container
An admonition written with a colon fence closes at the first colon-only line at least as long as its own, and a container nested in another must use a shorter fence than the outer one; a `:::{note}` inside a `:::{card}` would therefore end the card early.
| Input | Outcome |
|---|---|
| an alert inside a `:::{card}`, a `:::{tab-item}` of a tab set or a three-colon card of a nested grid, followed by a paragraph | the admonition is a backtick directive; the paragraph stays inside the card or tab and the text after the container stays outside |
| the same documents | the blocks carry the lines of the file as written (the tab panels carry the lines of their items) |
| an alert outside every colon container | it is a colon-fence admonition, as before |
| an alert whose body holds a colon container (a `::::{grid}` of `:::{card}`) | the admonition's colon fence is longer than every colon fence of its body; the whole container stays inside the admonition and the text after the alert stays outside |
boundaryCRLF documents
| Input | Outcome |
|---|---|
| an alert written with CRLF line endings | an admonition is produced |
| a CRLF document mixing a fence and an alert | the HTML equals the LF rendering |
Implemented in 4
Tested by 9
- test/core/render/alertInsideColonContainer.test.tsunit
- test/core/render/alertLazyContinuation.test.tsunit
- test/core/render/alertSourceLines.test.tsunit
- test/core/render/alertTitle.test.tsunit
- test/core/render/crlfAlerts.test.tsunit
- test/core/render/mystFeatures.test.tsunit
- test/core/render/mystPaletteRendering.test.tsunit
- test/integration/realInput/qa210Replays.tsintegration
- test/session/alertBlockEditOpen.test.tsunit