Behaviour SwRS-MDOKFSTUDIO-TOOLBAR-077
A click or Enter on a link is routed to the host and opened or refused with a warning
When the reader clicks, middle-clicks or presses Enter or Space on a link that carries a navigation request, the extension SHALL cancel the default action, post previewLink with that request and have the host open the target or show a warning with the reason when it cannot; the host follows nothing when the message carries no request and refuses a malformed frontmatter link request with the reason The frontmatter link request is invalid.
Step 3 of path 1 in StRS-MDOKFSTUDIO-TOOLBAR-011: from “The tooltip names where the link leads” to “The target is open”.
Part of StRS-MDOKFSTUDIO-FMSCHEMA-014, outside the paths drawn on its map.
Scenarios 10
The situations the tests check; open one to read it.
nominalClick, middle click and keys are posted
| Given | When | Then |
|---|---|---|
| a local link and a wiki link that the host has not been asked about yet | each is clicked, then the first is middle-clicked | each click posts previewLink with the link's request and the default action is cancelled |
| a focused link | Enter is pressed | previewLink is posted |
| a focused link | Space is pressed | previewLink is posted |
boundaryEdit mode keeps a plain click for editing
| Given, edit mode on | When | Then |
|---|---|---|
| a link inside a mapped block | it is clicked, or Enter or Space is pressed on it, with no Cmd or Ctrl key | no previewLink is posted; the editor of the block opens (SwRS-MDOKFSTUDIO-BLOCK-014) |
| the same link | it is clicked with Cmd or Ctrl held, Cmd/Ctrl+Enter is pressed on it, or it is middle-clicked | previewLink is posted |
| a link value of the properties table, in a comment thread or a label anchor | it is clicked | it keeps its own behaviour, as in reading mode |
refusalOther buttons and keys are not posted
| Given | When | Then |
|---|---|---|
| an auxclick with button 2 | the event arrives | nothing is posted and the default action stays |
| a focused link | the letter a is pressed | nothing is posted |
nominalThe host opens the target
| Link followed | Outcome |
|---|---|
| second.md#target | second.md opens in the text editor with the lines of the heading selected |
| second.md#missing | second.md opens with no selection |
| a normal Markdown file | it opens and no warning is shown |
| https://example.invalid/page (http, https or mailto) | the system opener is called once with the URL and the preview and the history are unchanged |
refusalThe host refuses with a warning
| Link followed | Outcome |
|---|---|
| javascript:alert(1) | the warning "Markdown OKF-Schema Studio could not follow the link: {reason}" is shown with the scheme reason, the system opener is not called and the history is unchanged |
| a valid Markdown link | no such warning is shown |
| a link to a file that cannot be opened as a text document | the warning "Markdown OKF-Schema Studio could not open {path}: {reason}" is shown with the path and the reason |
| a link whose resolution raises an error | the warning "Preview link resolution failed: {error}" is shown and nothing is recorded |
| a resolvable link | no resolution warning is shown |
nominalWith a request
Givena previewLink message with a request
Whenthe host receives it
Thenthe link is followed
refusalNo request
Givena previewLink message with no request field
Whenthe host receives it
Thenonly the page's scroll state is recorded, no link is resolved and nothing opens
refusalMalformed frontmatter link request
Givena navigation request okf-link: followed by text that is not valid JSON
Whenthe request is handled
Thenthe reason reads The frontmatter link request is invalid. and nothing opens
nominalWell-formed frontmatter link request
Givena request whose JSON names an existing link
Whenthe request is handled
Thenthe link is followed
refusalRequest that is not a string
Givena previewLink message whose request is not a string
Whenthe validator runs
Thenthe message is refused (see SwRS-MDOKFSTUDIO-TRUST-052)
Implemented in 3
Tested by 7
- test/integration/previewHistory.test.tsintegration
- test/integration/realInput/linkEditMode.tsintegration
- test/page/linkEditModeClick.test.tsunit
- test/page/modules/linkNavigation.test.tsunit
- test/page/modules/toolbarReq.requirements.test.tsunit
- test/session/diagReq.links.requirements.test.tsunit
- test/session/toolbarReq.requirements.test.tsunit
Replaces
SwRS-MDOKFSTUDIO-FMSCHEMA-083A malformed frontmatter link request is refused superseded superseded by SwRS-MDOKFSTUDIO-TOOLBAR-077 Markdown file
SwRS-MDOKFSTUDIO-TOOLBAR-113A link message needs a request, else it is ignored or refused superseded superseded by SwRS-MDOKFSTUDIO-TOOLBAR-077 Markdown file