• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Syntax.Block类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CommonMark.Syntax.Block的典型用法代码示例。如果您正苦于以下问题:C# Block类的具体用法?C# Block怎么用?C# Block使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Block类属于CommonMark.Syntax命名空间,在下文中一共展示了Block类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: PositionSafeForSmartLink

        public static bool PositionSafeForSmartLink(Block ast, int start, int length)
        {
            if (ast == null) return true;
            var end = start + length;
            var blockTags = new[] {BlockTag.FencedCode, BlockTag.HtmlBlock, BlockTag.IndentedCode, BlockTag.ReferenceDefinition};
            var inlineTags = new[] {InlineTag.Code, InlineTag.Link, InlineTag.RawHtml, InlineTag.Image};
            var lastBlockTag = BlockTag.Document;

            foreach (var block in EnumerateBlocks(ast.FirstChild))
            {
                if (block.SourcePosition + block.SourceLength < start)
                {
                    lastBlockTag = block.Tag;
                    continue;
                }

                if (block.SourcePosition >= end) return !blockTags.Any(tag => tag == lastBlockTag);
                if (blockTags.Any(tag => tag == block.Tag)) return false;

                return !EnumerateInlines(block.InlineContent)
                    .TakeWhile(il => il.SourcePosition < end)
                    .Where(il => il.SourcePosition + il.SourceLength > start)
                    .Any(il => inlineTags.Any(tag => tag == il.Tag));
            }
            return true;
        }
开发者ID:jhorv,项目名称:Markdown-Edit,代码行数:26,代码来源:AbstractSyntaxTree.cs


示例2: WriteAsync

 public async Task WriteAsync(Block block)
 {
     await WriteStartElementAsync("para");
     await WriteStartElementAsync("command");
     await WriteChildInlinesAsync(block);
     await WriteEndElementAsync(); //command
     await WriteEndElementAsync(); //para
 }
开发者ID:AMDL,项目名称:amdl2maml,代码行数:8,代码来源:CommandWriter.cs


示例3: TopicParserResult

 /// <summary>
 /// Initializes a new instance of the <see cref="TopicParserResult"/> class.
 /// </summary>
 /// <param name="doc">Document block.</param>
 internal TopicParserResult(Block doc)
 {
     if (doc == null)
         throw new ArgumentNullException("doc");
     if (doc.Tag != BlockTag.Document)
         throw new InvalidOperationException("Unexpected block tag: " + doc.Tag);
     Document = doc;
 }
开发者ID:AMDL,项目名称:amdl2maml,代码行数:12,代码来源:TopicParserResult.cs


示例4: GetTitle

 private static string GetTitle(TopicData topic, Block block)
 {
     if (block == null || block.HeaderLevel != 1)
         return topic.Name;
     var title = string.Empty;
     for (var inline = block.InlineContent; inline != null; inline = inline.NextSibling)
         title += inline.LiteralContent;
     return title;
 }
开发者ID:AMDL,项目名称:amdl2maml,代码行数:9,代码来源:TopicUpdater.cs


示例5: CreateDocument

        /// <summary>
        /// Creates a new top-level document block.
        /// </summary>
        internal static Block CreateDocument()
        {
#pragma warning disable 0618
            Block e = new Block(BlockTag.Document, 1, 1, 0);
#pragma warning restore 0618
            e.ReferenceMap = new Dictionary<string, Reference>();
            e.Top = e;
            return e;
        }
开发者ID:CodeCharm,项目名称:CommonMark.NET,代码行数:12,代码来源:Block.cs


示例6: DoWriteStartSectionAsync

 internal override async Task<SectionState> DoWriteStartSectionAsync(Block block, string title)
 {
     await WriteStartElementAsync("glossaryEntry");
     await WriteStartElementAsync("terms");
     foreach (var term in title.Split(','))
         await WriteTermAsync(term);
     await WriteEndElementAsync(); //terms
     await WriteStartElementAsync("definition");
     return SectionState.Content;
 }
开发者ID:AMDL,项目名称:amdl2maml,代码行数:10,代码来源:GlossaryTopicWriter.cs


