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.
18 lines
454 B
18 lines
454 B
import fs from "fs"
|
|
import markdown from "remark-parse"
|
|
import stringify from "remark-stringify"
|
|
import unified from "unified"
|
|
import util from "unist-util-select"
|
|
const { selectAll } = util
|
|
|
|
let mdast
|
|
unified()
|
|
.use(markdown)
|
|
.use(() => tree => (mdast = tree))
|
|
.use(stringify)
|
|
.process(fs.readFileSync("post.md"))
|
|
|
|
const headingsNodes = selectAll("heading[depth=2]", mdast)
|
|
const json = JSON.stringify(headingsNodes, null, 2)
|
|
|
|
console.log(json)
|
|
|