Exemplo n.º 1
0
    def test_find_toc_by_id(self):
        """
        Test finding the relevant TOC item by the tag ID.
        """

        index = search.SearchIndex()

        md = dedent("""
        # Heading 1
        ## Heading 2
        ### Heading 3
        """)
        toc = markdown_to_toc(md)

        toc_item = index._find_toc_by_id(toc, "heading-1")
        self.assertEqual(toc_item.url, "#heading-1")
        self.assertEqual(toc_item.title, "Heading 1")

        toc_item2 = index._find_toc_by_id(toc, "heading-2")
        self.assertEqual(toc_item2.url, "#heading-2")
        self.assertEqual(toc_item2.title, "Heading 2")

        toc_item3 = index._find_toc_by_id(toc, "heading-3")
        self.assertEqual(toc_item3.url, "#heading-3")
        self.assertEqual(toc_item3.title, "Heading 3")
Exemplo n.º 2
0
    def test_find_toc_by_id(self):
        """
        Test finding the relevant TOC item by the tag ID.
        """

        index = search.SearchIndex()

        md = dedent(
            """
        # Heading 1
        ## Heading 2
        ### Heading 3
        """
        )
        toc = markdown_to_toc(md)

        toc_item = index._find_toc_by_id(toc, "heading-1")
        self.assertEqual(toc_item.url, "#heading-1")
        self.assertEqual(toc_item.title, "Heading 1")

        toc_item2 = index._find_toc_by_id(toc, "heading-2")
        self.assertEqual(toc_item2.url, "#heading-2")
        self.assertEqual(toc_item2.title, "Heading 2")

        toc_item3 = index._find_toc_by_id(toc, "heading-3")
        self.assertEqual(toc_item3.url, "#heading-3")
        self.assertEqual(toc_item3.title, "Heading 3")
Exemplo n.º 3
0
    def test_create_search_index(self):

        html_content = """
        <h1 id="heading-1">Heading 1</h1>
        <p>Content 1</p>
        <h2 id="heading-2">Heading 2</h1>
        <p>Content 2</p>
        <h3 id="heading-3">Heading 3</h1>
        <p>Content 3</p>
        """

        pages = [
            {'Home': 'index.md'},
            {'About': 'about.md'},
        ]

        site_navigation = nav.SiteNavigation(load_config(pages=pages))

        md = dedent("""
        # Heading 1
        ## Heading 2
        ### Heading 3
        """)
        toc = markdown_to_toc(md)

        full_content = ''.join("""Heading{0}Content{0}""".format(i) for i in range(1, 4))

        for page in site_navigation:
            # Fake page.read_source() and page.render()
            page.markdown = md
            page.toc = toc
            page.content = html_content

            index = search.SearchIndex()
            index.add_entry_from_context(page)

            self.assertEqual(len(index._entries), 4)

            loc = page.abs_url

            self.assertEqual(index._entries[0]['title'], page.title)
            self.assertEqual(strip_whitespace(index._entries[0]['text']), full_content)
            self.assertEqual(index._entries[0]['location'], loc)

            self.assertEqual(index._entries[1]['title'], "Heading 1")
            self.assertEqual(index._entries[1]['text'], "Content 1")
            self.assertEqual(index._entries[1]['location'], "{0}#heading-1".format(loc))

            self.assertEqual(index._entries[2]['title'], "Heading 2")
            self.assertEqual(strip_whitespace(index._entries[2]['text']), "Content2")
            self.assertEqual(index._entries[2]['location'], "{0}#heading-2".format(loc))

            self.assertEqual(index._entries[3]['title'], "Heading 3")
            self.assertEqual(strip_whitespace(index._entries[3]['text']), "Content3")
            self.assertEqual(index._entries[3]['location'], "{0}#heading-3".format(loc))
Exemplo n.º 4
0
 def test_flat_h2_toc(self):
     md = dedent("""
     ## Heading 1
     ## Heading 2
     ## Heading 3
     """)
     expected = dedent("""
     Heading 1 - #heading-1
     Heading 2 - #heading-2
     Heading 3 - #heading-3
     """)
     toc = markdown_to_toc(md)
     self.assertEqual(str(toc).strip(), expected)
Exemplo n.º 5
0
 def test_indented_toc_html(self):
     md = dedent("""
     # Heading 1
     ## <code>Heading</code> 2
     ## Heading 3
     """)
     expected = dedent("""
     Heading 1 - #heading-1
         Heading 2 - #heading-2
         Heading 3 - #heading-3
     """)
     toc = markdown_to_toc(md)
     self.assertEqual(str(toc).strip(), expected)
Exemplo n.º 6
0
 def test_indented_toc(self):
     md = dedent("""
     # Heading 1
     ## Heading 2
     ### Heading 3
     """)
     expected = dedent("""
     Heading 1 - #heading-1
         Heading 2 - #heading-2
             Heading 3 - #heading-3
     """)
     toc = markdown_to_toc(md)
     self.assertEqual(str(toc).strip(), expected)
Exemplo n.º 7
0
 def test_entityref(self):
     md = dedent("""
     # Heading & 1
     ## Heading > 2
     ### Heading < 3
     """)
     expected = dedent("""
     Heading &amp; 1 - #heading-1
         Heading &gt; 2 - #heading-2
             Heading &lt; 3 - #heading-3
     """)
     toc = markdown_to_toc(md)
     self.assertEqual(str(toc).strip(), expected)
Exemplo n.º 8
0
    def test_create_search_index(self):

        html_content = """
        <h1 id="heading-1">Heading 1</h1>
        <p>Content 1</p>
        <h2 id="heading-2">Heading 2</h1>
        <p>Content 2</p>
        <h3 id="heading-3">Heading 3</h1>
        <p>Content 3</p>
        """

        pages = [{"Home": "index.md"}, {"About": "about.md"}]
        site_navigation = nav.SiteNavigation(pages)

        md = dedent(
            """
        # Heading 1
        ## Heading 2
        ### Heading 3
        """
        )
        toc = markdown_to_toc(md)

        full_content = "".join("""Heading{0}Content{0}""".format(i) for i in range(1, 4))

        for page in site_navigation:

            index = search.SearchIndex()
            index.add_entry_from_context(page, html_content, toc)

            self.assertEqual(len(index._entries), 4)

            loc = page.abs_url

            self.assertEqual(index._entries[0]["title"], page.title)
            self.assertEqual(strip_whitespace(index._entries[0]["text"]), full_content)
            self.assertEqual(index._entries[0]["location"], loc)

            self.assertEqual(index._entries[1]["title"], "Heading 1")
            self.assertEqual(index._entries[1]["text"], "Content 1")
            self.assertEqual(index._entries[1]["location"], "{0}#heading-1".format(loc))

            self.assertEqual(index._entries[2]["title"], "Heading 2")
            self.assertEqual(strip_whitespace(index._entries[2]["text"]), "Content2")
            self.assertEqual(index._entries[2]["location"], "{0}#heading-2".format(loc))

            self.assertEqual(index._entries[3]["title"], "Heading 3")
            self.assertEqual(strip_whitespace(index._entries[3]["text"]), "Content3")
            self.assertEqual(index._entries[3]["location"], "{0}#heading-3".format(loc))
Exemplo n.º 9
0
 def test_mixed_html(self):
     md = dedent("""
     # Heading 1
     ## Heading 2
     # Heading 3
     ### Heading 4
     ### <a>Heading 5</a>
     """)
     expected = dedent("""
     Heading 1 - #heading-1
         Heading 2 - #heading-2
     Heading 3 - #heading-3
         Heading 4 - #heading-4
         Heading 5 - #heading-5
     """)
     toc = markdown_to_toc(md)
     self.assertEqual(str(toc).strip(), expected)
Exemplo n.º 10
0
    def test_create_search_index(self):

        html_content = """
        <h1 id="heading-1">Heading 1</h1>
        <p>Content 1</p>
        <h2 id="heading-2">Heading 2</h1>
        <p>Content 2</p>
        <h3 id="heading-3">Heading 3</h1>
        <p>Content 3</p>
        """

        pages = [
            {'Home': 'index.md'},
            {'About': 'about.md'},
        ]
        site_navigation = nav.SiteNavigation(pages)

        md = dedent("""
        # Heading 1
        ## Heading 2
        ### Heading 3
        """)
        toc = markdown_to_toc(md)

        full_content = ''.join("""Heading{0}Content{0}""".format(i) for i in range(1, 4))

        for page in site_navigation:

            index = search.SearchIndex()
            index.add_entry_from_context(page, html_content, toc)

            self.assertEqual(len(index._entries), 3)

            loc = page.abs_url

            self.assertEqual(index._entries[0]['title'], page.title)
            self.assertEqual(strip_whitespace(index._entries[0]['text']), full_content)
            self.assertEqual(index._entries[0]['location'], loc)

            self.assertEqual(index._entries[1]['title'], "Heading 1")
            self.assertEqual(index._entries[1]['text'], "Content 1")
            self.assertEqual(index._entries[1]['location'], "{0}#heading-1".format(loc))

            self.assertEqual(index._entries[2]['title'], "Heading 2")
            self.assertEqual(strip_whitespace(index._entries[2]['text']), "Content2Heading3Content3")
            self.assertEqual(index._entries[2]['location'], "{0}#heading-2".format(loc))
Exemplo n.º 11
0
 def test_mixed_html(self):
     md = dedent("""
     # Heading 1
     ## Heading 2
     # Heading 3
     ### Heading 4
     ### <a>Heading 5</a>
     """)
     expected = dedent("""
     Heading 1 - #heading-1
         Heading 2 - #heading-2
     Heading 3 - #heading-3
         Heading 4 - #heading-4
         Heading 5 - #heading-5
     """)
     toc = markdown_to_toc(md)
     self.assertEqual(str(toc).strip(), expected)
Exemplo n.º 12
0
 def test_entityref(self):
     md = dedent(
         """
     # Heading & 1
     ## Heading > 2
     ### Heading < 3
     """
     )
     expected = dedent(
         """
     Heading &amp; 1 - #heading-1
         Heading &gt; 2 - #heading-2
             Heading &lt; 3 - #heading-3
     """
     )
     toc = markdown_to_toc(md)
     self.assertEqual(str(toc).strip(), expected)