示例7: PrintPosition

 private static void PrintPosition(bool enabled, TextWriter writer, Block block)
 {
     if (enabled)
     {
         writer.Write(" [");
         writer.Write(block.SourcePosition);
         writer.Write('-');
         writer.Write(block.SourceLastPosition);
         writer.Write(']');
     }
 }
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:11,代码来源:Printer.cs


示例8: WriteChainedInlineHeader

        public void WriteChainedInlineHeader()
        {
            // Process
            Block block = new Block(BlockTag.AtxHeader, 0);
            block.InlineContent = new Inline("Title");
            block.InlineContent.NextSibling = new Inline(" in many");
            block.InlineContent.NextSibling.NextSibling = new Inline(" siblings");
            string output = this.Process(block);

            // Assert
            Assert.AreEqual(string.Format(@"<!--UT [Title in many siblings](page-title-in-many-siblings)-->{0}<h0>Title in many siblings</h0>{0}", Environment.NewLine), output);
        }
开发者ID:chnfow,项目名称:Projbook,代码行数:12,代码来源:InjectAnchorHtmlFormatterTests.cs


示例9: EnumerateBlocks

 public static IEnumerable<Block> EnumerateBlocks(Block block)
 {
     if (block == null) yield break;
     var stack = new Stack<Block>();
     stack.Push(block);
     while (stack.Any())
     {
         var next = stack.Pop();
         yield return next;
         if (next.NextSibling != null) stack.Push(next.NextSibling);
         if (next.FirstChild != null) stack.Push(next.FirstChild);
     }
 }
开发者ID:jhorv,项目名称:Markdown-Edit,代码行数:13,代码来源:AbstractSyntaxTree.cs


示例10: WriteListItemAsync

        internal override async Task WriteListItemAsync(Block block)
        {
            if (GetSectionState() != SectionState.Sections)
            {
                await base.WriteListItemAsync(block);
                return;
            }

            await WriteStartElementAsync("step");
            await WriteStartElementAsync("content");
            await WriteChildBlocksAsync(block);
            await WriteEndElementAsync(); //content
            await WriteEndElementAsync(); //step
        }
开发者ID:AMDL,项目名称:amdl2maml,代码行数:14,代码来源:HowToTopicWriter.cs


示例11: EndsWithBlankLine

        /// <summary>
        /// Check to see if a block ends with a blank line, descending if needed into lists and sublists.
        /// </summary>
        private static bool EndsWithBlankLine(Block block)
        {
            while (true)
            {
                if (block.IsLastLineBlank)
                    return true;

                if (block.Tag != BlockTag.List && block.Tag != BlockTag.ListItem)
                    return false;

                block = block.LastChild;

                if (block == null)
                    return false;
            }
        }
开发者ID:aggieben,项目名称:CommonMark.NET,代码行数:19,代码来源:BlockMethods.cs


示例12: WriteChainedInlineHeader

        public void WriteChainedInlineHeader()
        {
            // Process
            Block block = new Block(BlockTag.AtxHeader, 0);
            block.InlineContent = new Inline("Title");
            block.InlineContent.NextSibling = new Inline(" in many");
            block.InlineContent.NextSibling.NextSibling = new Inline(" siblings");
            string output = this.Process(block);

            // Assert
            Assert.IsTrue(output.StartsWith(@"<a name=""page-title+in+many+siblings"">"));
            Assert.AreEqual(1, this.Formatter.Anchors.Length);
            Assert.AreEqual("page-title+in+many+siblings", this.Formatter.Anchors[0].Value);
            Assert.AreEqual("Title in many siblings", this.Formatter.Anchors[0].Label);
            Assert.AreEqual(0, this.Formatter.Anchors[0].Level);
        }
开发者ID:GregMialon,项目名称:Projbook,代码行数:16,代码来源:InjectAnchorHtmlFormatterTests.cs


示例13: WriteListAsync

        internal override async Task WriteListAsync(Block block)
        {
            if (SectionLevel < 2)
            {
                await base.WriteListAsync(block);
                return;
            }

            await WriteEndIntroductionAsync();

            //TODO procedure?
            await WriteStartElementAsync("steps");
            await WriteListClassAsync(block, ListClass.Bullet);
            SetSectionState(SectionState.Sections);
            await WriteChildBlocksAsync(block);
            await WriteEndElementAsync(); //steps
        }
