Beispiel #1
0
def test_html_whitelist_pre():
    """The pre element represents a block of preformatted text."""
    check_html_output_contains_text("""
        <pre>
            Some preformatted   text lives  here
        </pre>
    """)
Beispiel #2
0
def test_html_bare_text_linebreaks():
    """Line breaks in bare text should be removed."""
    check_html_output_contains_text(
        """
        Bare text with
        some linebreaks here
    """, "<p>Bare text with some linebreaks here</p>")
Beispiel #3
0
def test_html_whitelist_ul():
    """The ul element defines an unordered list."""
    check_html_output_contains_text("""
        <ul>
            <li>Item 1</li>
            <li>Item 2</li>
        </ul>
    """)
Beispiel #4
0
def test_html_bare_text_double_br():
    """Double <br> in bare text should trigger a new paragraph."""
    check_html_output_contains_text(
        """
        Bare text with
        <br/><br/>
        some linebreaks here
    """, "<p>Bare text with</p><p>some linebreaks here</p>")
Beispiel #5
0
def test_html_whitelist_p():
    """The p element defines a paragraph."""
    check_html_output_contains_text("""
        <p>Nulla venenatis nulla porta, vestibulum felis ac, faucibus urna.</p>
        <p>
            Praesent imperdiet nec justo at blandit. Morbi ultrices urna in
            elementum viverra.
        </p>
    """)
Beispiel #6
0
def test_html_space_separated_double_br():
    """Double <br> separated by whitespace should still trigger a new paragraph."""
    check_html_output_contains_text(
        """
        Bare text with
        <br/>
               <br/>
        some linebreaks here
    """, "<p>Bare text with</p><p>some linebreaks here</p>")
Beispiel #7
0
def test_html_whitelist_dt():
    """The dt element is a term in a description list."""
    check_html_output_contains_text(
        """
        <dl>
            <dt>Term 1</dt>
            <dd>Description 1</dd>
        </dl>
    """, "<dt>Term 1</dt>")
Beispiel #8
0
def test_html_whitelist_td():
    """The td element represents a cell in a table."""
    check_html_output_contains_text(
        """
        <table>
        <tr>
            <td>Table cell content</td>
        </tr>
        </table>
    """, "<td>Table cell content</td>")
Beispiel #9
0
def test_html_whitelist_th():
    """The th element represents a header cell in a table."""
    check_html_output_contains_text(
        """
        <table>
        <tr>
            <th>Header text</th>
        </tr>
        </table>
    """, "<th>Header text</th>")
Beispiel #10
0
def test_html_whitelist_dl():
    """The dl element is a description list."""
    check_html_output_contains_text("""
        <dl>
            <dt>Term 1</dt>
            <dd>Description 1</dd>
            <dt>Term 2</dt>
            <dd>Description 2</dd>
        </dl>
    """)
Beispiel #11
0
def test_html_whitelist_tr():
    """The tr element represents a row in a table."""
    check_html_output_contains_text(
        """
        <table>
        <tr>
            <td>Table row content</td>
        </tr>
        </table>
    """, "<tr><td>Table row content</td></tr>")
Beispiel #12
0
def test_html_whitelist_footer():
    """The footer element is the footer for its nearest ancestor section."""
    check_html_output_contains_text("""
        <p>
            A dolor sit amet, consectetur adipisicing elit, sed do eiusmod
            tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
            minim veniam, quis nostrud exercitation ullamco laboris nisi ut
            aliquip ex ea commodo consequat.
        </p>
        <footer>Text about author and date</footer>
    """)
Beispiel #13
0
def test_html_whitelist_article():
    """An article is a self-contained composition in a document."""
    check_html_output_contains_text("""
        <article>
        <header>
            <h2>Lorem ipsum dolor sit amet</h2>
            <p>Consectetur adipiscing elit</p>
        </header>
        <p>Vestibulum leo nulla, imperdiet a pellentesque ultrices aliquam.</p>
        </article>
    """)
