Highlighting a sentence in Markdown
Markdown has no colour. There is bold, italic, code and strikethrough, and that is the end of the inline formatting. Yet “highlight this sentence” is one of the first things anyone reaches for in a document they are reviewing.
Version 0.3.7 adds Format > Text Colour and Format > Highlight, with two toolbar buttons beside Italic. Select the words, pick a swatch. Yellow highlight is on Shift+Cmd+H (Shift+Ctrl+H on Windows).
The question was how to save it. Every Markdown dialect allows inline HTML, and two tags are understood everywhere:
Pay <mark>by Friday</mark> or the <span style="color: #d12f2f">late fee</span> applies.
<mark> is the HTML element for a highlight, and every reader that renders HTML shows it in yellow with no styling at all. For a text colour, a span with a color style is the plain, boring answer, and it is what the official Toast UI colour plugin and most other editors do too. Other highlight colours add a background-color style to the mark.
Rules we settled on:
- A new colour replaces the old one instead of nesting tags inside tags.
- Choosing Default or None removes the tag and leaves the words.
- A coloured word can also be highlighted; the two stack.
- In the Markdown Source view, the heading
#, list markers and>stay outside the tags, so a highlighted heading is still a heading. - Print, Print Preview and Export as PDF show the colours.
If a reader strips HTML (GitHub strips style attributes, for example), you lose the colour and keep the words, which is the failure we wanted.