-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
33 lines (29 loc) · 1007 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const fs = require('fs')
const util = require('util')
const unified = require('unified')
const markdown = require('remark-parse')
const markdownFile = 'short.md'
const tree = unified().use(markdown).parse(fs.readFileSync(markdownFile, 'utf8'))
function prunePosition(obj) {
for (let property in obj) {
if (obj.hasOwnProperty(property)) {
if (typeof obj[property] == "object") {
if (property === 'position') {
delete obj[property]
} else {
prunePosition(obj[property])
}
}
}
}
}
prunePosition(tree)
fs.writeFileSync('mdast.json', JSON.stringify(tree, null, ' '), 'utf8')
fs.writeFileSync('pandoc-ast.json', JSON.stringify(JSON.parse(fs.readFileSync('pandoc-ast.json', 'utf8')), null, ' '), 'utf8')
/*
console.log(util.inspect(tree, {showHidden: false, depth: null}))
console.log('')
console.log('')
console.log('')
console.log(util.inspect(JSON.parse(fs.readFileSync('pandoc-ast.json', 'utf8')), {showHidden: false, depth: null}))
*/