From 1e6f7a276688d00f222dbe2fa0f189ed3deff3aa Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 2 May 2022 02:08:35 +0200 Subject: New version of ache.one --- src/build/to-html.mjs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/build/to-html.mjs (limited to 'src/build/to-html.mjs') diff --git a/src/build/to-html.mjs b/src/build/to-html.mjs new file mode 100644 index 0000000..d8c3a84 --- /dev/null +++ b/src/build/to-html.mjs @@ -0,0 +1,47 @@ +import {unified} from 'unified'; +import remarkParse from 'remark-parse'; +import remarkGfm from 'remark-gfm'; +import remarkToc from 'remark-toc'; +import remarkDirective from 'remark-directive'; +import remarkMath from 'remark-math'; +import remarkRehype from 'remark-rehype'; +import rehypeSlug from 'rehype-slug'; +import rehypeKaTeX from 'rehype-katex'; +import rehypeRaw from 'rehype-raw'; +import rehypeAutolinkHeadings from 'rehype-autolink-headings'; +import rehypeStringify from 'rehype-stringify'; +import rehypeHighlight from 'rehype-highlight'; +import {h} from 'hastscript'; +import remarkSpecialBox from './special_box.mjs'; +import remarkRemoveFootnoteHeader from './remove-footnote-header.mjs'; + +const autoLinkOption = { + behavior: 'wrap', + properties: { + ariaHidden: true, + tabIndex: -1, + className: 'anchor', + }, +}; + +const generator = unified() + .use(remarkParse) + .use(remarkGfm) + .use(remarkToc, {heading: 'Sommaire', tight: true, ordered: true}) + .use(remarkMath) + .use(remarkDirective) + .use(remarkSpecialBox) + .use(remarkRehype, {allowDangerousHtml: true}) + .use(rehypeRaw) + .use(remarkRemoveFootnoteHeader) + .use(rehypeKaTeX) + .use(rehypeSlug) + .use(rehypeHighlight) + .use(rehypeAutolinkHeadings, autoLinkOption) + .use(rehypeStringify); + +const toHtml = content => generator.processSync(content); + +export const toHtmlRaw = content => generator.runSync(generator.parse(content)); +export const toString = content => generator.stringify(content); +export default toHtml; -- cgit v1.2.3