Skip to content

How to obtain parsed frontmatter using micromark #145

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

You must be logged in to vote

Thank you!

I'm not sure if any of the below is the best way of doing things.

Here's mdast-util-from-markdown:

import {fromMarkdown} from 'https://esm.sh/mdast-util-from-markdown@1?bundle'
import {toMarkdown} from 'https://esm.sh/mdast-util-to-markdown@1?bundle'
import {frontmatter} from 'https://esm.sh/micromark-extension-frontmatter@1?bundle'
import {frontmatterFromMarkdown, frontmatterToMarkdown} from 'https://esm.sh/mdast-util-frontmatter@1?bundle'
import yaml from 'https://esm.sh/js-yaml@1?bundle'
 

export const strToMarkdown = (value) => {
  const presets = ['yaml']
  const tree = fromMarkdown(value, {
    extensions: [frontmatter(presets)],
    mdastExtensions: [frontmatterFromMark…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@wooorm
Comment options

@Xananax
Comment options

Answer selected by Xananax
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