Repository navigation
Conversation
|
Hooray! All contributors have signed the CLA. |
|
Hey @robinst , pls, let me know what do you think about it. |
|
Hey, thanks for raising this. This seems promising, I like the simplicity of the API! A couple of questions/first impressions:
|
|
We implemented extensible inline parsing in the
I am terrible at naming things, but we went with the concept of having "block parsers" and "inline parsers", the latter of which runs after the block has been parsed.
We went with a somewhat-naive solution where all parsers (including both builtin and custom inline parsers) register themselves with a given Individual parsers are not aware of others - we basically stop at a given point in the line and then ask the relevant parsers one-at-a-time if they can parse the text at the given position; if so, they'll parse whatever they can, otherwise we'll try the next eligible parser. They can choose to parse as much or little as they need to. This approach seems to work well for parsing CommonMark and GFM.
We originally tried regexes but found the performance was indeed very slow, so we proceeded to implement a character-based triggering which helped significantly. Our inline parsers provide a list of characters they are "interested in" - if we stop on one of those characters, we hand control over to them and that's when they'll attempt to run the slower regexes. The other benefit to the inline parsers defining a list of characters is that you can dynamically build a regex that can quickly skip through plain text and stop where the next possible inline begins. This overall approach works great in 99% of cases, but we did come across one situation recently where it fell a bit short: thephpleague/commonmark#492 (comment) I'm leaning towards modifying the implementation to allow for both character-based and regex-based hints so we don't lose the performance optimizations. |
Yeah, it seems a preprocessor thing... I can rename following this concept. It makes more sense to me.
Good catch. Yeah, I need to cover this behavior. I tend to assume that the extension should win in this case.
Yeah, I thought about this trade-off performance/power so I came with this initial idea to give more power to the user side code. But yeah, it could be to much power with a serious performance impact.
I thought about this idea to have some character to trigger the extension but I thought that we could have a lot of false positives and that not always we do have some specific characteristics that can define the beginning of some specific text. For example, if from the extension it's considered
Yeah, I guess I came from the other direction first going by powerful then performance side. lol @colinodell But as you both said, it will have performance impact empowered by Number of Extensions. Kind of [line reads] x [Number of Extensions]. @colinodell gave one idea that could be nice which the client could inform one or character sequential, this could be one interesting idea. @robinst Do you think that could be helpful we keep this current approach in this PR where the extension can have the entire line to decide what to do? I will think about the approach to triggered by character/sequence too. |
|
I got interesting numbers here. I tried to build one simple performance test just to compare with/without extension. So, I did narrow: one regular image syntax and one extension node render and the results it looks almost the same. |
|
Adding a second extension the performance got significant impacted. |
944067a to
82748b4
Compare
|
Given that we may need to prioritize the current nodes + the nodes extended, I'm studying a possible new design to support it given that we may need to put all nodes(configurations) in the same bucket to be able to prioritize accordingly. So the ideas that you both gave will be really helpful. The main points for doing this that I'm thinking is:
I hope to commit an idea in the next days to us discuss it and see how the performance is impacted @robinst / @colinodell |
|
(I wrote this reply days ago, but I must have forgotten to submit it and lost it, sorry about that. Typed it again.) @colinodell thanks for that detailed comment, very helpful!
Yes, that's what I was thinking about, as it very closely matches how the existing inline parsing works, see e.g.:
Nice idea, yeah we could do something similar.
Our current autolink extension would have the same problem, as it runs after inline parsing on @samukce replying to this bit:
Yeah, the extension mechanism should be able to handle multiple inline parsers that register for the same trigger character. In the above example, the custom one would be allowed to run first (same as with custom block parsers), and decide whether it wants to handle it or not. @samukce do you feel like working on that? It might seem a bit daunting because it will mean the entire inline parser will change, but it's gonna be a good change. In any case, I think we should do that before we add any regex-based extension mechanism because we'll have a better starting point with it. |
|
Yes @robinst, I agree. I am doing a small POC to us discuss over given that this idea could mean some huge changes in our codebase. I hope until the weekend I commit the code so we can talk about the idea. :) |
|
hello @robinst, sorry for so later answer...lately I have been really busy here =/ . I let you know if I have a chance to get back to this one 🤞 |

This PR is one idea to make an extensible inline process through the interface
NodeExtensionwhere the client can implement how they want that the parser understanding the nodes in that line by the methodList<InlineBreakdown> lookup(String input);.So taking this case for example noties/Markwon#67.
The user needs to make the inline parser understanding how to handle this new format
~bug ~"Multiple word fea"For this one is just needed one extension that based on the line provides the Nodes(or Custom Nodes) with their respective line positions:
There are some conventions in the case of conflicts such as:
Pls, let me know what do you think and about the terminologies that I tried. All feedback is very welcome.
#113