Markdown ↔ K2F Conversion

Overview

Conversion runs in the SDK (markdown_to_k2f, k2f_to_markdown). Never parse Markdown in the agent and emit raw K2F JSON — use the deterministic bridge. Roundtrip targets semantic structure, not lock bytes, theme, or signatures.

Default theme for import: report (embedded in the Python/JS package — not in this skill folder). Fallback: legal.

K2F-specific mapping, skip strings, and <!-- k2f: … --> comments: converting-markdown/mapping.md.

Prerequisites

pip install k2f
cargo install k2f    # for k2f markdown CLI and verify

When to Use

  • User has Markdown → needs .K2F
  • Agent would otherwise output Markdown for a formal deliverable

When NOT to use

  • PDF/HTML as input
  • Full-fidelity MDX or footnotes — v0 skips; extend via writing.md after import

CLI (default)

k2f markdown README.md -o readme.K2F --theme report
k2f markdown ./notes -o ./out --theme report   # directory: mirrors .md → .K2F
k2f verify readme.K2F

Optional covering font: --font path/to/subset.otf.

Other surfaces

SurfaceCallNotes
Pythonmarkdown_to_k2f(md, title=…, template="report") / k2f_to_markdown(bytes)bytes only — no report
JSmarkdownToK2f(md, { title, theme }) / k2fToMarkdown(bytes) after initWasmbytes only
Rustmarkdown_to_k2f(md, opts) → MarkdownResult { bytes, report }Full report

CLI writes the package and does not print warnings.

Validation loop

  1. Convert (k2f markdown / SDK).
  2. Warn user about known skips (footnotes, task boxes, raw HTML, remote images) per mapping.md.
  3. k2f verify on the package.
  4. FONT_MISSING_GLYPH → change the text, or re-run with k2f markdown --font pointing at a covering TTF/OTF. SDK packages embed the theme primary face plus an emoji companion; never fall back to OS fonts.
  5. Patch nodes → writing.md. PDF → exporting-pdf.md.

Failure protocol

SituationAction
Footnotes / MDX / raw HTML / task checkboxesSkipped (warning when report exists); do not claim full conversion
Remote http(s) imageSkipped — use a local path under CWD
Missing local imageSkipped
FONT_MISSING_GLYPHCovering --font, or change text; no OS fonts
Need footnotes as contentKeep in MD or extend tree with writing.md

Common mistakes

MistakeReality
Hand-build JSON from MDCall the bridge
Expect signature / lock in MDExport is unsigned semantics; sign the .K2F package
Emit code_block content typeFence → role code
Assert lock byte equality after roundtripCompare structure, not lock

See also