Skip to content

Commit

Permalink
feat: add remarkPlugins/rehypePlugins options.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 25, 2022
1 parent cc54aa9 commit 226cd10
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/html-to-markdown/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unified } from 'unified';
import { unified, PluggableList } from 'unified';
import rehypeParse, { Options as RehypeParseOptions} from 'rehype-parse';
import rehypeRemark from 'rehype-remark';
import remarkStringify from 'remark-stringify';
Expand All @@ -11,17 +11,23 @@ type Options = {
html?: string
url?: string
rehypeParseOption?: RehypeParseOptions;
/** List of [remark plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md#list-of-plugins) to use. See the next section for examples on how to pass options */
remarkPlugins?: PluggableList;
/** List of [rehype plugins](https://github.com/rehypejs/rehype/blob/main/doc/plugins.md#list-of-plugins) to use. See the next section for examples on how to pass options */
rehypePlugins?: PluggableList;
}

export default async function htmlToMarkdown(options: Options = {}) {
const { rehypeParseOption } = options;
const { rehypeParseOption, remarkPlugins = [], rehypePlugins = [] } = options;
const file = await unified()
.use(rehypeParse, { fragment: true, ...rehypeParseOption })
.use(rehypeRemark)
.use(rehypeIgnore)
.use(remarkGfm)
.use(rehypeVideo)
.use(rehypeIgnore)
.use(rehypeFormat)
.use(remarkPlugins || [])
.use(rehypePlugins || [])
.use(remarkStringify)
.processSync(options.html)
return String(file);
Expand Down

0 comments on commit 226cd10

Please sign in to comment.