deprecated/extractContent.js (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import { readFile, writeFile } from "fs-extra";
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import remarkFrontmatter from "remark-frontmatter";
import rehypeFormat from "rehype-format";
import rehypeRaw from "rehype-raw";
//
//NOTE input: markdown file. output, HTML fragment
//
export async function extractContent(filepath) {
let content;
const processor = await unified()
.use(remarkParse)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeRaw)
.use(remarkFrontmatter)
.use(rehypeFormat)
.use(rehypeStringify)
.process(await readFile(filepath, "utf-8"));
return processor.value;
}
console.log(await extractContent("./input/cookie.md"));
|