Skip to content

Add definition list rendering extension - #220

Open
soreavis wants to merge 1 commit into
sbarex:mainfrom
soreavis:feature/definition-lists
Open

Add definition list rendering extension#220
soreavis wants to merge 1 commit into
sbarex:mainfrom
soreavis:feature/definition-lists

Conversation

@soreavis

Copy link
Copy Markdown
Contributor

Adds support for definition lists (closes #66). cmark-gfm has no native definition lists, so this is a post-process cmark-extra extension (defl.c), in the same style as the existing heads / inlineimage extensions — the cmark engine itself is untouched.

A term on its own line followed by one or more : description lines is rewritten into <dl>/<dt>/<dd>:

Apple
: Pomaceous fruit of plants of the genus *Malus*.

Markdown
: A lightweight markup language.
: Created by John Gruber in 2004.

<dl>
<dt>Apple</dt>
<dd>Pomaceous fruit of plants of the genus <em>Malus</em>.</dd>
<dt>Markdown</dt>
<dd>A lightweight markup language.</dd>
<dd>Created by John Gruber in 2004.</dd>
</dl>

Multiple terms in one list and one or more definitions per term are supported, matching the Markdown Guide.

Behaviour

  • Off by default. Inline markup in terms and descriptions is preserved (the parsed inlines are moved into the new nodes rather than re-parsed), and it works inside blockquotes.
  • A : line only starts a description when it directly follows a term line, so ordinary paragraphs that happen to contain a colon are unaffected.
  • The bundled default.css already styles dl/dt/dd, so no CSS change is needed.

How it's exposed

  • Preferences UI — a new "Definition list" checkbox in the Extensions grid, wired with bindings exactly like the other extension toggles (value → definitionListExtension, enabled → renderAsCode via NSNegateBoolean).
  • CLI — a --definition-list on|off option.
  • Settings — a definitionListExtension flag (Codable + app-group defaults), defaulting to off.

Examples

  • Adds examples/test-definition-list.md (basic, multiple-descriptions, inline-markup, and blockquote cases).
  • Enriches examples/test1.md — the file shown in the Settings live preview — with a "Definition list extension" section (Apple / Markdown / HTML) and its TOC entry, so the effect is visible the moment the checkbox is toggled.

Changed files

  • cmark-extra/extensions/defl.{c,h}, extra-extensions.c — the extension and its registration
  • QLMarkdown/Settings.swift, Settings+render.swift — the flag and render wiring
  • qlmarkdown_cli/qlmarkdown_cli.swift — the CLI option
  • QLMarkdown/ViewController.swift, Base.lproj/Main.storyboard — the Preferences checkbox
  • examples/test-definition-list.md, examples/test1.md — examples
Light Dark
light dark

Closes #66.

cmark-gfm has no native definition lists, so this adds them as a post-process
cmark-extra extension (defl.c): the compact `term` / `: description` syntax is
rewritten into <dl>/<dt>/<dd>, preserving inline markup and working inside
blockquotes. Off by default behind a Settings flag and a --definition-list CLI
option; the bundled default.css already styles dl/dt/dd. Adds
examples/test-definition-list.md. Re sbarex#66.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: rendering of definition lists

1 participant