Skip to content

How would I parse markdown frontmatter into rehype-document properties #548

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

You must be logged in to vote

I came up with this code:

import unified from 'unified';
import markdown from 'remark-parse';
import remark2rehype from 'remark-rehype';
import stringify from 'rehype-stringify';
import raw from 'rehype-raw';
import frontmatter from 'remark-frontmatter';
import extract from 'remark-extract-frontmatter';
import meta from 'rehype-meta';
import gfm from 'remark-gfm';

import yaml from 'yaml';

// npm install --save-dev yaml unified remark-parse remark-rehype rehype-stringify rehype-raw remark-frontmatter remark-extract-frontmatter rehype-meta remark-gfm

const logger = (options) =>
  (tree, file) =>
    console.log(
      JSON.stringify(tree, null, 2).substr(0, 1000),
    );

unified()
  .use(

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@ilyaigpetrov
Comment options

Comment options

You must be logged in to vote
1 reply
@wooorm
Comment options

Comment options

You must be logged in to vote
1 reply
@wooorm
Comment options

Answer selected by ilyaigpetrov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants