Behaviour SwRS-MDOKFSTUDIO-PALETTE-272
The Code-block button edits a MyST code-block directive in a form
When the writer presses the Code-block (MyST) button in MyST mode, the extension SHALL open a form for the language, line numbers, emphasized lines, caption and name of the code-block directive at the caret, or of a new one, and Apply SHALL write that directive in one undo step, leaving every other option and the code unchanged.
Part of StRS-MDOKFSTUDIO-PALETTE-021, outside the paths drawn on its map.
Scenarios 4
The situations the tests check; open one to read it.
nominalEdit an existing directive
Giventhe caret inside a `{code-block}` directive that has a language, a caption and other options (the MyST palette lists the Code-block (MyST) button after Key)
Whenthe button is pressed, Line numbers, Emphasized lines and Name are changed, and Apply is pressed
Thenthe form first shows the language, the line numbers (Off when absent), the emphasized lines, the caption and the name read from the directive; the directive is then rewritten with `:linenos:`, `:emphasize-lines:` and `:name:` added after the existing options and a blank line before the code, as one undo step, and the other options and the code are unchanged
nominalInsert a new directive
Giventhe caret outside any `{code-block}` directive
Whenthe button is pressed, a language and Line numbers are chosen, and Insert is pressed
Thenan empty form was shown, and a directive with that language and `:linenos:` is written after a blank line (in place of a blank caret line, or around the selected lines as its code), with the caret on the first line of the code, as one undo step
boundaryWhat is read and written
| Input | Outcome |
|---|---|
| a directive whose values are not changed | Apply writes nothing; the text is byte for byte the same |
| an option whose value is not changed, or an option the form does not know (`:dedent:`) | its original line is kept |
| a value emptied (caption, name, emphasized lines) or Line numbers set to Off | the option line is removed |
| a fence of backticks, tildes or colons, indented or not, or an unclosed directive | read and written back with the same fence and indent |
| code holding a fence line of the same character | the fence of a new directive is longer than any run in the code |
| a directive written inside the code of another directive | not looked at: the outer directive is the one edited |
refusalInvalid values and YAML options
| Input | Outcome |
|---|---|
| a language with a space, or emphasized lines that are not numbers and ranges such as `1,3-5` | a message under the field, the form stays open and nothing is written |
| a caption or name with a line break | a message under the field, nothing is written |
| a directive whose options are a `---` YAML block | no form; the status line sends the writer to the text box |
| Escape or Cancel | the form closes and nothing is written |