You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

23 lines
574 B

const fs = require("fs")
const yaml = require("js-yaml")
const unified = require("unified")
const parse = require("remark-parse")
const stringify = require("remark-stringify")
const frontmatter = require("remark-frontmatter")
const select = require("unist-util-select").select
let tree
unified()
.use(parse)
.use(stringify)
.use(frontmatter, ["yaml"])
.use(() => t => (tree = t))
.process(fs.readFileSync("example.md"))
const yamlNode = select("yaml", tree)
const parsedYaml = yaml.safeLoad(yamlNode.value)
console.log(parsedYaml)
module.exports = parsedYaml