示例#1
0
		/// <summary>
		/// Replaces all {TOC} tokens with the HTML for the table of contents. This method also inserts
		/// anchored name tags before each H1,H2,H3 etc. tag that the contents references.
		/// </summary>
		public string InsertToc(string html)
		{
			if (!html.Contains("{TOC}"))
				return html;

			_tree = new Tree(_template);

			// Parse the HTML for H tags
			HtmlDocument document = new HtmlDocument();
			document.LoadHtml(html);
			HtmlNodeCollection elements = document.DocumentNode.ChildNodes;
			ParseHTagsAndAddAnchors(document.DocumentNode);

			string outputHtml = GenerateHtml();
			string innerHtml = document.DocumentNode.InnerHtml;

			// make sure {{TOC}} or {{{{TOC}}}} aren't matched
			innerHtml = _regex.Replace(innerHtml, outputHtml);
			return document.DocumentNode.InnerHtml = innerHtml;
		}