russross / blackfriday

Blackfriday: a markdown processor for Go
Other
5.42k stars 598 forks source link

Documentation for the AST / terminal renderer #545

Open MichaelMure opened 5 years ago

MichaelMure commented 5 years ago

It would be super useful to have a short documentation on the AST to explain:

For some context, I'm in the process of writing a renderer for the terminal, with ANSI escape code for the formatting and proper text wrapping, and it's fairly complicated to extract from the code exactly what is possible.

Here is my current understanding, is that correct ?

image

PlantUML code to generate it ``` @startuml (*) --> Document Document --> BlockQuote Document --> List Document --> Paragraph Document --> Heading Document --> Emph Document --> Strong Document --> Del Document --> Link Document --> Image Document --> Table Document --> HorizontalRule Document --> Text Document --> HTMLBlock Document --> CodeBlock Document --> Softbreak Document --> Hardbreak Document --> Code Document --> HTMLSpan BlockQuote --> BlockQuote BlockQuote --> List BlockQuote --> Paragraph BlockQuote --> Heading BlockQuote --> Emph BlockQuote --> Strong BlockQuote --> Del BlockQuote --> Link BlockQuote --> Image BlockQuote --> Table BlockQuote --> HorizontalRule BlockQuote --> Text BlockQuote --> HTMLBlock BlockQuote --> CodeBlock BlockQuote --> Softbreak BlockQuote --> Hardbreak BlockQuote --> Code BlockQuote --> HTMLSpan Item --> BlockQuote Item --> List Item --> Paragraph Item --> Heading Item --> Emph Item --> Strong Item --> Del Item --> Link Item --> Image Item --> Table Item --> HorizontalRule Item --> Text Item --> HTMLBlock Item --> CodeBlock Item --> Softbreak Item --> Hardbreak Item --> Code Item --> HTMLSpan List --> Item Table --> TableHead Table --> TableBody TableHead --> TableRow TableBody --> TableRow TableRow --> TableCell @enduml ```

WIP renderer is hover there: https://github.com/MichaelMure/git-bug/pull/165 Of course, any help with that is much welcome. I can also re-license when it's done so it can be integrated here.

Some rendering examples: image image

MichaelMure commented 5 years ago

I kinda bruteforced the parser with a custom renderer that output the node relationship in a plantUML format and feeded it all the test samples that are in this repo. I end up with the following which seems to make much more sense. Is that correct ? Is there everything ?

image

MichaelMure commented 5 years ago

I probably have all the cases now .. image

MichaelMure commented 5 years ago

FYI, I moved the WIP renderer into its own package over there: https://github.com/MichaelMure/go-term-markdown

MIT license.