Behaviour SwRS-MDOKFSTUDIO-PALETTE-092
The link panel writes a safe inline Markdown link
When the writer presses Enter in the Text or URL field of the link panel or presses Insert, the extension SHALL write [text](url) over the selection, or over the link around the caret, as one undoable step with the text and the target escaped so that they cannot break the link, and return the focus to the text box.
Part of StRS-MDOKFSTUDIO-PALETTE-007, outside the paths drawn on its map.
Scenarios 6
The situations the tests check; open one to read it.
nominalEnter or Insert
Giventhe panel with Text docs and URL https://example.org
Whenthe writer presses Enter in the URL field
Thenthe selection is replaced by [docs](https://example.org) in one undo step and the focus returns to the text box
Enter in the Text field and the Insert button write the same link
Enter in the Text field and the Insert button write the same link
boundaryEmpty fields
| Input | Outcome |
|---|---|
| Text docs and an empty URL | [docs]() is written with the caret between the parentheses |
| Text docs and a URL | The caret is after the closing parenthesis |
| An empty Text and the URL https://example.org | [https://example.org](https://example.org) is written |
| A Text that holds only blanks | The address is used as the label as well |
boundaryCharacters that would break the link
| Input | Outcome |
|---|---|
| The Text a [b] c | The label is written a \[b\] c; only the characters [ and ] are escaped |
| The caret in a link with the label a \[b\] c, panel opened | Text shows a [b] c without backslashes |
| The URL my file.md | The target is written in angle brackets around my file.md |
| The URL a<b | The less-than character is written %3C and the target stays unwrapped |
| The URL a(b, with unbalanced parentheses | The target is wrapped in angle brackets, written <a(b>; a blank or unbalanced parentheses both trigger the wrapping |
| A URL with balanced parentheses and no blank | The target is left as typed; the URL is trimmed |
nominalLink around the caret
Giventhe caret inside [docs](https://example.org "Site")
Whenthe panel opens and the URL is changed
Thenboth fields are prefilled, the whole link is replaced, the title "Site" is kept and the caret is after the link; one undo restores it
nominalReference-style link
Giventhe text see [docs][d] with the line [d]: https://example.org and the caret in the link, in the form [text][ref], [text][] or [ref]
Whenthe panel opens and Insert is pressed
Thenthe panel shows docs and the address, the link becomes an inline link and the definition line stays
boundaryNot a link
| Input | Outcome |
|---|---|
| The caret inside  | The image is not taken for a link and the panel starts as for a plain caret |
| A reference-style link with no definition line in the text | The panel starts as for a plain selection and saving inserts an inline link |