How to get AST tree from markdown via remark
Asked Answered
V

1

10

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

Vallejo answered 19/6, 2016 at 6:26 Comment(0)
P
9

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 :)

Psychologist answered 19/6, 2016 at 8:38 Comment(2)
I have the same issue and I've read the docs of remark, but the docs seems too simple, not cover how to get ast.Tavey
The Q/A on this question, How to parse markdown to json using remark, may help.Integrate

© 2022 - 2024 — McMap. All rights reserved.