开发者ID:AMDL,项目名称:amdl2maml,代码行数:17,代码来源:HowToTopicWriter.cs


示例14: WriteBlock

        /// <summary>
        /// Specializes block writing for anchor injection.
        /// For each formatted header we generate an anchor based on the context name, the header content and eventually add an integer suffix in order to prevent conflicts.
        /// </summary>
        /// <param name="block">The block to process.</param>
        /// <param name="isOpening">Define whether the block is opening.</param>
        /// <param name="isClosing">Defines whether the block is closing.</param>
        /// <param name="ignoreChildNodes">return whether the processing ignored child nodes.</param>
        protected override void WriteBlock(Block block, bool isOpening, bool isClosing, out bool ignoreChildNodes)
        {
            // Filter opening header
            if (isOpening && null != block && block.Tag == BlockTag.AtxHeader)
            {
                // Retrieve header content
                string headerContent;
                if (null != block.InlineContent && null != block.InlineContent.LiteralContent)
                {
                    // Read the whole content
                    Inline inline = block.InlineContent;
                    StringBuilder stringBuilder = new StringBuilder();
                    do
                    {
                        stringBuilder.Append(inline.LiteralContent);
                        inline = inline.NextSibling;
                    } while (null != inline);
                    headerContent = stringBuilder.ToString();
                }
                else
                {
                    headerContent = "unknown";
                }

                // Compute the anchor value
                string sectionId = HttpUtility.UrlEncode(headerContent.ToLower());
                sectionId = string.Format("{0}-{1}", this.ContextName, sectionId)
                    .Replace('+', '-');

                // Detect anchor conflict
                if (sectionConflict.ContainsKey(sectionId))
                {
                    // Append the index
                    sectionId = string.Format("{0}-{1}", sectionId, ++sectionConflict[sectionId]);
                }

                // Write anchor
                this.Write(string.Format(@"<!--{0} [{1}]({2})-->", this.PageSplittingIdentifier, headerContent, sectionId));
                sectionConflict[sectionId] = 1;
            }

            // Trigger parent rendering for the default html rendering
            base.WriteBlock(block, isOpening, isClosing, out ignoreChildNodes);
        }
开发者ID:chnfow,项目名称:Projbook,代码行数:52,代码来源:InjectAnchorHtmlFormatter.cs


示例15: WriteDocument

        /// <summary>
        /// Writes the given CommonMark document to the output stream as HTML.
        /// </summary>
        public void WriteDocument(Block document)
        {
            if (document == null)
                throw new ArgumentNullException(nameof(document));

            bool ignoreChildNodes;
            Block ignoreUntilBlockCloses = null;
            Inline ignoreUntilInlineCloses = null;

            foreach (var node in document.AsEnumerable())
            {
                if (node.Block != null)
                {
                    if (ignoreUntilBlockCloses != null)
                    {
                        if (ignoreUntilBlockCloses != node.Block)
                            continue;

                        ignoreUntilBlockCloses = null;
                    }

                    WriteBlock(node.Block, node.IsOpening, node.IsClosing, out ignoreChildNodes);
                    if (ignoreChildNodes && !node.IsClosing)
                        ignoreUntilBlockCloses = node.Block;
                }
                else if (ignoreUntilBlockCloses == null && node.Inline != null)
                {
                    if (ignoreUntilInlineCloses != null)
                    {
                        if (ignoreUntilInlineCloses != node.Inline)
                            continue;

                        ignoreUntilInlineCloses = null;
                    }

                    WriteInline(node.Inline, node.IsOpening, node.IsClosing, out ignoreChildNodes);
                    if (ignoreChildNodes && !node.IsClosing)
                        ignoreUntilInlineCloses = node.Inline;
                }
            }
        }
开发者ID:Knagis,项目名称:CommonMark.NET,代码行数:44,代码来源:HtmlFormatter.cs


示例16: BreakOutOfLists

        /// <summary>
        /// Break out of all containing lists
        /// </summary>
        private static void BreakOutOfLists(ref Block blockRef, LineInfo line)
        {
            Block container = blockRef;
            Block b = container.Top;

            // find first containing list:
            while (b != null && b.Tag != BlockTag.List)
                b = b.LastChild;

            if (b != null)
            {
                while (container != null && container != b)
                {
                    Finalize(container, line);
                    container = container.Parent;
                }

                Finalize(b, line);
                blockRef = b.Parent;
            }
        }
