Behaviour SwRS-MDOKFSTUDIO-CODE-039
Code lines are numbered and emphasized
When a code block of two lines or more is shown and the setting preview.codeBlocks.lineNumbers is on, the extension SHALL number its lines with generated content that neither the copy button nor a selection picks up, and SHALL number a MyST code block with the linenos or lineno-start option from its start value whatever the setting says, emphasizing the lines listed in its emphasize-lines option.
Step 2 of path 1 in StRS-MDOKFSTUDIO-CODE-001: from “The code is coloured” to “The lines of the code are numbered”.
Scenarios 6
The situations the tests check; open one to read it.
nominalA block of two lines or more is numbered
Givena fenced `python` block of three lines and a block of two lines in a language that is not bundled
Whenthe preview renders them with the setting on (the default)
Theneach line is its own line element numbered from 1 by generated content, and the line numbers are not part of the text of the block
boundaryA single line is never numbered
| Input | Outcome |
|---|---|
| a one-line fenced block | no line element and no number |
| a block of two or more lines, setting off | no number is shown, the lines keep their text |
| a block of two or more lines with no language label | numbered like the others |
nominalThe numbers are never copied
Givena numbered block with an empty line in the middle
Whenthe reader presses the copy button or selects the block with the mouse
Thenthe copied text equals the source text, empty line included, and holds no line number
nominalThe MyST options win over the setting
Givena `{code-block}` with `:linenos:`, `:lineno-start: 10` and `:emphasize-lines: 11`
Whenthe preview renders it with the setting off
Thenits lines are numbered from 10 whatever the setting says and the second line is emphasized
nominalA MyST code directive numbers and emphasizes lines
Givena `{code}`, `{code-block}` or `{code-cell}` with `:linenos:`, `:lineno-start: 10` and `:emphasize-lines: 2`
Whenthe preview renders it
Thenlines are numbered from 10 and the second line is emphasized
refusalInvalid directive values fall back
Givena directive with `:lineno-start: abc` and `:emphasize-lines: 2,x`
Whenthe preview renders it
Thennumbering starts at 1 and the invalid emphasis entry is ignored
Implemented in 5
Tested by 10
- test/core/preview/codeBlockStyles.test.tsunit
- test/core/preview/previewStyles.test.tsunit
- test/core/render/codeBlockComfort.requirements.test.tsunit
- test/core/render/highlight.test.tsunit
- test/core/render/mystFeatures.test.tsunit
- test/core/render/renderReq.codeBlocks.requirements.test.tsunit
- test/page/modules/codeCopy.test.tsunit
- test/page/pageSettings.test.tsunit
- test/security/package-contract.test.tsunit
- test/visual/codeBlockComfortScenarios.tsvisual
Replaces
SwRS-MDOKFSTUDIO-CODE-005Numbered, emphasized and diff blocks are wrapped into lines superseded superseded by SwRS-MDOKFSTUDIO-CODE-001, SwRS-MDOKFSTUDIO-CODE-039 Markdown file