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


C# ParserContext.CloseUnmatchedBlocks方法代码示例

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


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

示例1: ProcessLine

        private void ProcessLine(ParserContext context)
        {
            var groups = new string[0];
            var subject = new Subject(context.Line);

            context.Container = context.Document;
            while (context.Container.LastChild != null && context.Container.LastChild.IsOpen)
            {
                context.Container = context.Container.LastChild;
                if (!context.Container.MatchNextLine(subject))
                {
                    context.Container = context.Container.Parent; // back up to last matching block
                    break;
                }
            }

            var lastMatchedContainer = context.Container;

            // This function is used to finalize and close any unmatched
            // blocks.  We aren't ready to do this now, because we might
            // have a lazy paragraph continuation, in which case we don't
            // want to close unmatched blocks.  So we store this closure for
            // use later, when we have more information.
            var oldtip = context.Tip;
            context.CloseUnmatchedBlocks = () =>
            {
                // finalize any blocks not matched
                while (oldtip != lastMatchedContainer)
                {
                    oldtip.Close(context);
                    oldtip = oldtip.Parent;
                }
                context.CloseUnmatchedBlocks = () => { };
            };

            // Check to see if we've hit 2nd blank line; if so break out of list:
            if (subject.IsBlank && context.Container.LastLineIsBlank)
            {
                BreakOutOfLists(context, context.Container, context.LineNumber);
            }

            // Unless last matched context.Container is a code block, try new context.Container starts,
            // adding children to the last matched context.Container:
            while (!context.Container.IsCode && !context.BlocksParsed)
            {
                var parsed = context.Parsers.IndentedCodeParser.Parse(context, subject);
                parsed = parsed || context.Parsers.LazyParagraphContinuationParser.Parse(context, subject);
                parsed = parsed || context.Parsers.BlockQuoteParser.Parse(context, subject);
                parsed = parsed || context.Parsers.ATXHeaderParser.Parse(context, subject);
                parsed = parsed || context.Parsers.FencedCodeParser.Parse(context, subject);
                parsed = parsed || context.Parsers.HtmlBlockParser.Parse(context, subject);
                parsed = parsed || context.Parsers.SetExtHeaderParser.Parse(context, subject);
                parsed = parsed || context.Parsers.HorizontalRuleParser.Parse(context, subject);
                parsed = parsed || context.Parsers.ListParser.Parse(context, subject);

                if (!parsed || context.Container.AcceptsLines)
                {
                    // if none were found or it's a line context.Container, it can't contain other containers
                    context.BlocksParsed = true;
                }
            }

            // What remains at the offset is a text line.  Add the text to the
            // appropriate context.Container.

            // First check for a lazy paragraph continuation:
            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)
                {
//.........这里部分代码省略.........
开发者ID:MortenHoustonLudvigsen,项目名称:CommonMarkSharp,代码行数:101,代码来源:CommonMarkParser.cs


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