javascriptdata-structuresmarkdownabstract-syntax-treeremarkjs

How to get AST tree from markdown via remark


using code like this:

var remarkAbstract = require("remark");
var remark = remarkAbstract();

let remark = remarkAbstract();
var ast = remark.process(input);

but it returns output like:

AssertionError: VFile {
  contents: '# header\n\n20 December 2012\n\n![alt](http://yo.io/)\n\ncontent1\n\ncontent2\n\n## header2\n',
  messages: =

I'd like to get AST tree like this


Solution

  • By replacing remark.process(input) with remark.parse(input).

    P.S. Also, this is not a very good question for StackOverflow. I suggest reading up on that :)