Behaviour SwRS-MDOKFSTUDIO-BLOCK-094
The host inserts a new block with clean blank lines
When the host writes a new block after a line, it SHALL put one blank line before it and one blank line after it (none after it at the end of the document), in the line endings of the document, and write nothing for an empty or whitespace-only text or for a line that is not in the document.
Step 2 of path 1 in StRS-MDOKFSTUDIO-BLOCK-011: from “An empty insertion editor is open” to “The new block is in the document between its neighbours”.
Part of StRS-MDOKFSTUDIO-BLOCK-025, outside the paths drawn on its map.
Scenarios 8
The situations the tests check; open one to read it.
nominalBetween blocks
Givena document with two blocks separated by a blank line and a new block inserted after the first
Whenthe host plans the insertion
Thenthe new text goes at the end of the first block's last line, preceded by a blank line and followed by the existing blank line
boundaryBlocks and the end of the document
| Input | Outcome |
|---|---|
| A block directly followed by a non-blank line, a block inserted after it | A line break is added after the new block so that the next block is not glued to it |
| A document ending with a figure fence and a final line break, a block inserted after the closing fence | The new block follows the closing fence after one blank line, with no separator after it |
| A document that ends with an image line and no final line break, a block inserted after that line | The new block follows after one blank line, with no separator after it |
boundaryThe first block (after line 0)
| Input | Outcome |
|---|---|
| A document that starts with frontmatter | The new text follows the closing fence and the frontmatter text is unchanged |
| A document that holds only frontmatter | The new block ends the document after one blank line |
| An empty document | The document holds the new block followed by one line break |
| A document that starts with a heading and has no frontmatter | The new block comes first, followed by a blank line and then the heading |
boundaryLine endings
| Input | Outcome |
|---|---|
| A document with CR LF line breaks, a block of two lines inserted | Every line break of the inserted text is CR LF |
| A document with LF line breaks only, a block inserted | Every line break of the inserted text is LF |
| A document whose lines end with a lone CR, a block of two lines inserted after line 1 or after a later line | The block goes at the end of that line and every line break of the inserted text is CR; a line after the last CR is refused as missing |
refusalA whitespace-only new block
| Input | Outcome |
|---|---|
| An insertion editor whose text is ` \n`, the final save arrives | The document is unchanged and the edit ends |
| An insertion editor whose text is `Hello`, the final save arrives | The block is inserted |
boundaryTrailing line breaks are dropped
| Input | Outcome |
|---|---|
| A new block typed as `Hello\n\n` | The document holds `Hello` followed by the planned separator only |
| A block typed as `a\n\nb` | The inner blank line is kept |
| A new block typed as `\n\nHello` (leading blank lines), in LF, CR LF or lone CR | The leading blank lines are dropped and the block starts right after the separator |
| A new block typed as ` Hello` | The indentation of the first non-blank line is kept |
boundaryAn anchor line that is blank
| Input | Outcome |
|---|---|
| `- a`, a blank line and `Para`, a block inserted after line 2 (the blank line) | The document is `- a`, a blank line, `New`, a blank line, `Para`: one separator before the block, not two |
| A block inserted after a non-blank line | The prefix stays two line endings |
refusalA line that does not exist
| Input | Outcome |
|---|---|
| A previewEditOpen with insertAfterLine beyond the last line | The host registers no editor and the editor shows "The preview is stale. Refresh it before editing this block." |
| A previewEditOpen with insertAfterLine on the last line | The empty source of the new block is sent |
Implemented in 1
Tested by 2
Known limits (1)
- a document whose lines end with a lone CR is not recognised as having frontmatter (the fence match accepts LF and CR LF only), so an insertion at the start of such a document goes before the frontmatter.