Version 8.8.0

All pages

Markdown

Markdown formats text with plain characters, such as **strong** for strong emphasis or a dash before a list item. Cards and courses can be written in it. This page covers the Markdown Solid Memo reads, the texts that may use it, how each place in the app shows it, and why showing it is safe whatever a pod or library holds.

The data side, the sm:textFormat marker and the sm:TextFormats concepts, is in vocab.md. This page is the render policy, which may change without touching data.

The dialect

sm:markdown is CommonMark 0.31.2 with GitHub Flavored Markdown pipe tables and CJK-friendly emphasis, and nothing else. Strikethrough, autolink literals (www.x), task lists and footnotes show as typed. Wider Markdown would be a new concept.

CJK-friendly emphasis is the markdown-cjk-friendly amendment to CommonMark's flanking rules. CommonMark closes * or ** after punctuation only when a space or punctuation follows, so Korean, where a particle follows a word directly, would keep the asterisks of **스크립트(script)**라고 and *‘사과’*를. The amendment counts a Chinese, Japanese or Korean character next to the delimiter as a space or punctuation, so both are emphasis, as is **強調。**この文.

Text without those characters reads as in CommonMark (a**"b"**c keeps its asterisks), with one change: the amendment reads a character outside the Basic Multilingual Plane, such as an emoji, as one character. The parser alone saw two surrogate halves, neither space nor punctuation. An emoji is a symbol, which CommonMark counts as punctuation, so *😀*a and a**😀**b keep their asterisks, as *★*a always did. Before the amendment, the app showed them as emphasis. _ inside a word never emphasizes: __사람__들 shows as typed, and **사람**들 works.

CommonMark has no invalid documents, so nothing is refused: what a place can't show is shown as text.

GFM and the CJK-friendly amendment aren't formal standards; standards.md says why they don't stand in the way of reading the text elsewhere.

What is Markdown

Only text whose subject says sm:textFormat sm:markdown is Markdown. When the marker is absent, sm:plainText, or a concept this app doesn't know, the text is plain, shown exactly as before 1.15.

SubjectMarkdown when markedAlways plain
sm:Cardfront, back, frontNote, backNote, frontLabel, backLabel, and its distractors' distractorText and distractorNotethe pictures' descriptions (their alt text)
sm:Steptheory
sm:Chapterdcterms:descriptiondcterms:title (headings, links, the window title)
deck, release, series, group, catalogevery text: DCAT readers and library search read them

Each language's value is its own document, and its language tag still names its prose's language: a code block in @en text stays @en, and a code-only back may be @zxx.

The package

@solid-memo/markdown (packages/lib/markdown/) is the only code that touches the parser, and only in src/parse.ts. The parser is markdown-it, its commonmark preset with its table rule, and markdown-it-cjk-friendly. It keeps a link's URL as written: it encodes, converts or refuses none, as the renderer judges each (liveLink). It gives each block its lines but no place within them, so parse.ts wraps each of its rules to note where in the text each token was read from. What the tree shows as its source, and what a note holds, is the text as written. Everything else sees the package's own tree, folded to what the app shows:

