Behaviour SwRS-MDOKFSTUDIO-PALETTE-217
Pasted HTML becomes the matching Markdown
When the clipboard HTML of a paste is converted, the extension SHALL write the Markdown of each element it knows (headings, bold, italic, strikethrough, links, images, lists, code, block quotes and tables), escape text that Markdown would read as markup, keep only the text of every other element, and give an empty text when nothing readable is left.
Step 2 of path 2 in StRS-MDOKFSTUDIO-PALETTE-018: from “The host converts the HTML” to “The selection is replaced by the converted Markdown”.
Scenarios 9
The situations the tests check; open one to read it.
nominalHeadings and emphasis, also from styles
Givenpasted HTML with headings and with bold, italic or struck-through text, set by an element or by a style
Whenthe HTML is converted
Theneach case gives the Markdown of the table, and an empty heading gives no line
| Input | Outcome |
|---|---|
| h1 to h6 element | a line with 1 to 6 number signs and the text |
| h2 element with a bold span | the line reads ## and the text, without asterisks (bold and italic markers inside a heading are dropped) |
| h2 element with no text | no line is produced |
| spans with font-weight 700, font-style italic and text-decoration line-through (Google Docs) | the text carries the markers **, * and ~~ (double asterisks, single asterisks, double tildes) |
| b element styled font-weight normal (Google Docs wrapper) | the text is not bold |
nominalLinks and images
Givena link with emphasis inside and an image with alt text Logo, both with a safe address
Whenthe HTML is converted
Thenthe text reads [the *docs*](https://example.com/a%28b%29) and [Logo](https://example.com/i.png)
| Input | Outcome |
|---|---|
| link with text | [text](address), the parentheses of the address percent-encoded and an address with blanks in angle brackets |
| image with alternative text | [alt](address), using the word image when the alternative text is empty |
| link with no text | no link is produced |
The refusal of an unsafe address is in SwRS-MDOKFSTUDIO-PALETTE-229.
nominalLists with nesting, start number and task boxes
Givenan ol with start 3, an inner ol, a rule and a checked task item
Whenthe HTML is converted
Thenthe text reads 3. Three, 4. Four with an indented 1. Inner, then ---, then - [x] Done
| Input | Outcome |
|---|---|
| ul and ol lists | dash lists and numbered lists, with their nesting and the start number of an ordered list |
| checked checkbox input in an item | [x] |
| unchecked checkbox input in an item | [ ] |
| nested list placed next to its parent item (Google Docs) | the nested list is indented under the item before it |
nominalWord list paragraphs
GivenWord paragraphs with an mso-list style, of level 1 and level 2, and Word conditional comments around the markers
Whenthe HTML is converted
Thenthe text reads - First and an indented - Second, and the comments and the marker characters are dropped
| Input | Outcome |
|---|---|
| mso-list paragraph, marker is a number or a letter | numbered line (every numbered item is written with 1.) |
| mso-list paragraph, any other marker (the marker o is a bullet) | bulleted line |
| level of the paragraph | each level below the first indents by three blanks |
nominalCode, inline and fenced
Givena pre with a code element of class language-ts, a code element with a backtick inside, and a monospace block copied from VS Code
Whenthe HTML is converted
Thena ts fence surrounds the code, the inline span uses a longer backtick run, and a VS Code copy is kept as raw text
| Input | Outcome |
|---|---|
| pre element, optionally with a code child | a fenced block whose language comes from a class language-, lang-, highlight-source- or highlight-text-, with a fence longer than any backtick run inside |
| code, kbd, samp or tt text | a backtick span, using a longer backtick run than any inside |
| monospace block with preserved white space (a pre white-space and a monospace, consolas, menlo or courier font), copied from an editor, any number of lines | the lines as copied, raw, with their blank lines and any code fence they contain; never wrapped in a fence of its own |
nominalBlock quotes
Givena blockquote with two paragraphs
Whenthe HTML is converted
Thenthe text reads > Quoted, a bare >, and > Twice
| Input | Outcome |
|---|---|
| blockquote with blocks | its blocks, converted with the same rules, as lines that start with > , a bare > between paragraphs |
| empty blockquote | no line is produced |
boundaryTables
Givena table with a header row and a cell a|b, and a table with a cell of colspan 2
Whenthe HTML is converted
Thenthe first becomes a pipe table and the second keeps only the text of its cells
| Input | Outcome |
|---|---|
| table without colspan, rowspan or nested table | a pipe table with a delimiter row, the pipe in a cell escaped, a short row padded with empty cells, and the first row as header even when it uses td cells |
| table with a cell of colspan 2 (or a rowspan, or a nested table) | no table is written; the text of the cells stays, one line per row |
boundaryText that looks like Markdown is escaped
Giventhe text 2 * 3 [x] `y` and a paragraph # not a heading
Whenthe HTML is converted
Thenthe text reads 2 \* 3 \[x\] \`y\` and the number sign of the second paragraph is escaped
| Input | Outcome |
|---|---|
| asterisks, brackets, backticks, angle brackets | escaped with a backslash |
| underscore at a word edge | escaped with a backslash |
| underscore inside a word | left alone |
| line that Markdown would read as a heading, quote or list | its marker is escaped with a backslash |
boundaryOther elements and nothing readable
Givendiv, section and span elements around text, a heading among them, and a clipboard of only a style, a comment and a script
Whenthe HTML is converted
Thenthe text of the plain elements is kept without markup and the heading is converted as usual, and the second clipboard gives an empty result
| Input | Outcome |
|---|---|
| element that is not converted | its text only; block elements separate paragraphs and inline elements join their text |
| converted element among them | converted as usual |
| nothing readable left | an empty Markdown text; the result is trimmed and runs of three line breaks are reduced to two |
| empty result reaches the page | the plain text of the clipboard is pasted, as SwRS-MDOKFSTUDIO-PALETTE-213 states |