Markdown OKF-Schema Studio

Behaviour SwRS-MDOKFSTUDIO-PALETTE-058

The Colour picker wraps the selection in a safe colour span

When the writer presses Colour, the extension SHALL open a picker with the tabs Text and Background, sixteen colour swatches, a field for a colour code and a Remove button, apply a swatch, a valid colour code or Remove to the property of the open tab as a span whose only attribute is a colour style, and produce no edit for a value the sanitizer would strip.

Step 1 of path 2 in StRS-MDOKFSTUDIO-PALETTE-007: from “The palette is shown above the text box” to “The colour picker is open”.

Scenarios 7

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

nominalPicker contents
Givenan open block editor
an open table cell editor
Whenthe writer presses Colour
the writer presses Colour in the cell formatting group
Thenthe picker shows the tabs Text (selected) and Background, sixteen swatches each titled with its colour, the field named Colour code with the placeholder `#rrggbb` and the Remove button
the same picker opens

The action is a strict-mode action for blocks and cells with a swatch popover; the sixteen swatches are distinct and each is a colour the sanitizer keeps.

nominalA swatch or a valid code applies the colour of the open tab
Givena selected word and the Text tab open
the Background tab open
the field holds #c00 and a word is selected
Whenthe writer presses a swatch
the writer presses a swatch
the writer presses Enter
Thenthe word is wrapped in a span with that text colour and the picker closes
the span gets a background colour instead
the colour is applied like a swatch and the picker closes

The action receives the argument text:{colour} or background:{colour} and the picker is removed before the edit. The edit is one undo step and keeps the editor open.

refusalInvalid colour code in the field
Giventhe field holds red
Whenthe writer presses Enter
Thenthe field is marked aria-invalid, nothing is written and the picker stays open

The field is validated as the writer types too: a non-empty invalid value sets aria-invalid, an empty or valid value removes it; the valid values are the colour grammar of the sanitizer, named colours and hsl() included (see SwRS-MDOKFSTUDIO-GFM-034).

nominalThe span written and updated

In this table `[ ]` marks the selection and `|` marks the caret.

Giventhe selection foo and the argument text:#c00
a table cell editor
Whenthe action runs
the action runs
Thenthe text is a span with style color:#c00 around foo, with foo selected
the span is written without escaping any pipe, because it contains none
InputArgumentOutcome
`say [foo] now``text:#c00`say <span style="color:#c00">[foo]</span> now
`say [foo] now``background:#ff0`say <span style="background-color:#ff0">[foo]</span> now
`say | now``text:#c00`say <span style="color:#c00">|</span> now
`a[ foo ]b` (edge blanks ignored)`text:#c00`a <span style="color:#c00">[foo]</span> b
x <span style="color:#c00">[foo]</span> y (span around the selection)`text:#00f`the colour of the same span is replaced, no new span
x <span style="color:#c00">f|oo</span> y (caret in the span)`text:#00f`the colour is replaced and the caret stays where it was
x <span style="color:#c00">[foo]</span> y`background:#ff0``style="color:#c00; background-color:#ff0"`, the same span carries both colours
a span with both colours`background:rgb(1, 2, 3)`the background colour is replaced, the text colour is kept
`[foo]` in a table cell`text:#c00`<span style="color:#c00">[foo]</span>
a span with a colour, caret in it, in a table cell`background:#ff0``style="color:#c00; background-color:#ff0"`

The written opening tag is a span element with a single style attribute whose value is color:#c00; with two declarations they are separated by a semicolon and a space, color first. A span is recognised only when its tag has a style attribute with colour declarations the sanitizer keeps, and no other attribute.

boundaryPartial selection and whole content
Givena span around one two three and two selected
the whole content of the span selected
Whena colour is applied
a colour is applied
Thena new span surrounds two inside the outer span
the outer span is updated instead
InputArgumentOutcome
x <span style="color:#c00">a[b]c</span>`text:#00f`x <span style="color:#c00">a<span style="color:#00f">[b]</span>c</span>, the outer span is unchanged
a[b<span style="color:#c00">cd</span>e]f (balanced span inside the selection)`text:#00f`the selection is wrapped in a new span around the balanced span
nominalRemove drops the property of the open tab
Givena word in a span with both colours and the Text tab open
a span with only a text colour and the caret inside
the content selected
a word outside any generated span
Whenthe writer presses Remove
the text colour is removed
the colour is removed
the writer presses Remove
Thenthe span keeps only the background colour
the tags are gone, the content stays and the caret stays on its character
the content stays selected
the text is unchanged

The action receives text: or background: with an empty colour; when no property is left the span is unwrapped (the edit replaces the whole span with its inner text); a property the span does not carry, or no generated span, gives no edit.

refusalWhat the sanitizer would strip
Giventhe argument text:red
a selection that starts inside a span and ends outside it
Whenthe colour action runs
the colour action runs
Thenno edit is produced
no edit is produced, in both directions
InputOutcome
argument `text:redd`, `text:#12`, `text:#ggg`, `text:url(x)`, `text:#c00;position:fixed`, text:#c00"><script>, `text:rgb(1,2,3`, `text:var(--x)`, `text:#c00 !important`, `sky:#c00`, `#c00`, empty, or no argumentno edit (the colour is invalid or holds a control character)
ab<span style="color:#c00">c[d</span>e]fno edit (selection straddles a span boundary)
a[b<span style="color:#c00">c]d</span>efno edit (selection straddles a span boundary, the other direction)
ab<span style="co[lor:#c00">cd</span>e]fno edit (a boundary lies inside the text of a tag)
a<b onclick="x|y">c</b>no edit (a boundary lies inside the text of a tag)
a slice with an unmatched span tagno edit
the registry built without a colour validatorno edit

The action returns undefined. Everything the action writes passes the sanitizer grammar (see SwRS-MDOKFSTUDIO-GFM-034).

Implemented in 2

Tested by 3