micromark / micromark-extension-frontmatter

micromark extension to support frontmatter (YAML, TOML, etc)
https://unifiedjs.com
MIT License
20 stars 2 forks source link

Can't get metadata. #7

Closed guillevg closed 9 months ago

guillevg commented 9 months ago

Initial checklist

Affected packages and versions

2.0.0

Link to runnable example

No response

Steps to reproduce

I am trying to extract metadata from the frontmatter of a markdown file. The following code does work, but I only get the HTML from the markdown.

import {micromark} from 'https://esm.sh/micromark@3?bundle'
import {frontmatter, frontmatterHtml} from 'https://esm.sh/micromark-extension-frontmatter@2?bundle'
import {math, mathHtml} from 'https://esm.sh/micromark-extension-math@3?bundle'

fetch('math_document.md')
  .then(response => response.text())
  .then((data) => {
    const output = micromark(data, {
      extensions: [math(), frontmatter()],
      htmlExtensions: [mathHtml(), frontmatterHtml()]
    });
    console.log(output);
  })

Expected behavior

I would like to get an object with both the HTML and the metadata.

Actual behavior

I only get HTML. It's as if the only thing this extension does is remove the frontmatter to leave only markdown? Any step in the right direction would be greatly appreciated.

Runtime

No response

Package manager

No response

OS

No response

Build and bundle tools

No response

wooorm commented 9 months ago

That’s not what this project does. micromark is a markdown parser. It parses markdown. This package is an extension for micromark to allow different fronmatter syntax extensions in markdown.

These things are not YAML parsers. If you want to parse YAML, use a YAML parser. And something that understands YAML frontmatter. Here’s a convenience wrapper to do both: https://github.com/vfile/vfile-matter.

github-actions[bot] commented 9 months ago

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.

guillevg commented 9 months ago

All clear now. Thank you!