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


C# MarkdownDeep.Block类代码示例

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


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

示例1: ProcessFencedCodeBlock

        bool ProcessFencedCodeBlock(Block b)
        {
            char delim = current;

            // Extract the fence
            Mark();
            while (current == delim)
                SkipForward(1);
            string strFence = Extract();

            // Must be at least 3 long
            if (strFence.Length < 3)
                return false;

            // Rest of line must be blank
            SkipLinespace();
            if (!eol)
            {
                // Look for a language specifier
                Mark();
                while (char.IsLetterOrDigit(current) || current == '-')
                {
                    SkipForward(1);
                }
                string codeblockLangauge = Extract();
                b.CodeLanguage = codeblockLangauge;
                //return false;

                SkipLinespace();
            }

            // Skip the eol and remember start of code
            SkipEol();
            int startCode = position;

            // Find the end fence
            if (!Find(strFence))
                return false;

            // Character before must be a eol char
            if (!IsLineEnd(CharAtOffset(-1)))
                return false;

            int endCode = position;

            // Skip the fence
            SkipForward(strFence.Length);

            // Whitespace allowed at end
            SkipLinespace();
            if (!eol)
                return false;

            // Create the code block
            b.blockType = BlockType.codeblock;
            b.children = new List<Block>();

            // Remove the trailing line end
            if (input[endCode - 1] == '\r' && input[endCode - 2] == '\n')
                endCode -= 2;
            else if (input[endCode - 1] == '\n' && input[endCode - 2] == '\r')
                endCode -= 2;
            else
                endCode--;

            // Create the child block with the entire content
            var child = CreateBlock();
            child.blockType = BlockType.indent;
            child.buf = input;
            child.contentStart = startCode;
            child.contentEnd = endCode;
            b.children.Add(child);

            return true;
        }
开发者ID:ahaadi,项目名称:markdown-scanner,代码行数:75,代码来源:BlockProcessor.cs

示例2: FreeBlock

 public void FreeBlock(Block b)
 {
     m_SpareBlocks.Push(b);
 }
开发者ID:SmallPlanetUnity,项目名称:PUMarkdown,代码行数:4,代码来源:MardownDeep.cs

示例3: FreeBlock

 internal void FreeBlock(Block b)
 {
     m_SpareBlocks.Push(b);
 }
开发者ID:Daegalus,项目名称:markdowndeep-wp7,代码行数:4,代码来源:MardownDeep.cs

