Skip to content

How can I replace frontmatter before parsing it? #1285

Answered by ChristianMurphy
ben519 asked this question in Q&A
Discussion options

You must be logged in to vote

Two things to note:

  1. note that yaml AST nodes do not include --- in their content, adding this in the replacement makes it invalid
  2. note that one of your plugins modifies the AST, the other works on vFile. these are two separate things. If you want to get the updates in the AST read the YAML from the AST.

Working example https://stackblitz.com/edit/node-ts1rqw

source from sandbox
import remarkFrontmatter from 'remark-frontmatter';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import { unified } from 'unified';
import yaml from 'yaml';

import { EXIT, visit } from 'unist-util-visit';

// ==============================================================

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ben519
Comment options

@ChristianMurphy
Comment options

Answer selected by ben519
@ben519
Comment options

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