vsch / flexmark-java

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
BSD 2-Clause "Simplified" License
2.29k stars 271 forks source link

Help building a 'simple' extension #539

Open bsutton opened 1 year ago

bsutton commented 1 year ago

We have a database that holds 'textblocks'. These are records in the db that hold small snippets of html or markdown.

I would like to add a new tag to the markdown parser/render.

Something of the likes of:

<textblock page: apagename block: a blockname>

The precise syntax isn't critical.

My aim is to have the parser recognise this new tag and then during the render phase call out to my code so I can do a db lookup based on the page/block attributes and then return the HTML associated with the textblock. If the textblock contains markdown then I would do a recursive parse (but this I can deal with).

I've looked through the examples but they are all rather large and complex and in the readme it suggest that if the extension is more than 200 lines then I'm probably heading in the wrong direction which is why I'm here.

I need some suggestions as where to start from?

ghost commented 1 year ago

KeenWrite has a number of extensions that may serve as additional examples to those packaged with flexmark-java. In order from least to most complex, DocumentOutlineExtension.java, r/RInlineExtension.java and ImageLinkExtension.java files may be worth looking over. The tex/TeXExtension.java is a bit more involved and reasonably encapsulated.