In the textIn the tree
a headinga paragraph in bold: data never adds to the page's outline
raw HTML, block or inlineits source, as text, its hidden characters as markers
a picture, inline or by referenceits alt text: never loaded or linked
a reference linka link to its definition's URL (the first definition of a label wins); definitions show nothing
a code block's info stringits first word, lower-cased, when it matches [a-z0-9+#-]{1,20}; else none
hidden characters in code or link text: every format character (Unicode category Cf, such as the bidi controls U+202A–202E and U+2066–2069, the zero-width characters U+200B–200F, U+2060 and U+FEFF, the soft hyphen U+00AD, the invisible operators U+2061–2064 and the tag characters U+E0000–E007F), and characters that show nothing or look blank yet count (the Hangul fillers U+115F, U+1160, U+3164 and U+FFA0, the combining grapheme joiner U+034F, Khmer's U+17B4–17B5, and the variation selectors U+180B–180F, U+FE00–FE0F and U+E0100–E01EF), a picture's alt text in a link included, and in anything shown as its source, however deep it nestsa visible marker such as ⟨U+202E⟩ ("Trojan Source": code that reads other than it runs)
a table body row's cells past the header'sdropped, as GFM has it; a short row isn't padded
FunctionModuleWhat it gives
parseMarkdown(text)parsethe blocks: paragraph, code, list, quote, rule, table
parseDocument(text)parsethe repository's own Markdown as blocks, its headings kept at their level, or a DocumentError (repository Markdown)
parseInlineMarkdown(text)inlineone line of phrasing: text, code spans, emphasis, strong
plainText(text)plainTextthe text as plain text
labelText(text, max?)plainTexta short name: the plain text of its first block that shows any
liveLink(url)linkswhether a link is followed, and its host
inspectMarkdown(text)parsewhether the text is one paragraph as written (a heading isn't), and notes of what the tree folds away or a check looks at: raw HTML, pictures, links (an autolink told apart), code outside a link, character references, what nests too deep to show as written (and code or a link there with hidden characters), a table past its caps, a heading underlined with dashes
markdownProblems(text, rule)problemswhat wouldn't show as its author meant, by the rules for a release, in a field held to SIDE, OPTION or PROSE
chunksOf(blocks)chunksthe chunks blocks are shown in, split at their top-level rules
splitAtRules(blocks)chunksthe pieces between top-level rules, empty ones included
inspectChunks(text)chunkshow many chunks a text is shown in, and how many empty pieces its rules make

Limits

Every entry point for data is bounded. The limits bound a text's size, its depth and the parser's work on it, never by predicting which shapes of Markdown make the parser slow. Repository Markdown lifts only MAX_CHARS and MAX_WORK.

The package's tests include the cmark and commonmark.js pathological inputs, and the shapes that made the parser before it slow, each at the length cap. Each reads within 25 times what plain prose of the same length takes, or within 4 times what its first eighth takes read eight times over. Time linear in the length gives about once, quadratic time about eight. Both are CPU time, which a busy CI runner doesn't stretch as it does the time on the clock. The costliest shapes the budget lets through each read within 7 times what text like a course's step of the same length takes. Among them are a heading on each line, lists of one-word items, tables of empty rows and a link every few characters. Drawn, a text of links as dense as the budget lets through, inline links or reference links, takes within 10 times what such a step of its length takes, timed on the test's own thread.

Chunks

A step's theory in Markdown is read a chunk at a time (courses.md), split at its thematic breaks (---, *** or ___ on a line of their own). Nowhere else does a break split: in a note or a chapter's description it shows as a rule.

Where it is shown: the profiles

The renderer is packages/ui/src/ui/Markdown.tsx, reached through DataText.tsx (DataText, DataProse for a step's theory, DataLine); nothing else renders text from data as Markdown. A text's profile depends only on the place, never on its deck or course.

ConstructBlock profile (DataText, MarkdownBlocks)Inline profile (DataLine)
Text, emphasis, strong, code spansas suchas such
Paragraphs, hard breaks<p>, <br>joined by a space
Lists, block quotes, thematic breaksas such, but for a step's theory, which is split at its top-level breaks (chunks)items joined by "; ", the rest flattened
Code blocks<pre><code translate="no"> in a region that scrolls sideways, its language as a small labelone code span, white space collapsed
Tablesin a region that scrolls sideways, alignment as md-align-* classescells joined by " · "
Linksfollowed only by liveLink (below)their text

Plain text still renders byte for byte as it did before Markdown.

Keys and screen readers

An example

A card's back, with "Format with Markdown" on:

Make a branch with `git switch -c`, then:

- *stage* the files
- **commit** them

```sh
git add .
git commit
```

On a card's side, See <b>this</b> and [the docs](https://example.org). shows as typed, with three hints while the card is edited: one for each HTML tag ("HTML such as <b> shows as typed. Put it in backticks to show it as code.") and one for the link ("No links here, where they would be in the way of studying: … Put a link in a note."). In a note, where links are followed, only the two about HTML remain.

Repository Markdown

The repository's own Markdown, its docs, is read by the same package in the same dialect. parseDocument(text) is its profile, for trusted input at build time only, never for data:

Diagrams

The site's build in @solid-memo/build-tools (packages/build-tools/) draws the docs' Mermaid blocks to SVG at build time, in Node: diagrams.ts and drawDiagrams.ts. It runs the official Mermaid in Chromium through Playwright, the same parser family and layout engine as GitHub's. GitHub's own Mermaid version and HTML labels differ, so a diagram is still checked there after an edit (style.md).

A drawing is safe to serve

A drawing is only shown through <img>, where nothing in it runs, but its address can be opened on its own, on the app's origin, and GitHub Pages lets the site set no Content Security Policy header. checkSvg takes only what Mermaid writes, and refuses the rest.

Every < opens a plain tag, with no namespace prefix, of an element Mermaid draws the docs' diagram types with. Each attribute is one Mermaid writes (or data-…, aria-…, and the SVG and XLink namespaces at their own addresses), each value is in quotes with no < inside, and the tags close in order. That rules out <script>, event handlers, HTML (<foreignObject>), animation (which could set a link), a document type, comments and CDATA. A character reference is one of XML's five (&amp; and the like), so the text checked is the text the browser reads.

No style or attribute value can load anything (cssProblem): no @import, no image-set(, no backslash (which could spell any of them), no string with : or /, and an href or url( only to #… in the drawing. An SVG in <img> loads nothing from elsewhere, so the font is inside it: the one exception is a single @font-face from a data: WOFF2, allowed only with its notice, the one comment, right after the opening tag.

The diagrams' font

The diagrams are set in Fredoka, the app's own font (vendor-code.md), from @fontsource-variable/fredoka's Latin file. Each drawing embeds it as one data: @font-face, so it looks the same on every machine and its text fits its boxes. Its glyphs, FONT_CHARS, are printable ASCII, Latin-1 but the soft hyphen, and – — ‘ ’ “ ” … −, written out and held to the file's own table by a test. The package's unicode-range declares more than the file has (↑ and ↓ among them). A character outside FONT_CHARS would be drawn and measured in another font, so a block that draws one fails, naming it. So a drawing doesn't depend on the system's fonts, and the jobs that build what's deployed don't install them (testing.md).

Fredoka is under the SIL Open Font License 1.1 (OFL). It may be bundled and embedded in software on four conditions. It isn't sold by itself. Each copy carries its copyright notice and the license (as a file, a human-readable header, or metadata the user can easily see). A modified version uses no Reserved Font Name. The font stays under the OFL, though a document made with it needn't. Fredoka names no Reserved Font Name, and the file is embedded unchanged.

The file holds its copyright but not the license's text, so each drawing starts with a comment (fontNotice). It quotes the copyright line (the first of the package's LICENSE, read at build time), names the license, and says the font stays under it and the drawing doesn't. It points to OFL-Fredoka.txt, the package's LICENSE byte for byte, published beside the drawings. checkSvg refuses the font without that comment. Nothing under the OFL is in the repository, so REUSE.toml and LICENSES/ don't name it.

The docs as a site

The site's build in @solid-memo/build-tools renders the docs to static pages. renderDocsSite in docsSite.ts reads each page of docs/ with parseDocument, and its own emitter writes the HTML, escaping every text, with no way to write raw HTML. publishDocs.ts, the Vite plugin of the site's build (vite.config.ts), emits the pages under docs/. Every build, each release's among them, publishes its own docs at /docs/ (deployment.md); in dev, a page is rendered anew on each request, so an edit shows on reload. The build hands the plugin the repository's address (VITE_REPO_URL, from the site's checked settings), the version, the commit the links name (main, with a warning, when unknown), and the site's origin from CNAME, for each page's canonical address.

renderDocsSite throws one DocsSiteError listing, each with its file and line, every problem that wouldn't show as written or would lead nowhere:

build-tools' tests render the repository's own docs, so npm run check fails on any of these.

The docs' index

Which pages the docs have, in which group and order, and what each covers, is said in one place: docs.ttl, hand-written Turtle. The README holds the title and the introduction and links to it, so GitHub, a tag or a clone shows the list as that file; the site shows it on docs/, under the README's text. Nothing made from it is committed: it exists in the build and in each release's archive.

@base <https://solid-memo.com/docs/> .

@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix schema:  <https://schema.org/> .

<>
    a schema:Collection ;
    dcterms:title "Docs"@en .

<#the-code>
    a schema:Collection ;
    dcterms:title "The code"@en ;
    schema:isPartOf <> ;
    schema:position 20 .

<boundaries.md>
    a schema:TechArticle ;
    schema:isPartOf <#the-code> ;
    schema:position 20 ;
    schema:learningResourceType "reference" ;
    dcterms:abstract "the import rules between packages, as `npm run check:boundaries` enforces them."@en .

npm run check:docs checks that the index lists every page in docs/, and only those, and prints the block to add for a page it doesn't list. npm run format:turtle formats the file, like the Turtle in ns/ and decks/. Its license is stated in REUSE.toml, as the formatter keeps a comment only before a subject.

Safety

Pods and libraries are untrusted: anyone's data may be opened, and most of it never passed npm run library:check. Script on solid-memo.com holds the user's Solid-OIDC session. Every safety rule holds when the text is rendered, and none relies on a check of the data.

ThreatRule
Raw HTML, <script>, <img onerror>Text: the tree has no HTML node.
An HTML sinkNone. The renderer turns each node into one fixed element with fixed attributes; data only becomes text children, never markup, a class, a style, an id or a handler. No dangerouslySetInnerHTML, no sanitizer.
javascript:, data:, http:, mailto:, relative and #/route links, a URL with a user name or passwordShown as their text: only an absolute https: URL without credentials is followed (liveLink). Data can't run script, steer the app, fill in a mail, or hide its host behind user@. An address in a plain-text description follows the same rule. A deck's source and license links are followed for http: too, as sources carry it, but never with user@ (DataLink), and so is the "Report a mistake" link of a release from a link. Any other address the app shows from a pod or a profile, such as a subject on the Validation or Health screens or in the Data check notice, is followed for http: and mailto: too, but never with a user name or password, nor a mailto: address with a query or fragment that would fill in the mail (ExternalLink). Every followed link, a card's picture and a release Studio opens use the address as the URL parser has it, the one that was checked, never the address as written: a browser reads an https: address without // against the page's own address, so as written it could lead elsewhere than the host the check named.
Link spoofingA followed link opens in a new tab and says so. When its text isn't its own URL, or its host is an international one, the host follows it in sight: "the spec (solidproject.org)", punycode kept, so <https://bаnk.example> with a Cyrillic "а" shows "(xn--bnk-6cd.example)". Text counts as its own URL only when each label of its host is the one the URL parser reads, give or take case, or an international one the parser writes in punycode, and its port is the same (writtenHost). A percent escape, an ideographic or full-width dot or letter, an IPv4 address in short form or a default port written out shows the host the link opens. An address in a plain-text description does the same, with its hidden characters as markers, as does a deck's source. Any other address the app shows from a pod or a profile reads with its hidden characters as markers, and as the URL parser has it, punycode kept, when it doesn't name its host as the parser reads it or that host is an international one (ExternalLink). For a deck's source, a title beside its link counts as text that isn't its URL. A license gets a short name such as "CC BY 4.0" only at its address on the Creative Commons or GNU site; any other shows its URL, with its host when it needs one. The link and its host are each isolated against a bidi override in the text before them. The host, and an address shown as itself, run left to right (dir="ltr"); other link text takes its first letter's direction (dir="auto"), so a link in Arabic reads right to left.
Tracking picturesNever loaded: alt text only. Pictures belong in sm:frontImage/sm:backImage, with a description.
Trojan SourceHidden characters in code and link text shown as markers (the package); links isolated from the text around them.
Denial of serviceThe limits above, at every entry point for data, and each text parsed once. A text's line-break opportunities after a slash (breakable, plain text too) come only after a slash between two other characters, neither a slash nor white space, and at most MAX_BREAKS (64) of them; the rest of the text is one string, so slashes add a bounded number of elements to a page. markdownCache.ts keeps the last 500 texts' blocks; the blocks of every chapter description of the last 8 courses whose page was opened, by release (COURSES_KEPT), so opening a course again parses none of them again, for as long as the app is open, an eighth of CACHE_WEIGHT of each course at most, a description past that parsed each time it's shown; a theory's chunks, split from its cached blocks; the plain text of every card of the deck the Studio's workbench searches; the phrasing of every option of the course question shown, for as long as it is shown, so choosing an option, or typing a question in the Studio while its preview asks it, parses none of them again; the phrasing of every wrong option of the card being edited, so typing in its editor parses none of them again and draws again only the options that change; the hints of each language of a text being edited, one text each, so typing checks only the language typed in; the problems of every text of each field rule the Studio's release check reads, for the last draft it checked; and labelText keeps the label of each text's start, so a draft's outline shown again reads none of them again. Each cache of markdownCache.ts kept under a text's hash, the release check's and a deck's health's too, holds no more than CACHE_WEIGHT (64 MiB) in all, counted from each text's length and the objects of what it keeps for it, the oldest going first: the tree of a text of short Markdown lines is many times the size of the text, so a count of texts alone wouldn't bound it. No cache is keyed by a whole text: V8's Map hashes a long string by its length alone, and would compare a lookup with every long text of that length. The chapter descriptions' are kept by position, the labels by a text's start, the hints by field and language entry, and the others under a hash of all of a text's characters (textHash, from a seed drawn once a page), each lookup compared with the one text kept there.

parseDocument lifts MAX_CHARS and is never given data: it reads the repository's own files at build time, and no code that reads a pod or library calls it.

Two checks of the built site hold this (apps/web/src/build.test.ts, over every chunk, the Studio's included):

Rules for a release

A library release is held to more than a pod, so its text shows as its author meant: markdownProblems(text, rule) names what wouldn't. npm run library:check reports it field by field, for every card, step and chapter of a release that states sm:textFormat sm:markdown (deck-library.md). The card editor shows the same problems as hints, never as a block (writing Markdown in the app). A distractor that several marked cards name is checked once, not once for each card.

Problem (code)Why
Raw HTML (html), such as git clone <url>It shows as its source. Write it as code, or escape its <.
A picture (image)Only its alt text shows. A card shows a picture by sm:frontImage/sm:backImage, with a description.
A link where none may be (link): a card's front, back, frontLabel and backLabel and a distractor's distractorText (fields SIDE and OPTION), an autolink <ex:title> or <http://…> includedIt's in the way of the keys that reveal and grade, and of an option's <label>; an autolink loses its angle brackets too. The fix is code.
A link the app doesn't follow (linkNotFollowed), in a note, a step's theory or a chapter's description (field PROSE)Only https: without a user name or password is followed; any other shows as text.
Link text that reads as an address or a host name other than the link's (linkHost)Misleading text: the named host, as written, must be the link's, port included, give or take a www.. A percent escape or a full-width dot in it fails. [solidproject.org](https://www.solidproject.org/) passes; [bank.example](https://evil.example/) and [github.io](https://evil.github.io/) don't. The test is by shape, a dotted word ending in letters: "Node.js" and a file's name such as package.json, v1.ttl or README.md count, even as code. Other wording avoids it ("npm's documentation of package.json"). It checks data only; the defense is the host shown beside a link (safety).
A bidi control, zero-width or other hidden character in code or a link (hiddenControl), nested past MAX_DEPTH tooCode that reads other than it runs ("Trojan Source"); the app shows them as markers.
A character reference outside code (characterReference), such as &aring;CommonMark decodes it: it shows as "å". As code, or with its & escaped (\&aring;), it shows as typed. An unknown name, &nosuchname;, is text and passes.
A heading underlined with dashes (dashHeading): a line of text with --- right under it, no blank line betweenIt looks like text over a thematic break, which a blank line before the --- makes it (ending a chunk in a step's theory). That blank line, or a ## heading, avoids it; === underlining passes.
An option that isn't one paragraph (notOneParagraph): a distractor's distractorText, and the back of a card with distractors (field OPTION)Options show on one line, in the inline profile, and must look alike, or the odd one out gives the answer away. A heading is no paragraph: it shows bold on a revealed back.
Past the limits: longer than MAX_CHARS (tooLong), past MAX_WORK (tooComplex), nested past MAX_DEPTH (tooDeep, unless it's plain text that shows as written anyway, with no hidden characters), a table past its caps (largeTable)The text, or that part of it, shows as plain text or as its source, its hidden characters as markers.

A dense text can have a problem every few characters, so markdownProblems lists at most MAX_PROBLEMS (20) of a text's and then counts the rest (more). The card editor's hints, the Studio's checks and the caches that keep what it finds hold no more than that of a text.

A step's theory is held to its chunks too: none of them empty, and as many in each language, so a learner who switches language keeps their place (deck-library.md). None of these is a safety rule: the safety rules hold when text is rendered, whether or not a check ran.

Writing Markdown in the app

A user's own card is plain text unless its writer says otherwise. The card editor (CardContentFields.tsx, with MarkdownEditing.tsx) has a "Format with Markdown" checkbox, off for a new card (so 2 * 3 * 4 or <tag> stays as typed), the next one in a run too, which keeps the added card's languages.

Wrong options, a step's theory and a chapter's description have no in-app editor (courses.md).

Outside readers

Other Solid apps, and schema.org or DCAT readers of a library, see the Markdown source as the literal's value, which is readable by design. A reader with plain CommonMark shows the asterisks of emphasis that only the CJK-friendly rule reads. So does an app before 1.15 (migrations.md).