Replies: 2 comments
-
goldmark is a CommonMark parser. I recommend reading the CommonMark spec. OK. You have read the emphasis section. OK. you have read the parsing strategy section. I must say "CommonMark is complicated as hell" (as I wrote in README). You seem underestimate complexity of the CommonMark. |
Beta Was this translation helpful? Give feedback.
-
Sorry I should have been more clear. This was more a question of how nesting inline parsers is done on the In the meantime I got it to work so here's what I've gathered. In When we then come across a closing ']', we grab the original Essentially, parsing See https://github.com/yuin/goldmark/blob/v1.5.4/parser/link.go#L239-L244 |
Beta Was this translation helpful? Give feedback.
-
I've stared at
parser/link.go
for hours now but I still can't figure out how it actually does nested inline parsing. There appears to be no general stack of nodes and also no way to change the parent node into which the next, parsed node will be appended. Based on some debugging sessions, my best guess so far is that when the link parser sees the opening[
it leaves a "marker" node in the AST by returning a link label state.When it later on comes across the closing
]
, it will use that sneakily inserted marker node to loop over the siblings and move them into the actual link node and remove them from their parent. Nested emphasis and italic seems to work in an entirely different manner, I guessProcessDelimiters
somehow does this? I don't know.It would be great to have an example of an inline parser that allows arbitrarily nesting stuff inside of it. Both nesting itself, and emphasis.
[%**foo[%bar%]**%]
assuming[% %]
is a new inline parserBeta Was this translation helpful? Give feedback.
All reactions