示例4: ProcessMarkdownEnabledHtml

        internal bool ProcessMarkdownEnabledHtml(Block b, HtmlTag openingTag, MarkdownInHtmlMode mode)
        {
            // Current position is just after the opening tag

            // Scan until we find matching closing tag
            int inner_pos = position;
            int depth = 1;
            bool bHasUnsafeContent = false;
            while (!eof)
            {
                // Find next angle bracket
                if (!Find('<'))
                    break;

                // Is it a html tag?
                int tagpos = position;
                HtmlTag tag = HtmlTag.Parse(this);
                if (tag == null)
                {
                    // Nope, skip it
                    SkipForward(1);
                    continue;
                }

                // In markdown off mode, we need to check for unsafe tags
                if (m_markdown.SafeMode && mode == MarkdownInHtmlMode.Off && !bHasUnsafeContent)
                {
                    if (!tag.IsSafe())
                        bHasUnsafeContent = true;
                }

                // Ignore self closing tags
                if (tag.closed)
                    continue;

                // Same tag?
                if (tag.name == openingTag.name)
                {
                    if (tag.closing)
                    {
                        depth--;
                        if (depth == 0)
                        {
                            // End of tag?
                            SkipLinespace();
                            SkipEol();

                            b.blockType = BlockType.HtmlTag;
                            b.data = openingTag;
                            b.contentEnd = position;

                            switch (mode)
                            {
                                case MarkdownInHtmlMode.Span:
                                {
                                    Block span = this.CreateBlock();
                                    span.buf = input;
                                    span.blockType = BlockType.span;
                                    span.contentStart = inner_pos;
                                    span.contentLen = tagpos - inner_pos;

                                    b.children = new List<Block>();
                                    b.children.Add(span);
                                    break;
                                }

                                case MarkdownInHtmlMode.Block:
                                case MarkdownInHtmlMode.Deep:
                                {
                                    // Scan the internal content
                                    var bp = new BlockProcessor(m_markdown, mode == MarkdownInHtmlMode.Deep);
                                    b.children = bp.ScanLines(input, inner_pos, tagpos - inner_pos);
                                    break;
                                }

                                case MarkdownInHtmlMode.Off:
                                {
                                    if (bHasUnsafeContent)
                                    {
                                        b.blockType = BlockType.unsafe_html;
                                        b.contentEnd = position;
                                    }
                                    else
                                    {
                                        Block span = this.CreateBlock();
                                        span.buf = input;
                                        span.blockType = BlockType.html;
                                        span.contentStart = inner_pos;
                                        span.contentLen = tagpos - inner_pos;

                                        b.children = new List<Block>();
                                        b.children.Add(span);
                                    }
                                    break;
                                }
                            }

                            return true;
                        }
                    }
//.........这里部分代码省略.........
开发者ID:carbonrobot,项目名称:markdowndeep,代码行数:101,代码来源:BlockProcessor.cs

示例5: CollapseLines

        internal void CollapseLines(List<Block> blocks, List<Block> lines)
        {
            // Remove trailing blank lines
            while (lines.Count>0 && lines.Last().blockType == BlockType.Blank)
            {
                FreeBlock(lines.Pop());
            }

            // Quit if empty
            if (lines.Count == 0)
            {
                return;
            }

            // What sort of block?
            switch (lines[0].blockType)
            {
                case BlockType.p:
                {
                    // Collapse all lines into a single paragraph
                    var para = CreateBlock();
                    para.blockType = BlockType.p;
                    para.buf = lines[0].buf;
                    para.contentStart = lines[0].contentStart;
                    para.contentEnd = lines.Last().contentEnd;
                    blocks.Add(para);
                    FreeBlocks(lines);
                    break;
                }

                case BlockType.quote:
                {
                    // Create a new quote block
                    var quote = new Block(BlockType.quote);
                    quote.children = new BlockProcessor(m_markdown, m_bMarkdownInHtml, BlockType.quote).Process(RenderLines(lines));
                    FreeBlocks(lines);
                    blocks.Add(quote);
                    break;
                }

                case BlockType.ol_li:
                case BlockType.ul_li:
                    blocks.Add(BuildList(lines));
                    break;

                case BlockType.dd:
                    if (blocks.Count > 0)
                    {
                        var prev=blocks[blocks.Count-1];
                        switch (prev.blockType)
                        {
                            case BlockType.p:
                                prev.blockType = BlockType.dt;
                                break;

                            case BlockType.dd:
                                break;

                            default:
                                var wrapper = CreateBlock();
                                wrapper.blockType = BlockType.dt;
                                wrapper.children = new List<Block>();
                                wrapper.children.Add(prev);
                                blocks.Pop();
                                blocks.Add(wrapper);
                                break;
                        }

                    }
                    blocks.Add(BuildDefinition(lines));
                    break;

                case BlockType.footnote:
                    m_markdown.AddFootnote(BuildFootnote(lines));
                    break;

                case BlockType.indent:
                {
                    var codeblock = new Block(BlockType.codeblock);
                    /*
                    if (m_markdown.FormatCodeBlockAttributes != null)
                    {
                        // Does the line first line look like a syntax specifier
                        var firstline = lines[0].Content;
                        if (firstline.StartsWith("{{") && firstline.EndsWith("}}"))
                        {
                            codeblock.data = firstline.Substring(2, firstline.Length - 4);
                            lines.RemoveAt(0);
                        }
                    }
                     */
                    codeblock.children = new List<Block>();
                    codeblock.children.AddRange(lines);
                    blocks.Add(codeblock);
                    lines.Clear();
                    break;
                }
            }
        }
开发者ID:carbonrobot,项目名称:markdowndeep,代码行数:99,代码来源:BlockProcessor.cs

示例6: BuildList

        /*
         * Spacing
         *
         * 1-3 spaces - Promote to indented if more spaces than original item
         *
         */
        /*
         * BuildList - build a single <ol> or <ul> list
         */
        private Block BuildList(List<Block> lines)
        {
            // What sort of list are we dealing with
            BlockType listType = lines[0].blockType;
            System.Diagnostics.Debug.Assert(listType == BlockType.ul_li || listType == BlockType.ol_li);

            // Preprocess
            // 1. Collapse all plain lines (ie: handle hardwrapped lines)
            // 2. Promote any unindented lines that have more leading space
            //    than the original list item to indented, including leading
            //    special chars
            int leadingSpace = lines[0].leadingSpaces;
            for (int i = 1; i < lines.Count; i++)
            {
                // Join plain paragraphs
                if ((lines[i].blockType == BlockType.p) &&
                    (lines[i - 1].blockType == BlockType.p || lines[i - 1].blockType == BlockType.ul_li || lines[i - 1].blockType==BlockType.ol_li))
                {
                    lines[i - 1].contentEnd = lines[i].contentEnd;
                    FreeBlock(lines[i]);
                    lines.RemoveAt(i);
                    i--;
                    continue;
                }

                if (lines[i].blockType != BlockType.indent && lines[i].blockType != BlockType.Blank)
                {
                    int thisLeadingSpace = lines[i].leadingSpaces;
                    if (thisLeadingSpace > leadingSpace)
                    {
                        // Change line to indented, including original leading chars
                        // (eg: '* ', '>', '1.' etc...)
                        lines[i].blockType = BlockType.indent;
                        int saveend = lines[i].contentEnd;
                        lines[i].contentStart = lines[i].lineStart + thisLeadingSpace;
                        lines[i].contentEnd = saveend;
                    }
                }
            }

            // Create the wrapping list item
            var List = new Block(listType == BlockType.ul_li ? BlockType.ul : BlockType.ol);
            List.children = new List<Block>();

            // Process all lines in the range
            for (int i = 0; i < lines.Count; i++)
            {
                System.Diagnostics.Debug.Assert(lines[i].blockType == BlockType.ul_li || lines[i].blockType==BlockType.ol_li);

                // Find start of item, including leading blanks
                int start_of_li = i;
                while (start_of_li > 0 && lines[start_of_li - 1].blockType == BlockType.Blank)
                    start_of_li--;

                // Find end of the item, including trailing blanks
                int end_of_li = i;
                while (end_of_li < lines.Count - 1 && lines[end_of_li + 1].blockType != BlockType.ul_li && lines[end_of_li + 1].blockType != BlockType.ol_li)
                    end_of_li++;

                // Is this a simple or complex list item?
                if (start_of_li == end_of_li)
                {
                    // It's a simple, single line item item
                    System.Diagnostics.Debug.Assert(start_of_li == i);
                    List.children.Add(CreateBlock().CopyFrom(lines[i]));
                }
                else
                {
                    // Build a new string containing all child items
                    bool bAnyBlanks = false;
                    StringBuilder sb = m_markdown.GetStringBuilder();
                    for (int j = start_of_li; j <= end_of_li; j++)
                    {
                        var l = lines[j];
                        sb.Append(l.buf, l.contentStart, l.contentLen);
                        sb.Append('\n');

                        if (lines[j].blockType == BlockType.Blank)
                        {
                            bAnyBlanks = true;
                        }
                    }

                    // Create the item and process child blocks
                    var item = new Block(BlockType.li);
                    item.children = new BlockProcessor(m_markdown, m_bMarkdownInHtml, listType).Process(sb.ToString());

                    // If no blank lines, change all contained paragraphs to plain text
                    if (!bAnyBlanks)
                    {
                        foreach (var child in item.children)
//.........这里部分代码省略.........
开发者ID:carbonrobot,项目名称:markdowndeep,代码行数:101,代码来源:BlockProcessor.cs

示例7: ProcessFencedCodeBlock

        bool ProcessFencedCodeBlock(Block b)
        {
            // Extract the fence
            Mark();
            while (current == '~' || current == '`')
                SkipForward(1);
            string strFence = Extract();

            // Must be at least 3 long
            if (strFence.Length < 3)
                return false;

            // Skip a space if needed
            SkipLinespace();
            var lang = string.Empty;
            if (!eol)
            {
                // process language
                Mark();
                SkipToEol();
                lang = Extract();
            }

            // Skip the eol and remember start of code
            SkipEol();
            int startCode = position;

            // Find the end fence
            if (!Find(strFence))
                return false;

            // Character before must be a eol char
            if (!IsLineEnd(CharAtOffset(-1)))
                return false;

            int endCode = position;

            // Skip the fence
            SkipForward(strFence.Length);

            // Whitespace allowed at end
            SkipLinespace();
            if (!eol)
                return false;

            // Create the code block
            b.blockType = BlockType.codeblock;
            b.children = new List<Block>();
            b.codeBlockLang = lang;

            // Remove the trailing line end
            if (input[endCode - 1] == '\r' && input[endCode - 2] == '\n')
                endCode -= 2;
            else if (input[endCode - 1] == '\n' && input[endCode - 2] == '\r')
                endCode -= 2;
            else
                endCode--;

            // Create the child block with the entire content
            var child = CreateBlock();
            child.blockType = BlockType.indent;
            child.buf = input;
            child.contentStart = startCode;
            child.contentEnd = endCode;
            b.children.Add(child);

            return true;
        }
开发者ID:carbonrobot,项目名称:markdowndeep,代码行数:68,代码来源:BlockProcessor.cs

示例8: PreviewOfBlockContent

        protected string PreviewOfBlockContent(Block block)
        {
            if (block == null) return string.Empty;
            if (block.Content == null) return string.Empty;

            const int previewLength = 35;

            string contentPreview = block.Content.Length > previewLength ? block.Content.Substring(0, previewLength) : block.Content;
            contentPreview = contentPreview.Replace('\n', ' ').Replace('\r', ' ');
            return contentPreview;
        }
开发者ID:chaelim,项目名称:markdown-scanner,代码行数:11,代码来源:DocFile.cs

示例9: IsHeaderBlock

        private static bool IsHeaderBlock(Block block, int maxDepth = 2)
        {
            if (null == block)
            {
                return false;
            }

            var blockType = block.BlockType;
            if (maxDepth >= 1 && blockType == BlockType.h1)
                return true;
            if (maxDepth >= 2 && blockType == BlockType.h2)
                return true;
            if (maxDepth >= 3 && blockType == BlockType.h3)
                return true;
            if (maxDepth >= 4 && blockType == BlockType.h4)
                return true;
            if (maxDepth >= 5 && blockType == BlockType.h5)
                return true;
            if (maxDepth >= 6 && blockType == BlockType.h6)
                return true;

            return false;
        }
开发者ID:chaelim,项目名称:markdown-scanner,代码行数:23,代码来源:DocFile.cs

示例10: FindCodeBlocks

 /// <summary>
 /// Filters the blocks to just a collection of blocks that may be
 /// relevent for our purposes
 /// </summary>
 /// <returns>The code blocks.</returns>
 /// <param name="blocks">Blocks.</param>
 protected static List<Block> FindCodeBlocks(Block[] blocks)
 {
     var blockList = new List<Block>();
     foreach (var block in blocks)
     {
         switch (block.BlockType)
         {
             case BlockType.codeblock:
             case BlockType.html:
                 blockList.Add(block);
                 break;
             default:
                 break;
         }
     }
     return blockList;
 }
开发者ID:chaelim,项目名称:markdown-scanner,代码行数:23,代码来源:DocFile.cs

示例11: CreateHeaderFromBlock

 protected Config.DocumentHeader CreateHeaderFromBlock(Block block)
 {
     var header = new Config.DocumentHeader();
     switch (block.BlockType)
     {
         case BlockType.h1:
             header.Level = 1; break;
         case BlockType.h2:
             header.Level = 2; break;
         case BlockType.h3:
             header.Level = 3; break;
         case BlockType.h4:
             header.Level = 4; break;
         case BlockType.h5:
             header.Level = 5; break;
         case BlockType.h6:
             header.Level = 6; break;
         default:
             throw new InvalidOperationException("block wasn't a header!");
     }
     header.Title = block.Content;
     return header;
 }
开发者ID:chaelim,项目名称:markdown-scanner,代码行数:23,代码来源:DocFile.cs

示例12: ParseCodeBlock

        /// <summary>
        /// Convert an annotation and fenced code block in the documentation into something usable. Adds
        /// the detected object into one of the internal collections of resources, methods, or examples.
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="code"></param>
        public ItemDefinition ParseCodeBlock(Block metadata, Block code)
        {
            if (metadata.BlockType != BlockType.html)
                throw new ArgumentException("metadata block does not appear to be metadata");

            if (code.BlockType != BlockType.codeblock)
                throw new ArgumentException("code block does not appear to be code");

            var metadataJsonString = metadata.Content.Substring(4, metadata.Content.Length - 9);
            var annotation = CodeBlockAnnotation.FromJson(metadataJsonString);

            switch (annotation.BlockType)
            {
                case CodeBlockType.Resource:
                    {
                        var resource = new ResourceDefinition(annotation, code.Content, this, code.CodeLanguage);
                        this.resources.Add(resource);
                        return resource;
                    }
                case CodeBlockType.Request:
                    {
                        var method = MethodDefinition.FromRequest(code.Content, annotation, this);
                        if (string.IsNullOrEmpty(method.Identifier))
                            method.Identifier = string.Format("{0} #{1}", this.DisplayName, this.requests.Count);
                        this.requests.Add(method);
                        return method;
                    }

                case CodeBlockType.Response:
                    {
                        MethodDefinition pairedRequest = null;
                        if (!string.IsNullOrEmpty(annotation.MethodName))
                        {
                            // Look up paired request by name
                            pairedRequest = (from m in this.requests where m.Identifier == annotation.MethodName select m).FirstOrDefault();
                        }
                        else
                        {
                            pairedRequest = Enumerable.Last(this.requests);
                        }

                        if (null == pairedRequest)
                        {
                            throw new InvalidOperationException(string.Format("Unable to locate the corresponding request for response block: {0}. Requests must be defined before a response.", annotation.MethodName));
                        }

                        pairedRequest.AddExpectedResponse(code.Content, annotation);
                        return pairedRequest;
                    }
                case CodeBlockType.Example:
                    {
                        var example = new ExampleDefinition(annotation, code.Content, this, code.CodeLanguage);
                        this.examples.Add(example);
                        return example;
                    }
                case CodeBlockType.Ignored:
                    return null;
                case CodeBlockType.SimulatedResponse:
                    {
                        var method = Enumerable.Last(this.requests);
                        method.AddSimulatedResponse(code.Content, annotation);
                        return method;
                    }
                case CodeBlockType.TestParams:
                    {
                        var method = Enumerable.Last(this.requests);
                        method.AddTestParams(code.Content);
                        return method;
                    }
                default:
                    throw new NotSupportedException("Unsupported block type: " + annotation.BlockType);
            }
        }
开发者ID:chaelim,项目名称:markdown-scanner,代码行数:79,代码来源:DocFile.cs

示例13: ParsePageAnnotation

        private PageAnnotation ParsePageAnnotation(Block block)
        {
            var commentText = StripHtmlCommentTags(block.Content).Trim();

            if (!commentText.StartsWith("{"))
                return null;

            var response = JsonConvert.DeserializeObject<PageAnnotation>(commentText);
            if (null != response && null != response.Type && response.Type.Equals(PageAnnotationType, StringComparison.OrdinalIgnoreCase))
                return response;

            return null;
        }
开发者ID:rgregg,项目名称:markdown-scanner,代码行数:13,代码来源:DocFile.cs

示例14: ParseCodeBlock

        /// <summary>
        /// Convert an annotation and fenced code block in the documentation into something usable. Adds
        /// the detected object into one of the internal collections of resources, methods, or examples.
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="code"></param>
        public ItemDefinition ParseCodeBlock(Block metadata, Block code)
        {
            if (metadata.BlockType != BlockType.html)
                throw new ArgumentException("metadata block does not appear to be metadata");

            if (code.BlockType != BlockType.codeblock)
                throw new ArgumentException("code block does not appear to be code");

            var metadataJsonString = StripHtmlCommentTags(metadata.Content);
            CodeBlockAnnotation annotation = CodeBlockAnnotation.ParseMetadata(metadataJsonString, code);

            switch (annotation.BlockType)
            {
                case CodeBlockType.Resource:
                    {
                        ResourceDefinition resource;
                        if (code.CodeLanguage.Equals("json", StringComparison.OrdinalIgnoreCase))
                        {
                            resource = new JsonResourceDefinition(annotation, code.Content, this);
                        }
                        //else if (code.CodeLanguage.Equals("xml", StringComparison.OrdinalIgnoreCase))
                        //{
                        //
                        //}
                        else
                        {
                            throw new NotSupportedException("Unsupported resource definition language: " + code.CodeLanguage);
                        }

                        if (string.IsNullOrEmpty(resource.Name))
                        {
                            throw new InvalidDataException("Resource definition is missing a name");
                        }

                        this.resources.Add(resource);
                        return resource;
                    }
                case CodeBlockType.Request:
                    {
                        var method = MethodDefinition.FromRequest(code.Content, annotation, this);
                        if (string.IsNullOrEmpty(method.Identifier))
                            method.Identifier = string.Format("{0} #{1}", this.DisplayName, this.requests.Count);
                        this.requests.Add(method);
                        return method;
                    }

                case CodeBlockType.Response:
                    {
                        MethodDefinition pairedRequest = null;
                        if (!string.IsNullOrEmpty(annotation.MethodName))
                        {
                            // Look up paired request by name
                            pairedRequest = (from m in this.requests where m.Identifier == annotation.MethodName select m).FirstOrDefault();
                        }
                        else if (this.requests.Any())
                        {
                            pairedRequest = Enumerable.Last(this.requests);
                        }

                        if (null == pairedRequest)
                        {
                            throw new InvalidOperationException(string.Format("Unable to locate the corresponding request for response block: {0}. Requests must be defined before a response.", annotation.MethodName));
                        }

                        pairedRequest.AddExpectedResponse(code.Content, annotation);
                        return pairedRequest;
                    }
                case CodeBlockType.Example:
                    {
                        var example = new ExampleDefinition(annotation, code.Content, this, code.CodeLanguage);
                        this.examples.Add(example);
                        return example;
                    }
                case CodeBlockType.Ignored:
                    return null;
                case CodeBlockType.SimulatedResponse:
                    {
                        var method = Enumerable.Last(this.requests);
                        method.AddSimulatedResponse(code.Content, annotation);
                        return method;
                    }
                case CodeBlockType.TestParams:
                    {
                        var method = Enumerable.Last(this.requests);
                        method.AddTestParams(code.Content);
                        return method;
                    }
                default:
                    {
                        var errorMessage = string.Format("Unable to parse metadata block or unsupported block type. Line {1}. Content: {0}", metadata.Content, metadata.LineStart);
                        throw new NotSupportedException(errorMessage);
                    }
            }
        }
开发者ID:rgregg,项目名称:markdown-scanner,代码行数:100,代码来源:DocFile.cs

示例15: FreeBlock

 public void FreeBlock(Block b)
 {
     m_markdown.FreeBlock(b);
 }
开发者ID:SmallPlanetUnity,项目名称:PUMarkdown,代码行数:4,代码来源:BlockProcessor.cs


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