Markdown OKF-Schema Studio

Behaviour SwRS-MDOKFSTUDIO-PALETTE-276

Inline marker buttons toggle their markers around the selection

When the writer presses Bold, Italic, Strikethrough, Subscript, Superscript, Key or Key (MyST), the extension SHALL wrap the selection, or the word at a collapsed caret, in the markers of that button, remove the markers when they are already there, and produce no edit when the markers cannot be written safely.

Step 2 of path 1 in StRS-MDOKFSTUDIO-PALETTE-019: from “The palette is shown above the text box” to “The selection is wrapped in markers”.

Part of StRS-MDOKFSTUDIO-PALETTE-020, outside the paths drawn on its map.

Part of StRS-MDOKFSTUDIO-PALETTE-021, outside the paths drawn on its map.

Scenarios 9

The situations the tests check; open one to read it.

nominalBold and Italic wrap and unwrap
Giventhe text say foo now with foo selected
WhenBold is pressed twice
Thenthe first press gives say **foo** now with foo selected and the second restores the text
ActionInputOutcome
Bold`say [foo] now``say **[foo]** now`
Italic`say [foo] now``say *[foo]* now`
Bold`say **[foo]** now` (markers outside the selection)`say [foo] now`
Italic`say *[foo]* now` (markers outside the selection)`say [foo] now`
Bold`say [**foo**] now` (markers inside the selection)`say [foo] now`
Italic`say [*foo*] now` (markers inside the selection)`say [foo] now`
Bold`say **fo|o** now` (caret in the word)`say fo|o now`
Italic`say *fo|o* now` (caret in the word)`say fo|o now`
Bold`**foo|**``foo|`
Bold, then Italic, then Italic, then Bold on `x foo y` with foo selected`x ***foo*** y` after the first two presses, then `x foo y` with the same selection
nominalEmpty pair
Giventhe caret between two spaces
WhenItalic is pressed
Thenthe text gets two single asterisks with the caret between them
ActionInputOutcome
Bold`say | now``say **|** now`
Italic`say foo| now` (caret after a word)`say foo*|* now`
Bold`|``**|**`
Bold`x **|** y` (empty pair)`x | y`
Italic`x *|* y` (empty pair)`x | y`
Strikethrough`say | now` (caret outside a word)`say ~~|~~ now`
Strikethrough`x ~~|~~ y` (empty pair)`x | y`
nominalBold and Italic share a run of asterisks
Giventhe text foo selected inside ***foo***
the text foo selected inside *foo*
WhenBold is pressed and then Italic
Bold is pressed
ThenBold leaves *foo* and Italic then unwraps the text; each press removes only its share
the run becomes ***foo***
ActionInputOutcome
Bold`*[foo]*``***[foo]***`
Italic`**[foo]**``***[foo]***`
Italic`***[foo]***``**[foo]**`
Bold`***[foo]***``*[foo]*`
Bold`***fo|o***``*fo|o*`
Italic`***fo|o***``**fo|o**`
nominalStrikethrough wraps and unwraps a double tilde pair
Giventhe text say foo now with foo selected
the caret inside ~~foo~~
WhenStrikethrough is pressed
Strikethrough is pressed
Thenthe text is say ~~foo~~ now with foo selected
the markers are removed and the caret stays in the word
InputOutcome
`say ~~[foo]~~ now` (markers outside the selection)`say [foo] now`
`say [~~foo~~] now` (markers inside the selection)`say [foo] now`
`say ~~fo|o~~ now``say fo|o now`
`a[ foo ]b` (blanks at the selection edges are ignored)`a ~~[foo]~~ b`
`[a` newline `b]` (multi-line selection)`~~[a` newline `b]~~`

The Strikethrough button has no keyboard shortcut.

nominalSubscript and Superscript wrap the selection in a role
Giventhe selected 2 in H2O
the caret in a table cell editor
WhenSubscript is pressed
Subscript or Superscript is pressed
Thenthe 2 is wrapped in the sub role and stays selected; with nothing selected the caret is put between the quotes of the role
both buttons work as in a block editor
nominalKey (MyST) wraps the selection in the kbd role
Giventhe selected word Ctrl
no selection
WhenKey (MyST) is pressed
Key (MyST) is pressed
Thenthe word is wrapped in the kbd role
`{kbd}` with the sample Ctrl+K is inserted with Ctrl+K selected
InputOutcome
Key (MyST) pressed in a table cellThe action works
Key (MyST) pressed on text that already has markupUnlike Key, it never removes existing markup
nominalKey wraps the selection in kbd tags
Givena selected word
WhenKey is pressed twice
Thenthe word is wrapped in kbd tags and then unwrapped; the tags are also removed when the selection or its surroundings already have them
InputOutcome
The caret with no selectionA kbd element holding Key is inserted with Key selected
Key pressed in a table cell editorKey works in a table cell too
refusalA selection that cuts into a marker run, or that a role cannot hold
Givena selection that starts inside a run of asterisks and ends outside it
a selection that covers the content with its whole run
a selection that contains a backtick (Subscript, Superscript or Key (MyST)) or a line break (Subscript or Superscript)
WhenBold is pressed
Bold is pressed
the button is pressed
Thenno edit is produced
the markers are handled as usual
no edit is produced
ActionInputOutcome
Bold`**f[oo]**`no edit
Italic`*[fo]o*`no edit
Bold`[*foo*]` (selection includes the markers)not refused: the markers are handled as usual (this input is untested)
Superscripta selection that contains a backtickno edit
Key (MyST)a selection that contains a backtickno edit
boundaryEdges, lines and other markers
ActionInputOutcome
Bold`a[ foo ]b` (blanks at the selection edges)`a **[foo]** b` (the markers go around the trimmed content)
Bold`**a**[ b ]**c**` (blanks between two spans)`**a** **[b]** **c**` (not a wrapped selection)
Bold`[a` newline `b]` (multi-line selection)`**[a` newline `b]**` (one span)
Bold`[_foo_]` (underscores)`**[_foo_]**` (underscores are not recognised as markers and stay in place)

A run holds bold when it has two or more asterisks and italic when its length is odd.

Implemented in 1

Tested by 2

Replaces

SwRS-MDOKFSTUDIO-PALETTE-045Bold and Italic toggle their shared asterisk markers superseded superseded by SwRS-MDOKFSTUDIO-PALETTE-276 Markdown file
SwRS-MDOKFSTUDIO-PALETTE-048Strikethrough toggles a double tilde pair superseded superseded by SwRS-MDOKFSTUDIO-PALETTE-276 Markdown file
SwRS-MDOKFSTUDIO-PALETTE-126Key wraps the selection in kbd tags, removes them, or inserts a sample superseded superseded by SwRS-MDOKFSTUDIO-PALETTE-276 Markdown file
SwRS-MDOKFSTUDIO-PALETTE-135Subscript and Superscript wrap the selection in a role superseded superseded by SwRS-MDOKFSTUDIO-PALETTE-276 Markdown file
SwRS-MDOKFSTUDIO-PALETTE-138Key (MyST) wraps the selection in the kbd role superseded superseded by SwRS-MDOKFSTUDIO-PALETTE-276 Markdown file