{"slug": "markdown-to-html-0-llm-tokens-for-4-posts-23-faqs-extracted", "title": "Markdown to HTML: 0 LLM Tokens for 4 Posts, 23 FAQs Extracted", "summary": "A developer built a deterministic Markdown-to-HTML converter that published four manuscripts (43,699 bytes) using zero LLM tokens, automatically extracting 23 FAQ questions while all four posts passed built-in self-checks. The converter exits with code 1 on spec violations and reports faq_count and html_len to catch formatting drift, stripping the H1 from the body and pulling FAQ entries only from the FAQ section to avoid structured-data mismatches. The developer argues scripts should handle fixed-format conversion where output must be byte-for-byte reproducible, reserving LLMs for work that requires judgment.", "body_md": "We needed to publish four manuscripts (43,699 bytes in total) that another project had handed over, and the obvious move was to ask an LLM to turn the markdown into HTML. We wrote a deterministic converter instead. It used zero LLM tokens, extracted 23 FAQ questions automatically, and all four posts passed its built-in checks. The reason is not cost. The manuscripts already contained values that had been cross-checked by hand, such as notice numbers and page numbers, so changing a single character during formatting would itself be a defect.\n\nThis post covers the rule we use to decide between a script and an LLM, what the converter actually does, and the two publishing traps it closed without anyone having to remember them.\n\nAsk these about the step you are about to automate. A single \"yes\" means use a script.\n\n| Question | If yes | If no | \n|---|---|---|\n| Must the same input always give the same output? | Script | LLM is fine | \n| Must source values stay byte-for-byte unchanged? | Script | LLM is fine | \n| Can pass or fail be decided automatically from an exit code? | Script | LLM is fine | \n\nOur conversion answered yes to all three. The manuscripts already followed a fixed layout (title, three-line summary, tables, a Q/A list), the rules for turning that layout into tags were unambiguous, and compliance could be checked with plain string searches. Work that needs judgment, such as summarizing, restructuring, or adjusting tone, belongs to the LLM. Moving a fixed format into fixed tags does not. The short version: if judgment is needed, use an LLM; if there is a rule, use a script.\n\nThere is a cost argument too, but it is the weakest of the three. A few posts are cheap either way, yet an LLM step also gives you a different output on each run and a chance to quietly touch a number. Those two problems are what actually hurt.\n\nThe script takes one markdown file and produces body HTML plus a metadata JSON. If it finds a spec violation it exits with code 1.\n\n```\npython -X utf8 scripts/publish/md2bsp.py post.md out/body.html --meta out/meta.json\n```\n\nStandard output is two lines. The first is the metadata, the second is the self-check result:\n\n```\n{\"title\": \"<from the H1>\", \"excerpt\": \"<first item of the 3-line summary>\", \"faq_count\": <n>, \"html_len\": <n>, \"src\": \"post.md\"}\nself-check: PASS\n```\n\n(The full manuscript and converter output checklists are in the [original post](https://my-blog.org/claude-code/post/md-to-html-do-not-use-llm?utm_source=devto&utm_medium=referral&utm_campaign=md-to-html-do-not-use-llm).) Two numbers catch most formatting accidents. If `faq_count` differs from what you expect, the Q/A format in the manuscript drifted. If `html_len` is far smaller than the source, part of the body was not parsed.\n\nThe converter also removes the H1 from the body and uses the first summary item as the excerpt. Our platform renders the title separately, so leaving the H1 in the body would show it twice.\n\nFAQ entries are pulled only from the FAQ section of the body. That keeps the structured data from containing questions the page never shows, which search engines flag as a mismatch. A runnable version of the idea looks like this:\n\n``` python\nimport re\n\ndef extract_faq(md):\n    m = re.search(r\"\\n##\\s*FAQ\\s*\\n(.*?)(?=\\n##\\s|\\Z)\", md, re.S)\n    if not m:\n        return []\n    return re.findall(\n        r\"\\*\\*Q\\.\\s*(.+?)\\*\\*\\s*\\n\\s*A\\.\\s*(.+?)(?=\\n\\s*\\n|\\Z)\",\n        m.group(1), re.S,\n    )\n\nsample = \"\\n## FAQ\\n**Q. Why a script?**\\nA. Same input, same output.\\n\\n** Q. Cost?**\\nA. Zero tokens.\\n\"\nprint(len(extract_faq(sample)))  # 2\n```\n\nThe regular expression enforces the format. If the section heading differs, the question line is styled differently, or an answer does not begin with `A.`, that pair is simply not captured. In other words, the manuscript format becomes the parser's input specification. On these four posts the approach extracted 23 questions with no manual step.\n\nThe last block of the converter counts the things that must not ship: a leftover style block, a leftover `h1` tag, a leftover `TODO` marker, a leftover emoji, or a missing title. Any hit makes the process exit with 1.\n\n``` python\nimport re\n\ndef check(html, title):\n    bad = []\n    if \"<style\" in html:\n        bad.append(\"style block left\")\n    if \"<h1\" in html:\n        bad.append(\"h1 left\")\n    if \"TODO\" in html:\n        bad.append(\"TODO left\")\n    if re.search(\"[\\U0001F300-\\U0001FAFF]\", html):\n        bad.append(\"emoji left\")\n    if not title:\n        bad.append(\"no H1 title\")\n    print(\"self-check:\", \"PASS\" if not bad else \"FAIL \" + \" / \".join(bad))\n    return 0 if not bad else 1\n```\n\nWith an LLM you would have to write \"do not include a style block\" into the prompt every time and then eyeball the result. A script holds the rule in code, so it does not forget, and a pipeline only has to look at whether the exit code is 0. All four posts passed.\n\nThe first trap is CSS leaking across the whole site. Our blog renderer lifts style definitions found inside a post body up into the page-level head, so CSS written for one post can change others. The converter never emits a style block. It keeps a per-tag style dictionary and injects the styles inline:\n\n``` python\nimport re\n\nhtml = \"<h2>Title</h2><p class='x'>Body</p><table><tr><td>cell</td></tr></table>\"\nS = {\n    \"h2\": \"font-size:1.5rem;font-weight:700;margin:2.4rem 0 .9rem;\",\n    \"p\":  \"line-height:1.85;margin:0 0 1.05rem;\",\n    \"td\": \"border:1px solid #e2e8f0;padding:.62rem .7rem;vertical-align:top;\",\n}\nfor tag, css in S.items():\n    html = re.sub(rf\"<{tag}(?=[ >])\", f'<{tag} style=\"{css}\"', html)\n    html = html.replace(f\"<{tag}>\", f'<{tag} style=\"{css}\">')\n```\n\nTables are wrapped in an `overflow-x:auto` container in the same pass, so a wide table scrolls instead of pushing the whole page sideways on mobile.\n\nThe second trap was duplicated JSON-LD, and it came from the handoff document, not from the script. The spec said to put a BlogPosting block in the body. The front end already generates BlogPosting in the head, so following the spec literally would have produced duplicate structured data. Reading the receiving code while building the converter showed that only a FAQPage block belonged in the body.\n\nThe lesson is about order, not about this spec: read the receiving code before executing a handoff document. A spec is true as of the day it was written, and the system on the other side may have changed since.\n\nA deterministic converter is only deterministic if the input follows the spec. Otherwise it silently drops things.\n\n| Failure condition | Symptom | Fix | \n|---|---|---|\n| FAQ heading differs | `faq_count` is 0 | Rename the H2 in the manuscript | \n| Q/A pairs with no blank line between them | Several pairs merge into one | Add a blank line between pairs | \n| No H1 | Exit code 1, \"no H1 title\" | Put a `# Title` on the first line | \n| Manuscripts arrive in different formats each time | The rules do not hold | Agree on a format first, or keep a human on this step | \n\nSome limits are worth stating plainly. This converter is built for our blog platform. The per-tag inline styles and the \"no style block\" rule exist because our renderer hoists styles globally, and another platform may not have that constraint. Markdown parsing relies on an external library and its extensions (tables, sane_lists, nl2br), so a version change can alter the output. And the approach only fits steps that need no judgment: writing the manuscript is still the LLM's job. Split a publishing pipeline along that line, with evidence gathering, machine verification, and layout in scripts and first drafts from the LLM.\n\nThe original write-up, including the pre-publish checklist for manuscripts and converter output, is here: [the full post on my-blog.org](https://my-blog.org/claude-code/post/md-to-html-do-not-use-llm?utm_source=devto&utm_medium=referral&utm_campaign=md-to-html-do-not-use-llm).\n\n*Free tools I keep on my own site: [34 calculators and how-to guides](https://my-blog.org/tools?utm_source=devto&utm_medium=referral&utm_campaign=md-to-html-do-not-use-llm) - loans, severance pay, take-home salary, savings vs deposits. New ones go out in one email, no ads.*", "url": "https://wpnews.pro/news/markdown-to-html-0-llm-tokens-for-4-posts-23-faqs-extracted", "canonical_source": "https://dev.to/sungwoo_lee_e0f26be4a29fd/markdown-to-html-0-llm-tokens-for-4-posts-23-faqs-extracted-1km", "published_at": "2026-11-20 23:34:31+00:00", "updated_at": "2026-11-20 23:44:32.841227+00:00", "lang": "en", "topics": ["structured-data", "ai-tools", "developer-tools"], "entities": ["Claude Code"], "also_reported_by": [], "takeaway": "Use a deterministic script instead of an LLM when the same input must always yield the same output and source values must stay byte-for-byte unchanged; the converter extracted 23 FAQ questions and passed self-checks on four posts at zero tokens.", "recommendation": {"advice": "Route fixed-format conversion to a script that exits non-zero on spec violations and reports faq_count and html_len, reserving LLM calls for tasks that need judgment.", "playbook": "llm-cost", "playbook_url": "https://wpnews.pro/playbooks/llm-cost"}, "alternates": {"html": "https://wpnews.pro/news/markdown-to-html-0-llm-tokens-for-4-posts-23-faqs-extracted", "markdown": "https://wpnews.pro/news/markdown-to-html-0-llm-tokens-for-4-posts-23-faqs-extracted.md", "text": "https://wpnews.pro/news/markdown-to-html-0-llm-tokens-for-4-posts-23-faqs-extracted.txt", "jsonld": "https://wpnews.pro/news/markdown-to-html-0-llm-tokens-for-4-posts-23-faqs-extracted.jsonld"}}