src/Markdig/Parsers/InlineProcessor.cs
/// <summary>
/// Processes the inline of the specified <see cref="LeafBlock"/>.
/// </summary>
/// <param name="leafBlock">The leaf block.</param>
Processes the inline of the specified .
Processes the inline of the specified .
public void ProcessInlineLeaf(LeafBlock leafBlock)
        {
            if (leafBlock is null) ThrowHelper.ArgumentNullException_leafBlock();
            Array.Clear(ParserStates, 0, ParserStates.Length);
            Root = new ContainerInline() { IsClosed = false };
            leafBlock.Inline = Root;
            Inline = null;
            Block = leafBlock;
            BlockNew = null;
            LineIndex = leafBlock.Line;
            previousSliceOffset = 0;
            previousLineIndexForSliceOffset = 0;
            lineOffsets.Clear();
            var text = leafBlock.Lines.ToSlice(lineOffsets);
            leafBlock.Lines.Release();
            int previousStart = -1;
            while (!text.IsEmpty)
            {
                if (previousStart == text.Start)
                {
                    ThrowHelper.InvalidOperationException($"The parser is in an invalid infinite loop while trying to parse inlines for block [{leafBlock.GetType().Name}] at position ({leafBlock.ToPositionText()}");
                }
                previousStart = text.Start;
                var c = text.CurrentChar;
                var textSaved = text;
                var parsers = Parsers.GetParsersForOpeningCharacter(c);
                if (parsers != null)
                {
                    for (int i = 0; i < parsers.Length; i++)
                    {
                        text = textSaved;
                        if (parsers[i].Match(this, ref text))
                        {
                            goto done;
                        }
                    }
                }
                parsers = Parsers.GlobalParsers;
                if (parsers != null)
                {
                    for (int i = 0; i < parsers.Length; i++)
                    {
                        text = textSaved;
                        if (parsers[i].Match(this, ref text))
                        {
                            goto done;
                        }
                    }
                }
                text = textSaved;
                LiteralInlineParser.Match(this, ref text);
                done:
                var nextInline = Inline;
                if (nextInline != null)
                {
                    if (nextInline.Parent is null)
                    {
                        var container = FindLastContainer();
                        if (!ReferenceEquals(container, nextInline))
                        {
                            container.AppendChild(nextInline);
                        }
                        if (container == Root)
                        {
                            if (container.Span.IsEmpty)
                            {
                                container.Span = nextInline.Span;
                            }
                            container.Span.End = nextInline.Span.End;
                        }
                    }
                }
                else
                {
                    var container = FindLastContainer();
                    Inline = container.LastChild is LeafInline ? container.LastChild : container;
                    if (Inline == Root)
                    {
                        Inline = null;
                    }
                }
            }
            if (TrackTrivia)
            {
                if (!(leafBlock is HeadingBlock))
                {
                    var newLine = leafBlock.NewLine;
                    leafBlock.Inline.AppendChild(new LineBreakInline { NewLine = newLine });
                }
            }
            Inline = null;
            PostProcessInlines(0, Root, null, true);
        }
public void ProcessInlineLeaf ( LeafBlock leafBlock ) { if ( leafBlock is null ) ThrowHelper . ArgumentNullException_leafBlock ( ) ; Array . Clear ( ParserStates , 0 , ParserStates . Length ) ; Root = new ContainerInline ( ) { IsClosed = false } ; leafBlock . Inline = Root ; Inline = null ; Block = leafBlock ; BlockNew = null ; LineIndex = leafBlock . Line ; previousSliceOffset = 0 ; previousLineIndexForSliceOffset = 0 ; lineOffsets . Clear ( ) ; var text = leafBlock . Lines . ToSlice ( lineOffsets ) ; leafBlock . Lines . Release ( ) ; int previousStart = - 1 ; while ( ! text . IsEmpty ) { if ( previousStart == text . Start ) { ThrowHelper . InvalidOperationException ( $" The parser is in an invalid infinite loop while trying to parse inlines for block [ { leafBlock . GetType ( ) . Name } ] at position ( { leafBlock . ToPositionText ( ) } " ) ; } previousStart = text . Start ; var c = text . CurrentChar ; var textSaved = text ; var parsers = Parsers . GetParsersForOpeningCharacter ( c ) ; if ( parsers != null ) { for ( int i = 0 ; i < parsers . Length ; i ++ ) { text = textSaved ; if ( parsers [ i ] . Match ( this , ref text ) ) { goto done ; } } } parsers = Parsers . GlobalParsers ; if ( parsers != null ) { for ( int i = 0 ; i < parsers . Length ; i ++ ) { text = textSaved ; if ( parsers [ i ] . Match ( this , ref text ) ) { goto done ; } } } text = textSaved ; LiteralInlineParser . Match ( this , ref text ) ; done : var nextInline = Inline ; if ( nextInline != null ) { if ( nextInline . Parent is null ) { var container = FindLastContainer ( ) ; if ( ! ReferenceEquals ( container , nextInline ) ) { container . AppendChild ( nextInline ) ; } if ( container == Root ) { if ( container . Span . IsEmpty ) { container . Span = nextInline . Span ; } container . Span . End = nextInline . Span . End ; } } } else { var container = FindLastContainer ( ) ; Inline = container . LastChild is LeafInline ? container . LastChild : container ; if ( Inline == Root ) { Inline = null ; } } } if ( TrackTrivia ) { if ( ! ( leafBlock is HeadingBlock ) ) { var newLine = leafBlock . NewLine ; leafBlock . Inline . AppendChild ( new LineBreakInline { NewLine = newLine } ) ; } } Inline = null ; PostProcessInlines ( 0 , Root , null , true ) ; }
Processes the inline of the specified .
Processes the inline of the specified .
// clear parser states // Security check so that the parser can't go into a crazy infinite loop if one extension is messing // Else match using the default literal inline parser // Get deepest container // Get deepest container //if (DebugLog != null) //{ //    DebugLog.WriteLine($"** Dump: char '{c}"); //    leafBlock.Inline.DumpTo(DebugLog); //} //if (DebugLog != null) //{ //    DebugLog.WriteLine("** Dump before Emphasis:"); //    leafBlock.Inline.DumpTo(DebugLog); //} // PostProcess all inlines //TransformDelimitersToLiterals(); //if (DebugLog != null) //{ //    DebugLog.WriteLine(); //    DebugLog.WriteLine("** Dump after Emphasis:"); //    leafBlock.Inline.DumpTo(DebugLog); //}
leafBlock
LeafBlock
The leaf block.
The leaf block .