Example #1
0
        // Split the markdown into sections, one section for each
        // top level heading
        public static List <string> SplitSections(string markdown)
        {
            // Build blocks
            var md = new global::Xilium.MarkdownDeep.Markdown();

            // Process blocks
            var blocks = md.ProcessBlocks(markdown);

            // Create sections
            var Sections           = new List <string>();
            int iPrevSectionOffset = 0;

            for (int i = 0; i < blocks.Count; i++)
            {
                var b = blocks[i];
                if (md.IsSectionHeader(b))
                {
                    // Get the offset of the section
                    int iSectionOffset = b.lineStart;

                    // Add section
                    Sections.Add(markdown.Substring(iPrevSectionOffset, iSectionOffset - iPrevSectionOffset));

                    iPrevSectionOffset = iSectionOffset;
                }
            }

            // Add the last section
            if (markdown.Length > iPrevSectionOffset)
            {
                Sections.Add(markdown.Substring(iPrevSectionOffset));
            }

            return(Sections);
        }
Example #2
0
        // Split the markdown into sections, one section for each
        // top level heading
        public static List <string> SplitUserSections(string markdown)
        {
            // Build blocks
            var md = new global::Xilium.MarkdownDeep.Markdown();

            md.UserBreaks = true;

            // Process blocks
            var blocks = md.ProcessBlocks(markdown);

            // Create sections
            var Sections           = new List <string>();
            int iPrevSectionOffset = 0;

            for (int i = 0; i < blocks.Count; i++)
            {
                var b = blocks[i];
                if (b.blockType == BlockType.user_break)
                {
                    // Get the offset of the section
                    int iSectionOffset = b.lineStart;

                    // Add section
                    Sections.Add(markdown.Substring(iPrevSectionOffset, iSectionOffset - iPrevSectionOffset).Trim());

                    // Next section starts on next line
                    if (i + 1 < blocks.Count)
                    {
                        iPrevSectionOffset = blocks[i + 1].lineStart;
                        if (iPrevSectionOffset == 0)
                        {
                            iPrevSectionOffset = blocks[i + 1].contentStart;
                        }
                    }
                    else
                    {
                        iPrevSectionOffset = markdown.Length;
                    }
                }
            }

            // Add the last section
            if (markdown.Length > iPrevSectionOffset)
            {
                Sections.Add(markdown.Substring(iPrevSectionOffset).Trim());
            }

            return(Sections);
        }
Example #3
0
        // Split the markdown into sections, one section for each
        // top level heading
        public static List<string> SplitUserSections(string markdown)
        {
            // Build blocks
            var md = new global::Xilium.MarkdownDeep.Markdown();
            md.UserBreaks = true;

            // Process blocks
            var blocks = md.ProcessBlocks(markdown);

            // Create sections
            var Sections = new List<string>();
            int iPrevSectionOffset = 0;
            for (int i = 0; i < blocks.Count; i++)
            {
                var b = blocks[i];
                if (b.blockType==BlockType.user_break)
                {
                    // Get the offset of the section
                    int iSectionOffset = b.lineStart;

                    // Add section
                    Sections.Add(markdown.Substring(iPrevSectionOffset, iSectionOffset - iPrevSectionOffset).Trim());

                    // Next section starts on next line
                    if (i + 1 < blocks.Count)
                    {
                        iPrevSectionOffset = blocks[i + 1].lineStart;
                        if (iPrevSectionOffset==0)
                            iPrevSectionOffset = blocks[i + 1].contentStart;
                    }
                    else
                        iPrevSectionOffset = markdown.Length;
                }
            }

            // Add the last section
            if (markdown.Length > iPrevSectionOffset)
            {
                Sections.Add(markdown.Substring(iPrevSectionOffset).Trim());
            }

            return Sections;
        }
Example #4
0
        // Split the markdown into sections, one section for each
        // top level heading
        public static List<string> SplitSections(string markdown)
        {
            // Build blocks
            var md = new global::Xilium.MarkdownDeep.Markdown();

            // Process blocks
            var blocks = md.ProcessBlocks(markdown);

            // Create sections
            var Sections = new List<string>();
            int iPrevSectionOffset = 0;
            for (int i = 0; i < blocks.Count; i++)
            {
                var b = blocks[i];
                if (md.IsSectionHeader(b))
                {
                    // Get the offset of the section
                    int iSectionOffset = b.lineStart;

                    // Add section
                    Sections.Add(markdown.Substring(iPrevSectionOffset, iSectionOffset - iPrevSectionOffset));

                    iPrevSectionOffset = iSectionOffset;
                }
            }

            // Add the last section
            if (markdown.Length > iPrevSectionOffset)
            {
                Sections.Add(markdown.Substring(iPrevSectionOffset));
            }

            return Sections;
        }