Beispiel #14
0
def test_html_space_separated_double_br_inside_div():
    """Double <br> separated by whitespace should still trigger a new div."""
    check_html_output_contains_text(
        """
        <div>
            Text with
            <br/>
                <br/>
            some linebreaks here
        <div>
    """, "<div><p>Text with</p><p>some linebreaks here</p></div>")
Beispiel #15
0
def test_html_whitelist_tfoot():
    """The tfoot element contains the column summary rows of its table."""
    check_html_output_contains_text(
        """
        <table>
        <tfoot>
            <tr>
                <td>Sum of column</td>
            </tr>
        </tfoot>
        </table>
    """, "<tfoot><tr><td>Sum of column</td></tr></tfoot>")
Beispiel #16
0
def test_html_whitelist_thead():
    """The thead element contains rows forming the header of its table."""
    check_html_output_contains_text(
        """
        <table>
        <thead>
            <tr>
                <th>Header</th>
            </tr>
        </thead>
        </table>
    """, "<thead><tr><th>Header</th></tr></thead>")
Beispiel #17
0
def test_html_whitelist_aside():
    """An aside is a tangentially related section, used for pull-quotes."""
    check_html_output_contains_text("""
        <p>
           Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
           libero neque, ullamcorper quis tristique.
        </p>
        <aside>
            <p>Aenean libero neque</p>
        </aside>
        <p>Pellentesque non sapien nec arcu facilisis gravida.</p>
    """)
Beispiel #18
0
def test_html_whitelist_table():
    """The table element represents data with more than one dimension."""
    check_html_output_contains_text(
        """
        <table>
        <tbody>
            <tr>
                <td>Table contents</td>
            </tr>
        </tbody>
        </table>
    """, "<table><tbody><tr><td>Table contents</td></tr></tbody></table>")
Beispiel #19
0
def test_html_whitelist_li():
    """The li element defines an item in a list."""
    check_html_output_contains_text(
        """
        <ul>
            <li>Item 1</li>
            <li>Item 2</li>
        </ul>
    """, """
        <li>Item 1</li>
        <li>Item 2</li>
    """)
Beispiel #20
0
def test_html_whitelist_tbody():
    """The tbody element represents a block of rows inside its parent table."""
    check_html_output_contains_text(
        """
        <table>
        <tbody>
            <tr>
                <td>Table body content</td>
            </tr>
        </tbody>
        </table>
    """, "<tbody><tr><td>Table body content</td></tr></tbody>")
Beispiel #21
0
def test_html_whitelist_h2_h3_h4_h5_h6():
    """hN elements represent headings for their sections in ranked order."""
    check_html_output_contains_text("""
        <h2>Second level</h2>
        <h3>Third level</h3>
        <h2>Also second-level</h2>
        <h3>Third level</h3>
        <h4>Fourth level</h4>
        <h5>Fifth level</h5>
        <h6>Bottom level</h6>
        <h4>Also fourth-level</h4>
        <h5>Also fifth level</h5>
    """)
Beispiel #22
0
def test_html_whitelist_header():
    """The header element contains introductory content for its ancestor."""
    check_html_output_contains_text("""
        <header>
            <p>Byline might live here for example.</p>
        </header>
        <p>
            A dolor sit amet, consectetur adipisicing elit, sed do eiusmod
            tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
            minim veniam, quis nostrud exercitation ullamco laboris nisi ut
            aliquip ex ea commodo consequat.
        </p>
    """)
Beispiel #23
0
def test_html_whitelist_figcaption():
    """The figcaption element represents the caption of its parent figure."""
    check_html_output_contains_text(
        """
        <p>In <a href="#figref">this figure</a> we see some code.</p>
        <figure id="figref">
            <figcaption>Listing 1. Code description.</figcaption>
            <pre>
                <code>Some formatted code lives here</code>
            </pre>
        </figure>
        <p>Further details are given in this paragraph.</p>
    """, """
        <figcaption>Listing 1. Code description.</figcaption>
    """)
