Confusion about Implementing Global Inline Parsers #191

Closed
opened 2026-01-29 14:29:56 +00:00 by claunia · 1 comment
Owner

Originally created by @QbDesu on GitHub (Feb 19, 2018).

Hello there,
I'm trying to write an InlineParser that works without specifying opening characters. However I can't seem to get it to work. To be more specific about it, when I try to add an Inline Object at a place that isn't the begining of current slice I also wind up deleting whatever comes before the target slice.

            processor.Inline = new LiteralInline(content)
            {
                Span =
                {
                    Start = startPosition + index,
                },
                Line = 0,
                Column = 0
            };
            processor.Inline.Span.End = processor.Inline.Span.Start + length - 1;
            slice.Start += index + length;

            return true;

I don't know if I'm supposed to do things differently. Maybe I'm supposed to add InlineLiterals for the segments that weren't matched too. But I still want other parsers to do their thing with the other segments.

Originally created by @QbDesu on GitHub (Feb 19, 2018). Hello there, I'm trying to write an InlineParser that works without specifying opening characters. However I can't seem to get it to work. To be more specific about it, when I try to add an Inline Object at a place that isn't the begining of current slice I also wind up deleting whatever comes before the target slice. ``` processor.Inline = new LiteralInline(content) { Span = { Start = startPosition + index, }, Line = 0, Column = 0 }; processor.Inline.Span.End = processor.Inline.Span.Start + length - 1; slice.Start += index + length; return true; ``` I don't know if I'm supposed to do things differently. Maybe I'm supposed to add InlineLiterals for the segments that weren't matched too. But I still want other parsers to do their thing with the other segments.
claunia added the question label 2026-01-29 14:29:56 +00:00
Author
Owner

@xoofx commented on GitHub (Apr 4, 2018):

I don't recall exactly the restrictions on the InlineParser (as It was evolved during the development)... but a LiteralInlineParser is optimized to be somehow the only global inline parser, as it is relying on the information of other parsers (opening characters), to efficiently grab as many characters it can.

So I believe that the only way to have this working is to replace the LiteralInlineParser with your own... maybe you can inherit from it... but if the starting characters are not clear, you may have to develop an entire new LiteralInlineParser for your use case.

@xoofx commented on GitHub (Apr 4, 2018): I don't recall exactly the restrictions on the InlineParser (as It was evolved during the development)... but a LiteralInlineParser is optimized to be somehow the only global inline parser, as it is relying on the information of other parsers (opening characters), to efficiently grab as many characters it can. So I believe that the only way to have this working is to replace the LiteralInlineParser with your own... maybe you can inherit from it... but if the starting characters are not clear, you may have to develop an entire new LiteralInlineParser for your use case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#191