开发者ID:aggieben,项目名称:CommonMark.NET,代码行数:24,代码来源:BlockMethods.cs


示例17: AddLine

        private static void AddLine(Block block, LineInfo lineInfo, string ln, int offset, int length = -1)
        {
            if (!block.IsOpen)
                throw new CommonMarkException(string.Format(CultureInfo.InvariantCulture, "Attempted to add line '{0}' to closed container ({1}).", ln, block.Tag));

            var len = length == -1 ? ln.Length - offset : length;
            if (len <= 0)
                return;

            var curSC = block.StringContent;
            if (curSC == null)
            {
                block.StringContent = curSC = new StringContent();
                if (lineInfo.IsTrackingPositions)
                    curSC.PositionTracker = new PositionTracker(lineInfo.LineOffset);
            }

            if (lineInfo.IsTrackingPositions)
                curSC.PositionTracker.AddOffset(lineInfo, offset, len);

            curSC.Append(ln, offset, len);
        }
开发者ID:aggieben,项目名称:CommonMark.NET,代码行数:22,代码来源:BlockMethods.cs


示例18: WriteStartIntroductionAsync

 internal override async Task WriteStartIntroductionAsync(Block block)
 {
     await WriteStartElementAsync("glossary");
 }
开发者ID:AMDL,项目名称:amdl2maml,代码行数:4,代码来源:GlossaryTopicWriter.cs


示例19: ProcessInlines

        /// <summary>
        /// Walk through the block, its children and siblings, parsing string content into inline content where appropriate.
        /// </summary>
        /// <param name="block">The document level block from which to start the processing.</param>
        /// <param name="refmap">The reference mapping used when parsing links.</param>
        /// <param name="settings">The settings that influence how the inline parsing is performed.</param>
        public static void ProcessInlines(Block block, Dictionary<string, Reference> refmap, CommonMarkSettings settings)
        {
            Stack<Inline> inlineStack = null;
            var stack = new Stack<Block>();
            var parsers = settings.InlineParsers;
            var specialCharacters = settings.InlineParserSpecialCharacters;
            var subj = new Subject(refmap);

            StringContent sc;
            int delta;

            while (block != null)
            {
                var tag = block.Tag;
                if (tag == BlockTag.Paragraph || tag == BlockTag.AtxHeader || tag == BlockTag.SETextHeader)
                {
                    sc = block.StringContent;
                    if (sc != null)
                    {
                        sc.FillSubject(subj);
                        delta = subj.Position;

                        block.InlineContent = InlineMethods.parse_inlines(subj, refmap, parsers, specialCharacters);
                        block.StringContent = null;

                        if (sc.PositionTracker != null)
                        {
                            sc.PositionTracker.AddBlockOffset(-delta);
                            AdjustInlineSourcePosition(block.InlineContent, sc.PositionTracker, ref inlineStack);
                        }
                    }
                }

                if (block.FirstChild != null)
                {
                    if (block.NextSibling != null)
                        stack.Push(block.NextSibling);

                    block = block.FirstChild;
                }
                else if (block.NextSibling != null)
                {
                    block = block.NextSibling;
                }
                else if (stack.Count > 0)
                {
                    block = stack.Pop();
                }
                else
                {
                    block = null;
                }
            }
        }
开发者ID:aggieben,项目名称:CommonMark.NET,代码行数:60,代码来源:BlockMethods.cs


示例20: EnumerateSpanningBlocks

 public static IEnumerable<Block> EnumerateSpanningBlocks(Block ast, int startOffset, int endOffset)
 {
     return EnumerateBlocks(ast.FirstChild)
         .Where(b => (b.SourcePosition + b.SourceLength) > startOffset)
         .TakeWhile(b => b.SourcePosition < endOffset);
 }
开发者ID:jhorv,项目名称:Markdown-Edit,代码行数:6,代码来源:AbstractSyntaxTree.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CommonSuite.SymbolCollection类代码示例发布时间:2022-05-24
下一篇:
C# Parser.Subject类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap