mity / md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
MIT License
776 stars 146 forks source link

Use MD4C for syntax highlighter: Passing document parts / single blocks #23

Closed DivineDominion closed 7 years ago

DivineDominion commented 7 years ago

Hi,

MD4C's SAX-like callbacks sound a lot more useful than the reference CMark AST implementation to implement syntax highlighting in an editor. Skimming the code, it appears only reference-style links and images would cause problems if the client does not pass the whole document but only parts of it, like the visible portion on screen or the last edited block of text. Did I get that right?

-- Christian

mity commented 7 years ago

Yes, if you pass to the parser complete blocks, or to be more precise, complete top-level blocks (e.g. complete list, not just single list item), then the references are the only problem.

It has to be top-level blocks in order to deal with sub-lists (list nesting), tight vs. loose lists or quoteblocks.

mity commented 7 years ago

But also note I am not sure whether MD4C (at least without some improvements) can be used for your purpose. It does not provide mapping of parsed things to position (e.g. line number and/or offset) in the input.

With some effort it could be probably added, but honestly, it is currently not on my to-do-list.

DivineDominion commented 7 years ago

Thanks, that clarifies the state of the repo! If you don't want to leave open questions like this tangling, you may close the issue as far as I am concerned. :)