コード例 #1
0
        /// <summary>
        /// Takes an HTML string and inserts the Table of Contents into
        /// the Html
        /// </summary>
        /// <param name="html">The html to insert the Table of Contents into</param>
        /// <returns>An Html string containing the original html along with a table of contents</returns>
        internal string InsertTableOfContents(string html)
        {
            var position = GetTableOfContentsPosition(ref html);

            if (position == -1)
            {
                return(html);
            }

            var hierarchy = _tableOfContentsService.GetHeadingHierarchy(html);

            if (hierarchy == null || !hierarchy.Any())
            {
                return(html);
            }

            var tableOfContents = _tableOfContentsBuilder.BuildTableOfContents(hierarchy);

            if (String.IsNullOrEmpty(tableOfContents))
            {
                return(html);
            }

            var newHtml = new StringBuilder();

            newHtml.Append(html.Substring(0, position));
            newHtml.Append(tableOfContents);
            newHtml.Append(html.Substring(position));

            return(newHtml.ToString());
        }
コード例 #2
0
        public void Test_Heading_AnchorName_Persisted()
        {
            var hierarchy = _tableOfContentsService.GetHeadingHierarchy("<h4><a name=\"h4-anchor\"></a>Heading Contents</h4>");

            Assert.AreEqual(1, hierarchy.Count);

            Assert.AreEqual("h4-anchor", hierarchy.First().Item.AnchorName);
        }