Several markdown files concatted into one html file? #124
-
Hello, Firstly, thanks for the massive amount of work that has gone into all these packages! I've been working with Unified for about a week now and it's been a pleasure. I've been tasked with creating a build tool which processes existing Markdown files into HTML. These Markdown files are sections which should be joined to form one HTML file. I've not found any documentation or packages accommodating this, and trying shoehorn it myself has caused a couple problems. My plan was to For example this works for one Markdown import embedImages from 'remark-embed-images'; // <-- this is part of the problem
const processor = unified()
.use(remarkParse)
.use(embedImages)
.use(myPluginA)
.use(myPluginB)
.use(myPluginC)
.use(remark2rehype)
.use(rehypeDocument)
.use(rehypeStringify);
processor.process(vfile, (err, file) => {
report(err || file)
console.log(String(file))
}) When I try to split it up a bit: const parsed = processor.parse(vfile);
const transformed = await processor.run(parsed);
const compiled = processor.stringify(transformed);
One solution that does work is to Am I barking up the wrong tree? Any pointers on how to do this would be very helpful! Cheers. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
you’re close! you can pass the But indeed, unified is a pipeline for a single file, so here we’d need two: const firstProcessor = unified()
.use(remarkParse)
.use(embedImages)
// ..
.use(remark2rehype)
// .parse and .run all markdown files, to get `hasts` (an array of HTML ASTs).
// Make that into a single HTML document
var hast = {type: 'root', children: hasts.flatMap(d => d.children)}
const secondProcessor = unified()
// Use rehhype plugins that run on the whole document
// ..
.use(rehypeStringify)
// .run and .stringify the single `hast`. (or only stringify if there are no rehype plugins which should run on the whole) |
Beta Was this translation helpful? Give feedback.
you’re close! you can pass the
vfile
to parse, but also torun
(and stringify), as the second parameter!But indeed, unified is a pipeline for a single file, so here we’d need two: