예제 #1
0
		public override string AfterParse(string html)
		{
			TocParser parser = new TocParser();
			html = parser.InsertToc(html);

			return html;
		}
예제 #2
0
        public override string AfterParse(string html)
        {
            TocParser parser = new TocParser();

            html = parser.InsertToc(html);

            return(html);
        }
예제 #3
0
		public void should_have_correct_tree_structure_from_basic_html()
		{
			// Arrange
			TocParser tocParser = new TocParser();
			string html = GetHtml();

			// Act
			tocParser.InsertToc(html);

			// Assert
			Item root = tocParser.Tree.Root;
			Assert.That(root, Is.Not.Null);
			Assert.That(root.Level, Is.EqualTo(Tree.DEFAULT_LEVEL_ZERO_BASED));

			List<Item> allH2s = root.Children.ToList();
			Assert.That(allH2s.Count, Is.EqualTo(2));

			// <h2>First h2</h2>
			Item firstH2 = allH2s[0];
			Assert.That(firstH2.Children.Count(), Is.EqualTo(1));
			Item firstH3 = firstH2.GetChild(0);
			Assert.That(firstH3.Children.Count(), Is.EqualTo(0));

			// <h2>Second h2</h2>
			Item secondH2 = allH2s[1];
			Assert.That(secondH2.Children.Count(), Is.EqualTo(2));
			
			Item secondH3 = secondH2.GetChild(0);
			Assert.That(secondH3.Children.Count(), Is.EqualTo(0));
			
			Item thirdH3 = secondH2.GetChild(1);
			Assert.That(thirdH3.Children.Count(), Is.EqualTo(1));

			Item firstH4 = thirdH3.GetChild(0);
			Assert.That(firstH4.Children.Count(), Is.EqualTo(0));			
		}
예제 #4
0
		public void should_have_correct_titles()
		{
			// Arrange
			TocParser tocParser = new TocParser();
			string html = GetHtml();

			// Act
			tocParser.InsertToc(html);

			// Assert
			Item root = tocParser.Tree.Root;
			List<Item> allH2s = root.Children.ToList();

			Item firstH2 = allH2s[0];
			Item firstH3 = firstH2.GetChild(0);
			Item secondH2 = allH2s[1];
			Item thirdH3 = secondH2.GetChild(1);
			Item firstH4 = thirdH3.GetChild(0);

			Assert.That(firstH2.Title, Is.EqualTo("First h2"));
			Assert.That(firstH3.Title, Is.EqualTo("First h3"));
			Assert.That(secondH2.Title, Is.EqualTo("Second h2"));
			Assert.That(thirdH3.Title, Is.EqualTo("Third h3"));
			Assert.That(firstH4.Title, Is.EqualTo("Lonely h4"));
		}
예제 #5
0
		public void should_have_correct_html_nesting_and_warning_titles_when_missing_levels()
		{
			// From issue #177
			// Arrange
			TocParser tocParser = new TocParser();
			string html = "{TOC} <p>some text</p>";
			html += "<h1>h1</h1>"; // deliberately removed
			//html += "	<h2>h2</h2>"; // deliberately removed
			html += "		<h3>h3a</h3>";
			html += "			<h4>h4a</h4>";
			html += "			<h4>h4b</h4>";
			html += "		<h3>h3b</h3>";
			html += "			<h4>h4c</h4>";
			html += "				<h5>h5a</h5>";
			html += "				<h5>h5b</h5>";
			html += "		<h3>h3c</h3>";
			html += "			<h4>h4d</h4>";
			html += "	<h2>h2b</h2>";
			//html += "		<h3>h3</h3>"; // deliberately removed
			//html += "			<h4>h4</h4>"; // deliberately removed
			html += "				<h5>h5c</h5>";

			// Act
			string actual = tocParser.InsertToc(html);

			// Assert
			Assert.That(actual, Is.StringContaining("(Missing level 2 header)"));
			Assert.That(actual, Is.StringContaining("(Missing level 3 header)"));
			Assert.That(actual, Is.StringContaining("(Missing level 4 header)"));


			Assert.That(actual, Is.StringContaining("1.3&nbsp;h3c"));
			Assert.That(actual, Is.StringContaining("1.3.1&nbsp;h4d"));
		}
예제 #6
0
		public void should_ignore_multiple_curlies()
		{
			// Arrange
			TocParser tocParser = new TocParser();
			string html = "Give me a {{TOC}} and a {{{{TOC}}}} - the should not render a TOC";
			string expected = html;

			// Act
			string actual = tocParser.InsertToc(html);

			// Assert
			Assert.That(actual, Is.EqualTo(expected));
		}
예제 #7
0
		public void should_have_correct_section_numbering_for_large_lists()
		{
			// Arrnage
			TocParser tocParser = new TocParser();
			string html = GetLotsOfHeaders();

			// Act
			string actual = tocParser.InsertToc(html);

			// Assert
			// (really basic asserts, as the alternative is to just copy the HTML)
			Assert.That(actual, Is.Not.StringContaining("1&nbsp;First h1"));
			Assert.That(actual, Is.StringContaining("1.&nbsp;First h2"));
			Assert.That(actual, Is.StringContaining("2.&nbsp;Second h2"));
			Assert.That(actual, Is.StringContaining("2.1&nbsp;h3 number #0"));
			Assert.That(actual, Is.StringContaining("2.47&nbsp;h3 number #46"));
			Assert.That(actual, Is.StringContaining("2.52&nbsp;Yet Another h3"));
			Assert.That(actual, Is.StringContaining("2.52.1&nbsp;Lonely h4"));
		}
예제 #8
0
		public void should_have_named_anchors_inserted_by_headers_in_html()
		{
			// Arrange
			TocParser tocParser = new TocParser();
			string html = GetHtml();

			// Act
			string actual = tocParser.InsertToc(html);

			// Assert
			StringAssert.IsMatch(@"<h2><a name=\"".*?""></a>First h2</h2>", actual);
		}