Ejemplo n.º 1
0
    def test_multilevel_implicit_section_extract(self):
        doc_src = """
            <p>test</p>

            <h1 id="s4">Head 4</h1>
            <p>test</p>
            <p>test</p>
            <h2 id="s4-1">Head 4-1</h2>
            <p>test</p>
            <p>test</p>
            <h3 id="s4-2">Head 4-1-1</h3>
            <p>test</p>
            <p>test</p>

            <h1 id="s4-next">Head</h1>
            <p>test</p>
        """
        expected = """
            <h1 id="s4">Head 4</h1>
            <p>test</p>
            <p>test</p>
            <h2 id="s4-1">Head 4-1</h1>
            <p>test</p>
            <p>test</p>
            <h3 id="s4-2">Head 4-1-1</h1>
            <p>test</p>
            <p>test</p>
        """
        result = (kuma.wiki.content.parse(doc_src)
                                   .extractSection(id="s4")
                                   .serialize())
        eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 2
0
 def test_ignore_heading_section_replace(self):
     doc_src = """
         <h1 id="s1">Head 1</h1>
         <p>test</p>
         <p>test</p>
         <h1 id="s2">Head 2</h1>
         <p>test</p>
         <p>test</p>
         <h1 id="s3">Head 3</h1>
         <p>test</p>
         <p>test</p>
     """
     replace_src = """
         <p>replacement worked yay hooray</p>
     """
     expected = """
         <h1 id="s1">Head 1</h1>
         <p>test</p>
         <p>test</p>
         <h1 id="s2">Head 2</h1>
         <p>replacement worked yay hooray</p>
         <h1 id="s3">Head 3</h1>
         <p>test</p>
         <p>test</p>
     """
     result = (kuma.wiki.content
               .parse(doc_src)
               .replaceSection(id="s2",
                               replace_src=replace_src,
                               ignore_heading=True)
               .serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 3
0
 def test_keep_markup(self):
     content = """
         <h2 id="Summary">Summary</h2>
         <p>The <strong>Document Object Model </strong>
         (<strong>DOM</strong>) is an API for <a href="/en-US/docs/HTML"
         title="en-US/docs/HTML">HTML</a> and <a href="/en-US/docs/XML"
         title="en-US/docs/XML">XML</a> documents. It provides a structural
         representation of the document, enabling you to modify its content
         and visual presentation by using a scripting language such as <a
         href="/en-US/docs/JavaScript"
         title="https://developer.mozilla.org/en-US/docs/JavaScript">
         JavaScript</a>.</span></p>
      """
     expected = """
         The <strong>Document Object Model </strong>
         (<strong>DOM</strong>) is an API for <a href="/en-US/docs/HTML"
         title="en-US/docs/HTML">HTML</a> and <a href="/en-US/docs/XML"
         title="en-US/docs/XML">XML</a> documents. It provides a structural
         representation of the document, enabling you to modify its content
         and visual presentation by using a scripting language such as <a
         href="/en-US/docs/JavaScript"
         title="https://developer.mozilla.org/en-US/docs/JavaScript">
         JavaScript</a>.</span>
     """
     eq_(normalize_html(expected),
         normalize_html(get_seo_description(content, 'en-US', False)))
Ejemplo n.º 4
0
 def test_ignore_heading_section_replace(self):
     doc_src = """
         <h1 id="s1">Head 1</h1>
         <p>test</p>
         <p>test</p>
         <h1 id="s2">Head 2</h1>
         <p>test</p>
         <p>test</p>
         <h1 id="s3">Head 3</h1>
         <p>test</p>
         <p>test</p>
     """
     replace_src = """
         <p>replacement worked yay hooray</p>
     """
     expected = """
         <h1 id="s1">Head 1</h1>
         <p>test</p>
         <p>test</p>
         <h1 id="s2">Head 2</h1>
         <p>replacement worked yay hooray</p>
         <h1 id="s3">Head 3</h1>
         <p>test</p>
         <p>test</p>
     """
     result = (kuma.wiki.content
               .parse(doc_src)
               .replaceSection(id="s2",
                               replace_src=replace_src,
                               ignore_heading=True)
               .serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 5
0
    def test_multilevel_implicit_section_extract(self):
        doc_src = """
            <p>test</p>

            <h1 id="s4">Head 4</h1>
            <p>test</p>
            <p>test</p>
            <h2 id="s4-1">Head 4-1</h2>
            <p>test</p>
            <p>test</p>
            <h3 id="s4-2">Head 4-1-1</h3>
            <p>test</p>
            <p>test</p>

            <h1 id="s4-next">Head</h1>
            <p>test</p>
        """
        expected = """
            <h1 id="s4">Head 4</h1>
            <p>test</p>
            <p>test</p>
            <h2 id="s4-1">Head 4-1</h1>
            <p>test</p>
            <p>test</p>
            <h3 id="s4-2">Head 4-1-1</h1>
            <p>test</p>
            <p>test</p>
        """
        result = (kuma.wiki.content
                  .parse(doc_src)
                  .extractSection(id="s4")
                  .serialize())
        eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 6
0
 def test_section_edit_links(self):
     doc_src = """
         <h1 id="s1">Head 1</h1>
         <p>test</p>
         <p>test</p>
         <h2 id="s2">Head 2</h2>
         <p>test</p>
         <p>test</p>
         <h3 id="s3">Head 3</h3>
         <p>test</p>
         <p>test</p>
     """
     expected = """
         <h1 id="s1"><a class="edit-section" data-section-id="s1" data-section-src-url="/en-US/docs/some-slug?raw=true&amp;section=s1" href="/en-US/docs/some-slug$edit?section=s1&amp;edit_links=true" title="Edit section">Edit</a>Head 1</h1>
         <p>test</p>
         <p>test</p>
         <h2 id="s2"><a class="edit-section" data-section-id="s2" data-section-src-url="/en-US/docs/some-slug?raw=true&amp;section=s2" href="/en-US/docs/some-slug$edit?section=s2&amp;edit_links=true" title="Edit section">Edit</a>Head 2</h2>
         <p>test</p>
         <p>test</p>
         <h3 id="s3"><a class="edit-section" data-section-id="s3" data-section-src-url="/en-US/docs/some-slug?raw=true&amp;section=s3" href="/en-US/docs/some-slug$edit?section=s3&amp;edit_links=true" title="Edit section">Edit</a>Head 3</h3>
         <p>test</p>
         <p>test</p>
     """
     result = (kuma.wiki.content
               .parse(doc_src)
               .injectSectionEditingLinks('some-slug', 'en-US')
               .serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 7
0
 def test_section_edit_links(self):
     doc_src = """
         <h1 id="s1">Head 1</h1>
         <p>test</p>
         <p>test</p>
         <h2 id="s2">Head 2</h2>
         <p>test</p>
         <p>test</p>
         <h3 id="s3">Head 3</h3>
         <p>test</p>
         <p>test</p>
     """
     expected = """
         <h1 id="s1"><a class="edit-section" data-section-id="s1" data-section-src-url="/en-US/docs/some-slug?raw=true&amp;section=s1" href="/en-US/docs/some-slug$edit?section=s1&amp;edit_links=true" title="Edit section">Edit</a>Head 1</h1>
         <p>test</p>
         <p>test</p>
         <h2 id="s2"><a class="edit-section" data-section-id="s2" data-section-src-url="/en-US/docs/some-slug?raw=true&amp;section=s2" href="/en-US/docs/some-slug$edit?section=s2&amp;edit_links=true" title="Edit section">Edit</a>Head 2</h2>
         <p>test</p>
         <p>test</p>
         <h3 id="s3"><a class="edit-section" data-section-id="s3" data-section-src-url="/en-US/docs/some-slug?raw=true&amp;section=s3" href="/en-US/docs/some-slug$edit?section=s3&amp;edit_links=true" title="Edit section">Edit</a>Head 3</h3>
         <p>test</p>
         <p>test</p>
     """
     result = (kuma.wiki.content
               .parse(doc_src)
               .injectSectionEditingLinks('some-slug', 'en-US')
               .serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 8
0
 def test_editor_safety_filter(self):
     """Markup that's hazardous for editing should be stripped"""
     doc_src = """
         <svg><circle onload=confirm(3)>
         <h1 class="header1">Header One</h1>
         <p>test</p>
         <section>
             <h1 class="header2">Header Two</h1>
             <p>test</p>
         </section>
         <h1 class="header3">Header Three</h1>
         <p>test</p>
     """
     expected_src = """
         <svg><circle>
         <h1 class="header1">Header One</h1>
         <p>test</p>
         <section>
             <h1 class="header2">Header Two</h1>
             <p>test</p>
         </section>
         <h1 class="header3">Header Three</h1>
         <p>test</p>
     """
     result_src = (kuma.wiki.content.parse(doc_src)
                   .filterEditorSafety()
                   .serialize())
     eq_(normalize_html(expected_src), normalize_html(result_src))
Ejemplo n.º 9
0
 def test_generate_toc_h2(self):
     doc_src = """
         <h2 id="HTML">HTML</h2>
           <h3 id="HTML5_canvas_element">HTML5 <code>canvas</code> element</h3>
         <h2 id="JavaScript">JavaScript</h2>
           JavaScript is awesome.
           <h3 id="WebGL">WebGL</h3>
           <h3 id="Audio">Audio</h3>
             <h4 id="Audio-API">Audio API</h4>
         <h2 id="CSS">CSS</h2>
             <h4 id="CSS_transforms">CSS transforms</h4>
           <h3 id="Gradients">Gradients</h3>
             <h4 id="Scaling_backgrounds">Scaling backgrounds</h4>
     """
     expected = """
         <li><a rel="internal" href="#HTML">HTML</a>
         </li>
         <li><a rel="internal" href="#JavaScript">JavaScript</a>
         </li>
         <li><a rel="internal" href="#CSS">CSS</a>
         </li>
     """
     result = (kuma.wiki.content
               .parse(doc_src)
               .filter(H2TOCFilter).serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 10
0
 def test_code_syntax_conversion(self):
     doc_src = """
         <h2>Some JavaScript</h2>:
         <pre class="deki-transform" function="syntax.JavaScript">
         function foo(){
             alert("bar");
         }
         </pre>
         <pre>Some CSS:</pre>
         <pre class="dek-trans" function="syntax.CSS">
         .dek-trans { color: red; }
         </pre>
     """
     expected = """
         <h2>Some JavaScript</h2>:
         <pre class="brush: js">
         function foo(){
             alert("bar");
         }
         </pre>
         <pre>Some CSS:</pre>
         <pre class="brush: css">
         .dek-trans { color: red; }
         </pre>
     """
     result = (kuma.wiki.content
               .parse(doc_src)
               .filter(CodeSyntaxFilter).serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 11
0
 def test_generate_toc_h2(self):
     doc_src = """
         <h2 id="HTML">HTML</h2>
           <h3 id="HTML5_canvas_element">HTML5 <code>canvas</code> element</h3>
         <h2 id="JavaScript">JavaScript</h2>
           JavaScript is awesome.
           <h3 id="WebGL">WebGL</h3>
           <h3 id="Audio">Audio</h3>
             <h4 id="Audio-API">Audio API</h4>
         <h2 id="CSS">CSS</h2>
             <h4 id="CSS_transforms">CSS transforms</h4>
           <h3 id="Gradients">Gradients</h3>
             <h4 id="Scaling_backgrounds">Scaling backgrounds</h4>
     """
     expected = """
         <li><a rel="internal" href="#HTML">HTML</a>
         </li>
         <li><a rel="internal" href="#JavaScript">JavaScript</a>
         </li>
         <li><a rel="internal" href="#CSS">CSS</a>
         </li>
     """
     result = (kuma.wiki.content
               .parse(doc_src)
               .filter(H2TOCFilter).serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 12
0
 def test_editor_safety_filter(self):
     """Markup that's hazardous for editing should be stripped"""
     doc_src = """
         <svg><circle onload=confirm(3)>
         <h1 class="header1">Header One</h1>
         <p>test</p>
         <section>
             <h1 class="header2">Header Two</h1>
             <p>test</p>
         </section>
         <h1 class="header3">Header Three</h1>
         <p>test</p>
     """
     expected_src = """
         <svg><circle>
         <h1 class="header1">Header One</h1>
         <p>test</p>
         <section>
             <h1 class="header2">Header Two</h1>
             <p>test</p>
         </section>
         <h1 class="header3">Header Three</h1>
         <p>test</p>
     """
     result_src = (kuma.wiki.content.parse(doc_src)
                   .filterEditorSafety()
                   .serialize())
     eq_(normalize_html(expected_src), normalize_html(result_src))
Ejemplo n.º 13
0
 def test_keep_markup(self):
     content = """
         <h2 id="Summary">Summary</h2>
         <p>The <strong>Document Object Model </strong>
         (<strong>DOM</strong>) is an API for <a href="/en-US/docs/HTML"
         title="en-US/docs/HTML">HTML</a> and <a href="/en-US/docs/XML"
         title="en-US/docs/XML">XML</a> documents. It provides a structural
         representation of the document, enabling you to modify its content
         and visual presentation by using a scripting language such as <a
         href="/en-US/docs/JavaScript"
         title="https://developer.mozilla.org/en-US/docs/JavaScript">
         JavaScript</a>.</span></p>
      """
     expected = """
         The <strong>Document Object Model </strong>
         (<strong>DOM</strong>) is an API for <a href="/en-US/docs/HTML"
         title="en-US/docs/HTML">HTML</a> and <a href="/en-US/docs/XML"
         title="en-US/docs/XML">XML</a> documents. It provides a structural
         representation of the document, enabling you to modify its content
         and visual presentation by using a scripting language such as <a
         href="/en-US/docs/JavaScript"
         title="https://developer.mozilla.org/en-US/docs/JavaScript">
         JavaScript</a>.</span>
     """
     eq_(normalize_html(expected),
         normalize_html(get_seo_description(content, 'en-US', False)))
Ejemplo n.º 14
0
 def test_code_syntax_conversion(self):
     doc_src = """
         <h2>Some JavaScript</h2>:
         <pre class="deki-transform" function="syntax.JavaScript">
         function foo(){
             alert("bar");
         }
         </pre>
         <pre>Some CSS:</pre>
         <pre class="dek-trans" function="syntax.CSS">
         .dek-trans { color: red; }
         </pre>
     """
     expected = """
         <h2>Some JavaScript</h2>:
         <pre class="brush: js">
         function foo(){
             alert("bar");
         }
         </pre>
         <pre>Some CSS:</pre>
         <pre class="brush: css">
         .dek-trans { color: red; }
         </pre>
     """
     result = (kuma.wiki.content
               .parse(doc_src)
               .filter(CodeSyntaxFilter).serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 15
0
    def test_form_save_section(self):
        d, r = doc_rev("""
            <h1 id="s1">s1</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s2">s2</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s3">s3</h1>
            <p>test</p>
            <p>test</p>
        """)
        replace_content = """
            <h1 id="s2">New stuff</h1>
            <p>new stuff</p>
        """
        expected = """
            <h1 id="s1">s1</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s2">New stuff</h1>
            <p>new stuff</p>

            <h1 id="s3">s3</h1>
            <p>test</p>
            <p>test</p>
        """
        rev_form = RevisionForm({"content": replace_content},
                                instance=r,
                                section_id="s2")
        new_rev = rev_form.save(r.creator, d)
        eq_(normalize_html(expected), normalize_html(new_rev.content))
Ejemplo n.º 16
0
 def test_stripped_ie_comment(self):
     """bug 801046: strip IE conditional comments"""
     content = """
         <p>Hi there.</p>
         <!--[if]><script>alert(1)</script -->
         <!--[if<img src=x onerror=alert(2)//]> -->
         <p>Goodbye</p>
     """
     expected = """
         <p>Hi there.</p>
         <p>Goodbye</p>
     """
     result = Document.objects.clean_content(content)
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 17
0
 def test_stripped_ie_comment(self):
     """bug 801046: strip IE conditional comments"""
     content = """
         <p>Hi there.</p>
         <!--[if]><script>alert(1)</script -->
         <!--[if<img src=x onerror=alert(2)//]> -->
         <p>Goodbye</p>
     """
     expected = """
         <p>Hi there.</p>
         <p>Goodbye</p>
     """
     result = Document.objects.clean_content(content)
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 18
0
 def test_iframe_host_contents_filter(self):
     """Any contents inside an <iframe> should be removed"""
     doc_src = """
         <iframe>
         <iframe src="javascript:alert(1);"></iframe>
         </iframe>
     """
     expected_src = """
         <iframe>
         </iframe>
     """
     result_src = (kuma.wiki.content.parse(doc_src).filterIframeHosts(
         '^https?\:\/\/sampleserver').serialize())
     eq_(normalize_html(expected_src), normalize_html(result_src))
Ejemplo n.º 19
0
 def test_bug_925043(self):
     '''Bug 925043 - Redesign TOC has a bunch of empty <code> tags in markup'''
     doc_src = """
         <h2 id="Print">Mastering <code>print</code></h2>
         <code>print 'Hello World!'</code>
     """
     expected = """
         <li>
             <a href="#Print" rel="internal">Mastering<code>print</code></a>
         </li>
     """
     result = (kuma.wiki.content.parse(doc_src).filter(
         SectionTOCFilter).serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 20
0
 def test_iframe_host_contents_filter(self):
     """Any contents inside an <iframe> should be removed"""
     doc_src = """
         <iframe>
         <iframe src="javascript:alert(1);"></iframe>
         </iframe>
     """
     expected_src = """
         <iframe>
         </iframe>
     """
     result_src = (kuma.wiki.content.parse(doc_src)
                   .filterIframeHosts('^https?\:\/\/sampleserver')
                   .serialize())
     eq_(normalize_html(expected_src), normalize_html(result_src))
Ejemplo n.º 21
0
 def test_bug_925043(self):
     '''Bug 925043 - Redesign TOC has a bunch of empty <code> tags in markup'''
     doc_src = """
         <h2 id="Print">Mastering <code>print</code></h2>
         <code>print 'Hello World!'</code>
     """
     expected = """
         <li>
             <a href="#Print" rel="internal">Mastering<code>print</code></a>
         </li>
     """
     result = (kuma.wiki.content
               .parse(doc_src)
               .filter(SectionTOCFilter).serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 22
0
    def test_morelevels_implicit_section_extract(self):
        doc_src = """
            <h1 id="s7">Head 7</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s8">Head</h1>
            <p>test</p>
            <h2 id="s8-1">Head</h1>
            <p>test</p>
            <h3 id="s8-1-1">Head</h3>
            <p>test</p>
            <h2 id="s8-2">Head</h1>
            <p>test</p>
            <h3 id="s8-2-1">Head</h3>
            <p>test</p>
            <h4 id="s8-2-1-1">Head</h4>
            <p>test</p>
            <h2 id="s8-3">Head</h1>
            <p>test</p>

            <h1 id="s9">Head</h1>
            <p>test</p>
            <p>test</p>
        """
        expected = """
            <h1 id="s8">Head</h1>
            <p>test</p>
            <h2 id="s8-1">Head</h1>
            <p>test</p>
            <h3 id="s8-1-1">Head</h3>
            <p>test</p>
            <h2 id="s8-2">Head</h1>
            <p>test</p>
            <h3 id="s8-2-1">Head</h3>
            <p>test</p>
            <h4 id="s8-2-1-1">Head</h4>
            <p>test</p>
            <h2 id="s8-3">Head</h1>
            <p>test</p>
        """
        result = (kuma.wiki.content
                  .parse(doc_src)
                  .extractSection(id="s8")
                  .serialize())
        eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 23
0
    def test_morelevels_implicit_section_extract(self):
        doc_src = """
            <h1 id="s7">Head 7</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s8">Head</h1>
            <p>test</p>
            <h2 id="s8-1">Head</h1>
            <p>test</p>
            <h3 id="s8-1-1">Head</h3>
            <p>test</p>
            <h2 id="s8-2">Head</h1>
            <p>test</p>
            <h3 id="s8-2-1">Head</h3>
            <p>test</p>
            <h4 id="s8-2-1-1">Head</h4>
            <p>test</p>
            <h2 id="s8-3">Head</h1>
            <p>test</p>

            <h1 id="s9">Head</h1>
            <p>test</p>
            <p>test</p>
        """
        expected = """
            <h1 id="s8">Head</h1>
            <p>test</p>
            <h2 id="s8-1">Head</h1>
            <p>test</p>
            <h3 id="s8-1-1">Head</h3>
            <p>test</p>
            <h2 id="s8-2">Head</h1>
            <p>test</p>
            <h3 id="s8-2-1">Head</h3>
            <p>test</p>
            <h4 id="s8-2-1-1">Head</h4>
            <p>test</p>
            <h2 id="s8-3">Head</h1>
            <p>test</p>
        """
        result = (kuma.wiki.content
                  .parse(doc_src)
                  .extractSection(id="s8")
                  .serialize())
        eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 24
0
    def test_simple_implicit_section_extract(self):
        doc_src = """
            <h1 id="s1">Head 1</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s2">Head 2</h1>
            <p>test</p>
            <p>test</p>
        """
        expected = """
            <h1 id="s1">Head 1</h1>
            <p>test</p>
            <p>test</p>
        """
        result = (kuma.wiki.content.parse(doc_src).extractSection(
            id="s1").serialize())
        eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 25
0
    def test_explicit_section_extract(self):
        doc_src = """
            <h1 id="s4-next">Head</h1>
            <p>test</p>

            <section id="parent-s5">
                <h1 id="s5">Head 5</h1>
                <p>test</p>
                <p>test</p>
                <section>
                    <h1>head subsection</h1>
                </section>
                <h2 id="s5-1">Head 5-1</h2>
                <p>test</p>
                <p>test</p>
                <h1 id="s5-next">Head 5 next</h1>
                <p>test</p>
                <p>test</p>
            </section>

            <h1 id="s7">Head 7</h1>
            <p>test</p>
            <p>test</p>
        """
        expected = """
                <h1 id="s5">Head 5</h1>
                <p>test</p>
                <p>test</p>
                <section>
                    <h1>head subsection</h1>
                </section>
                <h2 id="s5-1">Head 5-1</h2>
                <p>test</p>
                <p>test</p>
                <h1 id="s5-next">Head 5 next</h1>
                <p>test</p>
                <p>test</p>
        """
        result = (kuma.wiki.content
                  .parse(doc_src)
                  .extractSection(id="parent-s5")
                  .serialize())
        eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 26
0
    def test_explicit_section_extract(self):
        doc_src = """
            <h1 id="s4-next">Head</h1>
            <p>test</p>

            <section id="parent-s5">
                <h1 id="s5">Head 5</h1>
                <p>test</p>
                <p>test</p>
                <section>
                    <h1>head subsection</h1>
                </section>
                <h2 id="s5-1">Head 5-1</h2>
                <p>test</p>
                <p>test</p>
                <h1 id="s5-next">Head 5 next</h1>
                <p>test</p>
                <p>test</p>
            </section>

            <h1 id="s7">Head 7</h1>
            <p>test</p>
            <p>test</p>
        """
        expected = """
                <h1 id="s5">Head 5</h1>
                <p>test</p>
                <p>test</p>
                <section>
                    <h1>head subsection</h1>
                </section>
                <h2 id="s5-1">Head 5-1</h2>
                <p>test</p>
                <p>test</p>
                <h1 id="s5-next">Head 5 next</h1>
                <p>test</p>
                <p>test</p>
        """
        result = (kuma.wiki.content
                  .parse(doc_src)
                  .extractSection(id="parent-s5")
                  .serialize())
        eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 27
0
    def test_simple_implicit_section_extract(self):
        doc_src = """
            <h1 id="s1">Head 1</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s2">Head 2</h1>
            <p>test</p>
            <p>test</p>
        """
        expected = """
            <h1 id="s1">Head 1</h1>
            <p>test</p>
            <p>test</p>
        """
        result = (kuma.wiki.content.parse(doc_src)
                                   .extractSection(id="s1")
                                   .serialize())
        eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 28
0
    def test_dekiscript_macro_conversion(self):
        doc_src = u"""
            <span>Just a span</span>
            <span class="notascript">Hi there</span>
            <li><span class="script">Warning("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong>strongly</strong> discouraged!")</span></li>
            <li><span class="script">Note("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong class="important">strongly</strong> discouraged!")</span></li>
            <li><span class="script">MixedCaseName('parameter1', 'parameter2')</span></li>
            <li><span class="script">template.lowercasename('border')</span></li>
            <li><span class="script">Template.UpperCaseTemplate("foo")</span></li>
            <li><span class="script">wiki.template('英語版章題', [ "Reusing tabs" ])</span></li>
            <li><span class="script">template("non-standard_inline", ["Reusing tabs", "YAY"])</span></li>
            <li><span class="script">wiki.template('英語版章題')</span></li>
            <li><span class="script">template("non-standard_inline")</span></li>
        """
        expected = u"""
            <span>Just a span</span>
            <span class="notascript">Hi there</span>
            <li>{{ Warning("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong>strongly</strong> discouraged!") }}</li>
            <li>{{ Note("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong class="important">strongly</strong> discouraged!") }}</li>
            <li>{{ MixedCaseName('parameter1', 'parameter2') }}</li>
            <li>{{ lowercasename('border') }}</li>
            <li>{{ UpperCaseTemplate("foo") }}</li>
            <li>{{ 英語版章題("Reusing tabs") }}</li>
            <li>{{ non-standard_inline("Reusing tabs", "YAY") }}</li>
            <li>{{ 英語版章題() }}</li>
            <li>{{ non-standard_inline() }}</li>
        """

        # Check line-by-line, to help work out any issues failure-by-failure
        doc_src_lines = doc_src.split("\n")
        expected_lines = expected.split("\n")
        for i in range(0, len(doc_src_lines)):
            result = (kuma.wiki.content
                      .parse(doc_src_lines[i])
                      .filter(DekiscriptMacroFilter).serialize())
            eq_(normalize_html(expected_lines[i]), normalize_html(result))

        # But, the whole thing should work in the filter, as well.
        result = (kuma.wiki.content
                  .parse(doc_src)
                  .filter(DekiscriptMacroFilter).serialize())
        eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 29
0
    def test_dekiscript_macro_conversion(self):
        doc_src = u"""
            <span>Just a span</span>
            <span class="notascript">Hi there</span>
            <li><span class="script">Warning("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong>strongly</strong> discouraged!")</span></li>
            <li><span class="script">Note("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong class="important">strongly</strong> discouraged!")</span></li>
            <li><span class="script">MixedCaseName('parameter1', 'parameter2')</span></li>
            <li><span class="script">template.lowercasename('border')</span></li>
            <li><span class="script">Template.UpperCaseTemplate("foo")</span></li>
            <li><span class="script">wiki.template('英語版章題', [ "Reusing tabs" ])</span></li>
            <li><span class="script">template("non-standard_inline", ["Reusing tabs", "YAY"])</span></li>
            <li><span class="script">wiki.template('英語版章題')</span></li>
            <li><span class="script">template("non-standard_inline")</span></li>
        """
        expected = u"""
            <span>Just a span</span>
            <span class="notascript">Hi there</span>
            <li>{{ Warning("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong>strongly</strong> discouraged!") }}</li>
            <li>{{ Note("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong class="important">strongly</strong> discouraged!") }}</li>
            <li>{{ MixedCaseName('parameter1', 'parameter2') }}</li>
            <li>{{ lowercasename('border') }}</li>
            <li>{{ UpperCaseTemplate("foo") }}</li>
            <li>{{ 英語版章題("Reusing tabs") }}</li>
            <li>{{ non-standard_inline("Reusing tabs", "YAY") }}</li>
            <li>{{ 英語版章題() }}</li>
            <li>{{ non-standard_inline() }}</li>
        """

        # Check line-by-line, to help work out any issues failure-by-failure
        doc_src_lines = doc_src.split("\n")
        expected_lines = expected.split("\n")
        for i in range(0, len(doc_src_lines)):
            result = (kuma.wiki.content
                      .parse(doc_src_lines[i])
                      .filter(DekiscriptMacroFilter).serialize())
            eq_(normalize_html(expected_lines[i]), normalize_html(result))

        # But, the whole thing should work in the filter, as well.
        result = (kuma.wiki.content
                  .parse(doc_src)
                  .filter(DekiscriptMacroFilter).serialize())
        eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 30
0
 def test_ignore_heading_section_extract(self):
     doc_src = """
         <p>test</p>
         <h1 id="s4">Head 4</h1>
         <p>test</p>
         <h2 id="s4-1">Head 4-1</h2>
         <p>test</p>
         <h3 id="s4-2">Head 4-1-1</h3>
         <p>test s4-2</p>
         <h1 id="s4-next">Head</h1>
         <p>test</p>
     """
     expected = """
         <p>test</p>
         <h3 id="s4-2">Head 4-1-1</h3>
         <p>test s4-2</p>
     """
     result = (kuma.wiki.content.parse(doc_src).extractSection(
         id="s4-1", ignore_heading=True).serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 31
0
 def test_noinclude(self):
     doc_src = u"""
         <div class="noinclude">{{ XULRefAttr() }}</div>
         <dl>
           <dt>{{ XULAttr(&quot;maxlength&quot;) }}</dt>
           <dd>Type: <em>integer</em></dd>
           <dd>Przykłady 例 예제 示例</dd>
         </dl>
         <div class="noinclude">
           <p>{{ languages( { &quot;ja&quot;: &quot;ja/XUL/Attribute/maxlength&quot; } ) }}</p>
         </div>
     """
     expected = u"""
         <dl>
           <dt>{{ XULAttr(&quot;maxlength&quot;) }}</dt>
           <dd>Type: <em>integer</em></dd>
           <dd>Przykłady 例 예제 示例</dd>
         </dl>
     """
     result = (kuma.wiki.content.filter_out_noinclude(doc_src))
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 32
0
 def test_noinclude(self):
     doc_src = u"""
         <div class="noinclude">{{ XULRefAttr() }}</div>
         <dl>
           <dt>{{ XULAttr(&quot;maxlength&quot;) }}</dt>
           <dd>Type: <em>integer</em></dd>
           <dd>Przykłady 例 예제 示例</dd>
         </dl>
         <div class="noinclude">
           <p>{{ languages( { &quot;ja&quot;: &quot;ja/XUL/Attribute/maxlength&quot; } ) }}</p>
         </div>
     """
     expected = u"""
         <dl>
           <dt>{{ XULAttr(&quot;maxlength&quot;) }}</dt>
           <dd>Type: <em>integer</em></dd>
           <dd>Przykłady 例 예제 示例</dd>
         </dl>
     """
     result = (kuma.wiki.content.filter_out_noinclude(doc_src))
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 33
0
 def test_ignore_heading_section_extract(self):
     doc_src = """
         <p>test</p>
         <h1 id="s4">Head 4</h1>
         <p>test</p>
         <h2 id="s4-1">Head 4-1</h2>
         <p>test</p>
         <h3 id="s4-2">Head 4-1-1</h3>
         <p>test s4-2</p>
         <h1 id="s4-next">Head</h1>
         <p>test</p>
     """
     expected = """
         <p>test</p>
         <h3 id="s4-2">Head 4-1-1</h3>
         <p>test s4-2</p>
     """
     result = (kuma.wiki.content
               .parse(doc_src)
               .extractSection(id="s4-1", ignore_heading=True)
               .serialize())
     eq_(normalize_html(expected), normalize_html(result))
Ejemplo n.º 34
0
    def test_form_loaded_with_section(self):
        """RevisionForm given section_id should load initial content for only
        one section"""
        d, r = doc_rev("""
            <h1 id="s1">s1</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s2">s2</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s3">s3</h1>
            <p>test</p>
            <p>test</p>
        """)
        expected = """
            <h1 id="s2">s2</h1>
            <p>test</p>
            <p>test</p>
        """
        rev_form = RevisionForm(instance=r, section_id="s2")
        eq_(normalize_html(expected),
            normalize_html(rev_form.initial['content']))
Ejemplo n.º 35
0
    def test_form_save_section(self):
        d, r = doc_rev("""
            <h1 id="s1">s1</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s2">s2</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s3">s3</h1>
            <p>test</p>
            <p>test</p>
        """)
        replace_content = """
            <h1 id="s2">New stuff</h1>
            <p>new stuff</p>
        """
        expected = """
            <h1 id="s1">s1</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s2">New stuff</h1>
            <p>new stuff</p>

            <h1 id="s3">s3</h1>
            <p>test</p>
            <p>test</p>
        """
        rev_form = RevisionForm({"content": replace_content},
                                instance=r,
                                section_id="s2")
        new_rev = rev_form.save(r.creator, d)
        eq_(normalize_html(expected),
            normalize_html(new_rev.content))
Ejemplo n.º 36
0
    def test_form_loaded_with_section(self):
        """RevisionForm given section_id should load initial content for only
        one section"""
        d, r = doc_rev("""
            <h1 id="s1">s1</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s2">s2</h1>
            <p>test</p>
            <p>test</p>

            <h1 id="s3">s3</h1>
            <p>test</p>
            <p>test</p>
        """)
        expected = """
            <h1 id="s2">s2</h1>
            <p>test</p>
            <p>test</p>
        """
        rev_form = RevisionForm(instance=r, section_id="s2")
        eq_(normalize_html(expected),
            normalize_html(rev_form.initial['content']))
Ejemplo n.º 37
0
    def test_link_annotation(self):
        d, r = doc_rev("This document exists")
        d.save()
        r.save()

        document(title=u'Héritée', locale=u'fr', slug=u'CSS/Héritage',
                 save=True)
        document(title=u'DOM/StyleSheet', locale=u'en-US',
                 slug=u'DOM/StyleSheet', save=True)

        base_url = u'https://testserver'
        vars = dict(
            base_url=base_url,
            exist_url=d.get_absolute_url(),
            exist_url_with_base=urljoin(base_url, d.get_absolute_url()),
            uilocale_url=u'/en-US/docs/%s/%s' % (d.locale, d.slug),
            noexist_url=u'/en-US/docs/no-such-doc',
            noexist_url_with_base=urljoin(base_url,
                                          u'/en-US/docs/no-such-doc'),
            noexist_uilocale_url=u'/en-US/docs/en-US/blah-blah-blah',
            nonen_slug='/fr/docs/CSS/H%c3%a9ritage',
            tag_url='/en-US/docs/tag/foo',
            feed_url='/en-US/docs/feeds/atom/all',
            templates_url='/en-US/docs/templates',
        )
        doc_src = u"""
                <li><a href="%(nonen_slug)s">Héritée</a></li>
                <li><a href="%(exist_url)s">This doc should exist</a></li>
                <li><a href="%(exist_url)s#withanchor">This doc should exist</a></li>
                <li><a href="%(exist_url_with_base)s">This doc should exist</a></li>
                <li><a href="%(exist_url_with_base)s#withanchor">This doc should exist</a></li>
                <li><a href="%(uilocale_url)s">This doc should exist</a></li>
                <li><a class="foobar" href="%(exist_url)s">This doc should exist, and its class should be left alone.</a></li>
                <li><a href="%(noexist_url)s#withanchor">This doc should NOT exist</a></li>
                <li><a href="%(noexist_url)s">This doc should NOT exist</a></li>
                <li><a href="%(noexist_url_with_base)s">This doc should NOT exist</a></li>
                <li><a href="%(noexist_url_with_base)s#withanchor">This doc should NOT exist</a></li>
                <li><a href="%(noexist_uilocale_url)s">This doc should NOT exist</a></li>
                <li><a class="foobar" href="%(noexist_url)s">This doc should NOT exist, and its class should be altered</a></li>
                <li><a href="http://mozilla.org/">This is an external link</a></li>
                <li><a class="foobar" name="quux">A lack of href should not cause a problem.</a></li>
                <li><a>In fact, a "link" with no attributes should be no problem as well.</a></li>
                <a href="%(tag_url)s">Tag link</a>
                <a href="%(feed_url)s">Feed link</a>
                <a href="%(templates_url)s">Templates link</a>
                <a href="/en-US/docs/DOM/stylesheet">Case sensitive 1</a>
                <a href="/en-US/docs/DOM/Stylesheet">Case sensitive 1</a>
                <a href="/en-US/docs/DOM/StyleSheet">Case sensitive 1</a>
                <a href="/en-us/docs/dom/StyleSheet">Case sensitive 1</a>
                <a href="/en-US/docs/dom/Styles">For good measure</a>
        """ % vars
        expected = u"""
                <li><a href="%(nonen_slug)s">Héritée</a></li>
                <li><a href="%(exist_url)s">This doc should exist</a></li>
                <li><a href="%(exist_url)s#withanchor">This doc should exist</a></li>
                <li><a href="%(exist_url_with_base)s">This doc should exist</a></li>
                <li><a href="%(exist_url_with_base)s#withanchor">This doc should exist</a></li>
                <li><a href="%(uilocale_url)s">This doc should exist</a></li>
                <li><a class="foobar" href="%(exist_url)s">This doc should exist, and its class should be left alone.</a></li>
                <li><a class="new" href="%(noexist_url)s#withanchor">This doc should NOT exist</a></li>
                <li><a class="new" href="%(noexist_url)s">This doc should NOT exist</a></li>
                <li><a class="new" href="%(noexist_url_with_base)s">This doc should NOT exist</a></li>
                <li><a class="new" href="%(noexist_url_with_base)s#withanchor">This doc should NOT exist</a></li>
                <li><a class="new" href="%(noexist_uilocale_url)s">This doc should NOT exist</a></li>
                <li><a class="foobar new" href="%(noexist_url)s">This doc should NOT exist, and its class should be altered</a></li>
                <li><a class="external" href="http://mozilla.org/">This is an external link</a></li>
                <li><a class="foobar" name="quux">A lack of href should not cause a problem.</a></li>
                <li><a>In fact, a "link" with no attributes should be no problem as well.</a></li>
                <a href="%(tag_url)s">Tag link</a>
                <a href="%(feed_url)s">Feed link</a>
                <a href="%(templates_url)s">Templates link</a>
                <a href="/en-US/docs/DOM/stylesheet">Case sensitive 1</a>
                <a href="/en-US/docs/DOM/Stylesheet">Case sensitive 1</a>
                <a href="/en-US/docs/DOM/StyleSheet">Case sensitive 1</a>
                <a href="/en-us/docs/dom/StyleSheet">Case sensitive 1</a>
                <a class="new" href="/en-US/docs/dom/Styles">For good measure</a>
        """ % vars

        # Split the markup into lines, to better see failures
        doc_lines = doc_src.strip().split("\n")
        expected_lines = expected.strip().split("\n")
        for idx in range(0, len(doc_lines)):
            doc_line = doc_lines[idx]
            expected_line = expected_lines[idx]
            result_line = (kuma.wiki.content.parse(doc_line)
                          .annotateLinks(base_url=vars['base_url'])
                          .serialize())
            eq_(normalize_html(expected_line), normalize_html(result_line))
Ejemplo n.º 38
0
    def test_link_annotation(self):
        d, r = doc_rev("This document exists")
        d.save()
        r.save()

        document(title=u'Héritée', locale=u'fr', slug=u'CSS/Héritage',
                 save=True)
        document(title=u'DOM/StyleSheet', locale=u'en-US',
                 slug=u'DOM/StyleSheet', save=True)

        base_url = u'https://testserver'
        vars = dict(
            base_url=base_url,
            exist_url=d.get_absolute_url(),
            exist_url_with_base=urljoin(base_url, d.get_absolute_url()),
            uilocale_url=u'/en-US/docs/%s/%s' % (d.locale, d.slug),
            noexist_url=u'/en-US/docs/no-such-doc',
            noexist_url_with_base=urljoin(base_url,
                                          u'/en-US/docs/no-such-doc'),
            noexist_uilocale_url=u'/en-US/docs/en-US/blah-blah-blah',
            nonen_slug='/fr/docs/CSS/H%c3%a9ritage',
            tag_url='/en-US/docs/tag/foo',
            feed_url='/en-US/docs/feeds/atom/all',
            templates_url='/en-US/docs/templates',
        )
        doc_src = u"""
                <li><a href="%(nonen_slug)s">Héritée</a></li>
                <li><a href="%(exist_url)s">This doc should exist</a></li>
                <li><a href="%(exist_url)s#withanchor">This doc should exist</a></li>
                <li><a href="%(exist_url_with_base)s">This doc should exist</a></li>
                <li><a href="%(exist_url_with_base)s#withanchor">This doc should exist</a></li>
                <li><a href="%(uilocale_url)s">This doc should exist</a></li>
                <li><a class="foobar" href="%(exist_url)s">This doc should exist, and its class should be left alone.</a></li>
                <li><a href="%(noexist_url)s#withanchor">This doc should NOT exist</a></li>
                <li><a href="%(noexist_url)s">This doc should NOT exist</a></li>
                <li><a href="%(noexist_url_with_base)s">This doc should NOT exist</a></li>
                <li><a href="%(noexist_url_with_base)s#withanchor">This doc should NOT exist</a></li>
                <li><a href="%(noexist_uilocale_url)s">This doc should NOT exist</a></li>
                <li><a class="foobar" href="%(noexist_url)s">This doc should NOT exist, and its class should be altered</a></li>
                <li><a href="http://mozilla.org/">This is an external link</a></li>
                <li><a class="foobar" name="quux">A lack of href should not cause a problem.</a></li>
                <li><a>In fact, a "link" with no attributes should be no problem as well.</a></li>
                <a href="%(tag_url)s">Tag link</a>
                <a href="%(feed_url)s">Feed link</a>
                <a href="%(templates_url)s">Templates link</a>
                <a href="/en-US/docs/DOM/stylesheet">Case sensitive 1</a>
                <a href="/en-US/docs/DOM/Stylesheet">Case sensitive 1</a>
                <a href="/en-US/docs/DOM/StyleSheet">Case sensitive 1</a>
                <a href="/en-us/docs/dom/StyleSheet">Case sensitive 1</a>
                <a href="/en-US/docs/dom/Styles">For good measure</a>
        """ % vars
        expected = u"""
                <li><a href="%(nonen_slug)s">Héritée</a></li>
                <li><a href="%(exist_url)s">This doc should exist</a></li>
                <li><a href="%(exist_url)s#withanchor">This doc should exist</a></li>
                <li><a href="%(exist_url_with_base)s">This doc should exist</a></li>
                <li><a href="%(exist_url_with_base)s#withanchor">This doc should exist</a></li>
                <li><a href="%(uilocale_url)s">This doc should exist</a></li>
                <li><a class="foobar" href="%(exist_url)s">This doc should exist, and its class should be left alone.</a></li>
                <li><a class="new" href="%(noexist_url)s#withanchor">This doc should NOT exist</a></li>
                <li><a class="new" href="%(noexist_url)s">This doc should NOT exist</a></li>
                <li><a class="new" href="%(noexist_url_with_base)s">This doc should NOT exist</a></li>
                <li><a class="new" href="%(noexist_url_with_base)s#withanchor">This doc should NOT exist</a></li>
                <li><a class="new" href="%(noexist_uilocale_url)s">This doc should NOT exist</a></li>
                <li><a class="foobar new" href="%(noexist_url)s">This doc should NOT exist, and its class should be altered</a></li>
                <li><a class="external" href="http://mozilla.org/">This is an external link</a></li>
                <li><a class="foobar" name="quux">A lack of href should not cause a problem.</a></li>
                <li><a>In fact, a "link" with no attributes should be no problem as well.</a></li>
                <a href="%(tag_url)s">Tag link</a>
                <a href="%(feed_url)s">Feed link</a>
                <a href="%(templates_url)s">Templates link</a>
                <a href="/en-US/docs/DOM/stylesheet">Case sensitive 1</a>
                <a href="/en-US/docs/DOM/Stylesheet">Case sensitive 1</a>
                <a href="/en-US/docs/DOM/StyleSheet">Case sensitive 1</a>
                <a href="/en-us/docs/dom/StyleSheet">Case sensitive 1</a>
                <a class="new" href="/en-US/docs/dom/Styles">For good measure</a>
        """ % vars

        # Split the markup into lines, to better see failures
        doc_lines = doc_src.strip().split("\n")
        expected_lines = expected.strip().split("\n")
        for idx in range(0, len(doc_lines)):
            doc_line = doc_lines[idx]
            expected_line = expected_lines[idx]
            result_line = (kuma.wiki.content.parse(doc_line)
                          .annotateLinks(base_url=vars['base_url'])
                          .serialize())
            eq_(normalize_html(expected_line), normalize_html(result_line))