File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { parseFragment } from 'parse5'
2+ import { fromParse5 } from 'hast-util-from-parse5'
3+ import { toMdast } from 'hast-util-to-mdast'
4+ import { toMarkdown as mdastToMarkdown } from 'mdast-util-to-markdown'
5+ import { gfmTableToMarkdown } from 'mdast-util-gfm-table'
6+
7+ export interface HtmlToMarkdownOptions {
8+ /** Whether to pad table columns to equal width (default: `true`). */
9+ tablePipeAlign ?: boolean
10+ }
11+
12+ /**
13+ * Convert an HTML string to Markdown
14+ */
15+ export function htmlToMarkdown ( html : string , options : HtmlToMarkdownOptions = { } ) : string {
16+ const { tablePipeAlign = true } = options
17+ const dom = parseFragment ( html )
18+ const hast = fromParse5 ( dom )
19+ const mdast = toMdast ( hast )
20+ return mdastToMarkdown ( mdast , { extensions : [ gfmTableToMarkdown ( { tablePipeAlign } ) ] } )
21+ }
You can’t perform that action at this time.
0 commit comments