Beispiel #24
0
def test_html_whitelist_div():
    """The div element has no special meaning."""
    check_html_output_contains_text("""
        <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
            libero neque, ullamcorper quis tristique id pretium dapibus turpis.
        </p>
        <div>
            <p>Here is an example of using div for stylistic reasons.</p>
            <p>
                It marks several paragraphs which are in a different language
                from the rest of the text.
            </p>
        </div>
        <p>Pellentesque non sapien nec arcu facilisis gravida.</p>
    """)
Beispiel #25
0
def test_html_whitelist_main():
    """The main element contains content unique to its document."""
    check_html_output_contains_text(
        """
       <header>The header</header>
       <main>
            <p>A paragraph</p>
            <p>And another one</p>
        </main>
        <footer>The footer</footer>
    """, """
       <main>
            <p>A paragraph</p>
            <p>And another one</p>
        </main>
    """)
Beispiel #26
0
def test_html_whitelist_section():
    """The section element is a generic section of a document."""
    check_html_output_contains_text(
        """
        <section class="chapter">
            <h3 class="chaptertitle">My First Chapter</h3>
            <p>This is the first of my chapters. It doesn’t say much.</p>
            <p>But it has two paragraphs!</p>
        </section>
    """, """
        <section>
            <h3>My First Chapter</h3>
            <p>This is the first of my chapters. It doesn’t say much.</p>
            <p>But it has two paragraphs!</p>
        </section>
    """)
Beispiel #27
0
def test_html_whitelist_blockquote():
    """The blockquote element contains quotes from another source."""
    check_html_output_contains_text("""
        <p>He began his list of "lessons" with the following:</p>
        <blockquote>
            One should never assume that his side of the issue will be
            recognized, let alone that it will be conceded to have merits.
        </blockquote>
        <p>He continued with a number of similar points, ending with:</p>
        <blockquote>
            Finally, one should be prepared for the threat of breakdown in
            negotiations at any given moment and not be cowed by the
            possibility.
        </blockquote>
        <p>We shall now discuss these points...</p>
    """)
Beispiel #28
0
def test_html_whitelist_caption():
    """The caption element represents the title of its parent table."""
    check_html_output_contains_text(
        """
        <p>The caption provides context to the table.</p>
        <table>
            <caption>
                Table 1. This shows the possible results of flipping two coins.
            </caption>
            <tbody>
                <tr>
                    <th></th>
                    <th>H</th>
                    <th>T</th>
                </tr>
            </tbody>
        </table>
    """,
        "<caption>Table 1. This shows the possible results of flipping two coins.</caption>"
    )
Beispiel #29
0
def test_html_whitelist_rowspan():
    """The rowspan attribute allows cells to span multiple rows."""
    check_html_output_contains_text(
        """
    <table>
        <tr>
            <th>Month</th>
            <th>Savings</th>
            <th>Savings for holiday!</th>
        </tr>
        <tr>
            <td>January</td>
            <td>100</td>
            <td rowspan="2">50</td>
        </tr>
        <tr>
            <td>February</td>
            <td>80</td>
        </tr>
    </table>
    """, '<td rowspan="2">50</td>')
Beispiel #30
0
def test_html_whitelist_colspan():
    """The colspan attribute allows cells to span multiple columns."""
    check_html_output_contains_text(
        """
        <table>
            <tr>
                <th>Month</th>
                <th>Savings</th>
            </tr>
            <tr>
                <td>January</td>
                <td>100</td>
            </tr>
            <tr>
                <td>February</td>
                <td>80</td>
            </tr>
            <tr>
                <td colspan="2">Sum: 180</td>
            </tr>
        </table>
    """, '<td colspan="2">Sum: 180</td>')