Ejemplo n.º 1
0
        /// <summary>
        /// Create tree item or several tree items in parent-child relation based on levels count.
        /// There might be situations where document is invalid and header2 is followed by header4
        /// then to keep tree structure we need to create fake header3 in the middle.
        /// </summary>
        /// <param name="currentHeader">current header</param>
        /// <param name="levels">int representation of how many levels there is
        /// between curent header and last one added</param>
        /// <param name="headingBlock">data source for tree item</param>
        /// <param name="lastItemAdded">item added previously to tree</param>
        /// <returns>tree structure item for heading block</returns>
        private HeaderData CreateTreeItem(HeaderData currentHeader, int levels, HeadingBlock headingBlock, out HeaderData lastItemAdded)
        {
            var result = new List <HeaderData>();

            for (var i = 0; i < levels; i++)
            {
                result.Add(new HeaderData {
                    Level = currentHeader.Level + 1 + i
                });
                if (i == levels - 1)
                {
                    result[i].Text  = headingBlock.Inline.FirstChild.ToString();
                    result[i].Level = headingBlock.Level;
                    result[i].Id    = headingBlock.GetAttributes().Id;
                }
                if (i > 0)
                {
                    result[i - 1].Children = new List <HeaderData> {
                        result[i]
                    };
                    result[i].Parent = result[i - 1];
                }
                else
                {
                    result[i].Parent = currentHeader;
                }
            }
            lastItemAdded = result.Last();
            return(result[0]);
        }
            protected override void Write(HtmlRenderer renderer, HeadingBlock heading)
            {
                // Clone the heading block, and increment the level
                var hackHeading = new HeadingBlock(heading.Parser)
                {
                    Level = heading.Level + 1,

                    Column                    = heading.Column,
                    HeaderChar                = heading.HeaderChar,
                    Inline                    = heading.Inline,
                    IsBreakable               = heading.IsBreakable,
                    IsOpen                    = heading.IsOpen,
                    Line                      = heading.Line,
                    Lines                     = heading.Lines,
                    ProcessInlines            = heading.ProcessInlines,
                    RemoveAfterProcessInlines = heading.RemoveAfterProcessInlines,
                    Span                      = heading.Span,
                };

                hackHeading.SetAttributes(heading.GetAttributes());
                base.Write(renderer, hackHeading);
            }