const remark = require('remark');
const visit = require('unist-util-visit');
const got = require('got');
got('http://daynhauhoc.com/raw/29429')
.then((res) => {
// We don't want any part before this line
let data = res.body
const startPos = data.indexOf('### Giới thiệu tổng quan khóa học')
data = data.substring(startPos, data.length)
processMd(data)
})
.catch((error) => console.error(error))
// output tree
const tree = {
name: "root",
children: []
}
// pretty dumb plugin
const plugin = () => {
return function (ast) {
visit(ast, 'text', function (node) {
console.log(node)
})
}
}
const processMd = (data) => {
remark()
.use(plugin)
.process(data, (err, file) => {
if (err) {
throw err
}
console.log('='.repeat(50))
console.log(tree)
});
}