Skip to content

So how the hack should I parse frontmatter and markdown to html? #1395

Answered by gentlee
gentlee asked this question in Q&A
Discussion options

You must be logged in to vote

@ChristianMurphy syntax trees are trivial, problem is in API and docs.

Finally managed to get that, thanks, this is how:

import remarkExtractFrontmatter from 'remark-extract-frontmatter'
import remarkFrontmatter from 'remark-frontmatter'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
import {unified} from 'unified'
import yaml from 'yaml'

const parsedArticle = await unified()
  .use(remarkParse)
  .use(remarkFrontmatter)
  .use(remarkExtractFrontmatter, { yaml: yaml.parse, remove: true })
  .use(remarkRehype)
  .use(rehypeStringify)
  .process(await fs.readFile(`article.md`, 'utf-8'))
  
const frontmatter = p…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by gentlee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants