Skip to content

feat(documents): htmlToMarkdown and markdownToHtml for blog bodies - #3112

Merged
leemour merged 1 commit into
mainfrom
feat/html-markdown
Nov 18, 2026
Merged

leemour merged 1 commit into
mainfrom
feat/html-markdown

Conversation

@leemour

@leemour leemour commented Nov 18, 2026

Copy link
Copy Markdown
Member

Task

Give content CLIs (WordPress, Ghost) one way to turn a post body from HTML into Markdown and back.

Why

A blog keeps HTML; a CLI shows and takes Markdown. Each content CLI writing its own converter would repeat the same untrusted-input rules, so they live in @wirecat/cli-core/documents.

What

  • htmlToMarkdown and markdownToHtml, built on unified's hast-util-from-html, hast-util-to-mdast, mdast-util-to-hast and hast-util-to-html, loaded on first use.
  • A post body is untrusted: raw HTML (WordPress block comments, Ghost card comments), scripts, styles, frames and event attributes go; links and images with a scheme other than http(s), mailto or tel keep only their text; a reference whose first definition is unsafe stays unlinked.
  • docs/dev/DOCUMENTS.md describes both and notes the risk of writing a converted body back (what the conversion drops is lost on save).

Testing

  • Module tests on one post as WordPress 6.9.4 stores and renders it and as Ghost 6.78.0 renders it (fixtures in test/fixtures/posts/); Markdown that went through HTML once comes back the same.
  • Full local suite: 930 files, 12,583 tests passed. Typecheck, lint and docs check pass.

🤖 Generated with Claude Code

A blog keeps HTML (WordPress, Ghost) and a CLI shows and takes Markdown. Both directions treat the body as
untrusted: raw HTML (including WordPress block and Ghost card comments), scripts, styles, frames and event
attributes go, and links and images with a scheme other than http(s), mailto or tel keep only their text. A
reference whose first definition is unsafe stays unlinked. Tested on one post as WordPress 6.9.4 stores and renders
it and as Ghost 6.78.0 renders it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leemour
leemour merged commit 84773c5 into main Nov 18, 2026
46 of 49 checks passed
@leemour
leemour deleted the feat/html-markdown branch November 18, 2026 10:11
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.

1 participant