From e72b1f0332bfa2a792f42114406ee28df3c3daa2 Mon Sep 17 00:00:00 2001 From: ache Date: Wed, 4 May 2022 00:28:27 +0200 Subject: Support for meta data --- src/build/to-html.mjs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/build/to-html.mjs') diff --git a/src/build/to-html.mjs b/src/build/to-html.mjs index a418b1f..4bc3c06 100644 --- a/src/build/to-html.mjs +++ b/src/build/to-html.mjs @@ -4,6 +4,7 @@ import remarkGfm from 'remark-gfm'; import remarkToc from 'remark-toc'; import remarkDirective from 'remark-directive'; import remarkMath from 'remark-math'; +import remarkFrontmatter from 'remark-frontmatter'; import remarkRehype from 'remark-rehype'; import rehypeSlug from 'rehype-slug'; import rehypeKaTeX from 'rehype-katex'; @@ -29,6 +30,26 @@ const generator = unified() .use(remarkMath) .use(remarkDirective) .use(remarkSpecialBox) + .use(remarkFrontmatter, {type: 'toml', marker: '-'}) + .use(remarkRehype, {allowDangerousHtml: true}) + .use(rehypeRaw) + .use(remarkRemoveFootnoteHeader) + .use(rehypeKaTeX) + .use(rehypeSlug) + .use(rehypeHighlight) + .use(rehypeAutolinkHeadings, autoLinkOption) + .use(rehypeStringify); + +const generatorMd = unified() + .use(remarkParse) + .use(remarkGfm) + .use(remarkToc, {heading: 'Sommaire', tight: true, ordered: true}) + .use(remarkMath) + .use(remarkDirective) + .use(remarkSpecialBox) + .use(remarkFrontmatter, {type: 'toml', marker: '-'}); + +const generatorHTML = unified() .use(remarkRehype, {allowDangerousHtml: true}) .use(rehypeRaw) .use(remarkRemoveFootnoteHeader) @@ -40,6 +61,9 @@ const generator = unified() const toHtml = content => generator.processSync(content); +export const toMdRaw = content => generatorMd.runSync(generatorMd.parse(content)); +export const mdToHtmlRaw = content => generatorHTML.runSync(content); + export const toHtmlRaw = content => generator.runSync(generator.parse(content)); export const toString = content => generator.stringify(content); export default toHtml; -- cgit v1.2.3