Files
backnotprop__plannotator/packages/shared/html-to-markdown.ts
Michael Ramos be2d06a7c2 Make HTML annotations render HTML by default
* feat(annotate): render html files by default

* fix(annotate): support raw html assets and sharing

* fix(annotate): address html first review followups

* fix(editor): avoid raw html sidebar init crash

* fix(annotate): support portable html shares

* fix(annotate): harden html share support

* fix(share): clear attachments when loading shared payloads

* fix(share): warn on remote share link failures

* perf(annotate): lazy-build html share payloads

* test(annotate): guard lazy html share generation

* test(annotate): drop flaky html share server test
2026-06-16 16:16:05 -07:00

33 lines
1005 B
TypeScript

/**
* HTML-to-Markdown conversion via Turndown.
*
* Shared between URL fetching, `annotate --markdown`, and the server's
* on-demand conversion for HTML files in folder mode.
*/
import TurndownService from "turndown";
// @ts-expect-error — @joplin/turndown-plugin-gfm ships JS only, no .d.ts (see declarations.d.ts for local types)
import { gfm } from "@joplin/turndown-plugin-gfm";
const td = new TurndownService({
headingStyle: "atx",
codeBlockStyle: "fenced",
bulletListMarker: "-",
});
td.use(gfm);
// Strip <style> and <script> tags entirely (Turndown keeps unrecognised
// tags as blank by default, but their text content can leak through).
td.remove(["style", "script", "noscript"]);
/**
* Convert an HTML string to Markdown.
*
* Uses a module-level TurndownService singleton (stateless, safe to reuse).
* GFM tables, strikethrough, and task lists are supported via turndown-plugin-gfm.
*/
export function htmlToMarkdown(html: string): string {
return td.turndown(html);
}