Replies: 2 comments 1 reply
-
Thank you for starting this conversation. When I switched markdown parser to MD4C for my application I had to drop a feature that the previous parser made possible: localization of input markdown. It is natural for me to think about that use case in relation to MD4C custom syntax constructions. My application, based on the previous parser, supports:
I leave out further details. It seems to me that for an MD4C extension to be able to support the behavior I described, there should be a way to stop parsing at the leaf block level. Perhaps that is what item 4 in your list (custom "block" command) means? What is the "block"? Suppose a custom "block" extension can return the input text of each block, could my application change that text and re-enter the parser with the modified markdown at exactly the same document context of the original block? The |
Beta Was this translation helpful? Give feedback.
-
Block as understood by the CommonMark specification
At the moment, no. And I'm not sure at all whether it's something I want to do: MD4C is not DOM parser, it even never constructs any complete block contents in a single uninterrupted buffer internally. I'm also not very keen on any replacement features: Imho MD4C is and should be "just" a parser. I might consider providing access to "raw block contents" in a form of array of pointers and/or offsets which together make a (leaf) block contents (this would roughly correspond to an array of
Ugh, the Example of this could be a custom feature similar to what github does when auto-linking issues (e.g. Similarly for the suggested example of user mentions, it could verify it's valid/known user name or that it at least follows some (application-specific) idea how usernames may look like. |
Beta Was this translation helpful? Give feedback.
-
I'm now working on a project which will likely need some superset of Markdown syntax. As some of the syntax is too application-specific. I'm not whether to maintain such customization in a fork or whether to (substantially) expand API of vanilla MD4C.
If done, it should likely cover the following uses cases:
Adding simple new emphasis similar to
MD_FLAG_STRIKETHROUGH
extension. Usable e.g. for superscript (e = mc^2^
) or highlighting (==highlight me==
) etc. (With this we wouldn't need to add highly app-specific stuff like LaTeX math equation extention to vanilla code.)Adding simple token-like spans similar to how entities are handled. Usable e.g. for github-like issue auto-linking (
#123
) or user mentions (@johndoe
).Adding custom "inline" commands, optionally with some argument (consider e.g. Doxygen's
@c
command).Adding custom "block" commands, optionally with some argument (consider e.g. Doxygen's
@param
command).Adding custom fenced block, possibly even container block (consider e.g. Doxygen's
@{{
and@}}
commands).Such expansion would significantly make the API more complex. Even though I believe it's possible without breaking backward ABI compatibility, it would likely mean introduction of new (extended)
MD_PARSER
structure (requireing withabi_version
)`:MD_PARSER
(MD_PARSER_v2
?) structure with following changes/additions:MD_PARSER_v2::abi_version
would expect a new value (2).int
instead of enumerations for the block/span/text IDs so that application can add new ones in run-time.My current (incomplete) idea is something like this:
The individual members of
custom[]
would be pointers to helper structures describing how the given extension is to be parsed. For custom emphasis-like spans and token-like spans it might perhaps be something like this:So my questions for potential users of such API are:
Beta Was this translation helpful? Give feedback.
All reactions