Files
translation-files/skills/translation/references/markdown-to-djot.md
T
2026-06-18 08:24:11 +08:00

1.8 KiB
Raw Blame History

Markdown to Djot Conversion

When source material arrives as .docx.md (pandoc-converted from docx), convert to .dj for translation workflows.

Splitting combined articles

If a single markdown file contains multiple articles (common when docx has two talks in one file), split at the article boundary before converting. Use sed by line number:

sed -n '1,218p' combined.md > a1.md
sed -n '220,282p' combined.md > a2.md

TOC stripping

Pandoc docx→md produces a markdown TOC with tab-separated page numbers:

[一、对佛教的感悟\t1](#一、对佛教的感悟)
[二、佛教与人类文明\t5](#二、佛教与人类文明)

Strip before conversion:

sed -i '/^\[.*\t.*\](#.*)$/d' input.md

Or in Python: skip lines matching line.startswith("[") and "\t" in line and "](#" in line.

Heading anchor cleanup

Pandoc's docx→md conversion adds {#heading-id} anchors to every heading:

## 1.安宁疗护 {#1.安宁疗护}

These must be stripped before markdown→djot conversion, otherwise pandoc's djot writer leaves stray {#...} lines in the output:

sed 's/ {#[^}]*}//g' input.md > clean.md

Conversion command

pandoc clean.md -f markdown -t djot --wrap=none -o output.dj

--wrap=none prevents reflow of long paragraphs.

Post-conversion cleanup

Pandoc may still leave stray {#...} lines in djot output. Remove them:

sed -i '/^{#.*}$/d' output.dj

Pandoc artifacts

  • Unicode —— (U+2014 × 2) → ------ in djot (two em dashes, --- each). This is correct djot syntax.
  • Markdown hard line breaks (trailing ) → \\\n in djot. Preserves original paragraph structure.
  • Pandoc normalizes heading IDs (strips and other punctuation). Ignore; the stray-line cleanup handles it.