当前位置: 首页>>代码示例>>C#>>正文


C# ParserContext.AddBlock方法代码示例

本文整理汇总了C#中ParserContext.AddBlock方法的典型用法代码示例。如果您正苦于以下问题:C# ParserContext.AddBlock方法的具体用法?C# ParserContext.AddBlock怎么用?C# ParserContext.AddBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParserContext的用法示例。


在下文中一共展示了ParserContext.AddBlock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessLine


//.........这里部分代码省略.........
            if (context.Tip != lastMatchedContainer && !subject.IsBlank &&
                context.Tip is Paragraph && context.Tip.Strings.Any())
            {
                // lazy paragraph continuation
                //context.Tip.LastLineIsBlank = false;
                context.Tip.AddLine(subject.Rest);
            }
            else
            {
                // not a lazy continuation

                // finalize any blocks not matched
                context.CloseUnmatchedBlocks();

                // Block quote lines are never blank as they start with >
                // and we don't count blanks in fenced code for purposes of tight/loose
                // lists or breaking out of lists.  We also don't set last_line_blank
                // on an empty list item.
                if (!subject.IsBlank || context.Container is BlockQuote || context.Container is FencedCode)
                {
                    context.Container.LastLineIsBlank = false;
                }
                else if (context.Container is ListItem)
                {
                    context.Container.LastLineIsBlank = context.Container.StartLine < context.LineNumber;
                }
                else
                {
                    context.Container.LastLineIsBlank = true;
                }

                var cont = context.Container;
                while (cont.Parent is Block)
                {
                    cont.Parent.LastLineIsBlank = false;
                    cont = cont.Parent;
                }

                if (context.Container is IndentedCode || context.Container is HtmlBlock)
                {
                    context.Tip.AddLine(subject.Rest);
                }
                else if (context.Container is FencedCode)
                {
                    var fencedCode = context.Container as FencedCode;
                    var saved = subject.Save();

                    // check for closing code fence:
                    var match = subject.Indent <= 3;
                    subject.AdvanceWhile(c => c == ' ');
                    match = match &&
                        subject.Char == fencedCode.Char &&
                        subject.AdvanceWhile(c => c == fencedCode.Char) >= fencedCode.Length;

                    subject.AdvanceWhile(c => c == ' ');

                    if (match && subject.EndOfString)
                    {
                        // don't add closing fence to context.Container; instead, close it:
                        context.Container.Close(context);
                    }
                    else
                    {
                        saved.Restore();
                        context.Tip.AddLine(subject.Rest);
                    }
                }
                else if (context.Container is ATXHeader || context.Container is SetExtHeader || context.Container is HorizontalRule)
                {
                    // nothing to do; we already added the contents.
                }
                else
                {
                    if (context.Container.AcceptsLines)
                    {
                        subject.AdvanceToFirstNonSpace();
                        context.Tip.AddLine(subject.Rest);
                    }
                    else if (subject.IsBlank)
                    {
                        // do nothing
                    }
                    else if (!(context.Container is HorizontalRule || context.Container is SetExtHeader))
                    {
                        // create paragraph context.Container for line
                        context.AddBlock(new Paragraph());
                        subject.AdvanceToFirstNonSpace();
                        context.Tip.AddLine(subject.Rest);
                    }
                    else
                    {
                        throw new Exception(
                            "Line " + context.LineNumber.ToString() +
                            " with context.Container type " + context.Container.GetType().Name +
                            " did not match any condition."
                        );
                    }
                }
            }
        }
开发者ID:MortenHoustonLudvigsen,项目名称:CommonMarkSharp,代码行数:101,代码来源:CommonMarkParser.cs


注:本文中的ParserContext.AddBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。