sirthias / pegdown

A pure-Java Markdown processor based on a parboiled PEG parser supporting a number of extensions
http://pegdown.org
Apache License 2.0
1.29k stars 217 forks source link

Write the AST back to a MD document #241

Closed brentgracey closed 8 years ago

brentgracey commented 8 years ago

Hello; this is more of a 'clarification question' than reporting an actual issue- so please just close it out if this isn't an appropriate channel to do that via.

I'm looking to create something like a 'ToMdSerializer implements Visitor' in order to serialize an AST back to its original mark down text form.

I would just like to know if this is possible from the information held in the AST? I'm wondering if the parser is focused on being able to create HTML output; so might not capture some data; which would be needed to re-construct the original document.

Thanks, Brent

miurahr commented 8 years ago

I've implemented MdToInternal and InternalToMd functionality in my project. I found that we can reproduce Md from an AST and original char[] text combination. Each node has getStartIndex() and getEndIndex(). You can parse original text using these indexes.

brentgracey commented 8 years ago

Hi; thanks for the suggestion; I have indeed used the index values to grab out the sub-strings I'm interested in. Thanks again