RichTextMarkdown.h header

#include <ew/app/RichTextMarkdown.h>

Namespace ew::app

Functions

QString ew::app::escapeMarkdownBlockLeader(const QString &text)

Backslash-escapes a leading Markdown block marker on text so a plain paragraph is not re-read as a different block on export. When prose happens to start with a list bullet (- , + , * ), an ordered marker (1. / 1) ), a blockquote (> ), an ATX heading (# .. ###### ), or forms a thematic break (a whole line of three or more -, *, or _), the marker is escaped (e.g. - 20 rounds -> \- 20 rounds, 1. First -> 1\. First, --- -> \---) so it renders as the literal characters. Each list/quote/heading marker must be followed by whitespace to count, so an emphasis run that opens the line (*word*, **bold**) – whose marker hugs non-whitespace – is left untouched. text with no leading block marker is returned unchanged. Intended for the plain-paragraph case of rich-text export, after inline emphasis has been applied (a literal */ ` is already escaped by then, so a bullet * never reaches here as a bare marker).

QString ew::app::wrapInlineMarkdown(const QString &text, bool bold, bool italic, bool strikeOut)

Wraps text in the inline Markdown for the given emphases – bold (**), italic (*), both (***), and/or strikethrough (~~) – for the desktop editor's rich-text export. Two fidelity rules the naive "marks + text + marks" approach gets wrong:

  • Markers must hug non-whitespace. Any leading/trailing whitespace in text is lifted outside the markers, because CommonMark's flanking rule renders **word ** (a space before the closing **) as the literal characters, not bold. A trailing space inside a run is common: extending a selection to the next word (Shift+Ctrl+Right) includes the space.
  • Literal emphasis characters are escaped. A real * or ` the writer typed as prose is backslash-escaped so it is not reinterpreted as formatting on re-parse. Square brackets are intentionally left untouched so the app's ![[…]] / [^id] markers survive verbatim. With no emphasis set, returns text with only that escaping applied; empty for empty text; an all-whitespace text is returned unchanged (nothing to emphasize).