Beispiel #1
0
 def test_pre_block_pre_text(self):
     """Don't treat pre blocks with pre-text differently."""
     a = '\n\n<pre>\nthis is `a\\_test` and this\\_too\n</pre>'
     b = 'hmm<pre>\nthis is `a\\_test` and this\\_too\n</pre>'
     self.assertEqual(
         gfm(a)[2:],
         gfm(b)[3:],
     )
Beispiel #2
0
 def test_pre_block_pre_text(self):
     """Don't treat pre blocks with pre-text differently."""
     a = '\n\n<pre>\nthis is `a\\_test` and this\\_too\n</pre>'
     b = 'hmm<pre>\nthis is `a\\_test` and this\\_too\n</pre>'
     self.assertEqual(
         gfm(a)[2:],
         gfm(b)[3:],
         )
Beispiel #3
0
 def test_two_underscores(self):
     """Escape two or more underscores inside words."""
     self.assertEqual(
         gfm('foo_bar_baz'),
         'foo\\_bar\\_baz',
     )
     self.assertEqual(
         gfm('something else then foo_bar_baz'),
         'something else then foo\\_bar\\_baz',
     )
Beispiel #4
0
 def test_two_underscores(self):
     """Escape two or more underscores inside words."""
     self.assertEqual(
         gfm('foo_bar_baz'),
         'foo\\_bar\\_baz',
         )
     self.assertEqual(
         gfm('something else then foo_bar_baz'),
         'something else then foo\\_bar\\_baz',
         )
Beispiel #5
0
 def test_underscores_code_blocks(self):
     """Don't touch underscores in code blocks."""
     self.assertEqual(
         gfm('    foo_bar_baz'),
         '    foo_bar_baz',
     )
     # Now with extra indentation
     self.assertEqual(
         gfm('        foo_bar_baz'),
         '        foo_bar_baz',
     )
Beispiel #6
0
 def test_underscores_code_blocks(self):
     """Don't touch underscores in code blocks."""
     self.assertEqual(
         gfm('    foo_bar_baz'),
         '    foo_bar_baz',
         )
     # Now with extra indentation
     self.assertEqual(
         gfm('        foo_bar_baz'),
         '        foo_bar_baz',
         )
Beispiel #7
0
    def test_gfm_code_blocks(self):
        """Turn ```code_blocks``` into 4-space indented code blocks."""
        # Without a syntax header
        self.assertEqual(
            gfm("```\nprint 'Hello'\n```"),
            "    print 'Hello'"
            )
        # With a syntax header
        self.assertEqual(
            gfm("```python\nprint 'Hello'\n```"),
            "    :::python\n    print 'Hello'"
            )
        # Embedded in some text
        self.assertEqual(gfm(
            "Some code:\n"
            "\n"
            "```python\n"
            "print 'Hello world'\n"
            "for x in range(10):\n"
            "    print x\n"
            "```\n"
            "\n"
            "Works?"),

            "Some code:\n"
            "\n"
            "    :::python\n"
            "    print 'Hello world'\n"
            "    for x in range(10):\n"
            "        print x\n"
            "\n"
            "Works?")

        # Embedded in some text, with \r\n line endings
        self.assertEqual(gfm(
            "Some code:\r\n"
            "\r\n"
            "```python\r\n"
            "print 'Hello world'\r\n"
            "for x in range(10):\r\n"
            "    print x\r\n"
            "```\r\n"
            "\r\n"
            "Works?"),

            "Some code:\r\n"
            "\r\n"
            "    :::python\r\n"
            "    print 'Hello world'\r\n"
            "    for x in range(10):\r\n"
            "        print x\r\n"
            "\r\n"
            "Works?")
Beispiel #8
0
 def test_newlines_list(self):
     """Don't convert newlines in lists."""
     self.assertEqual(
         gfm('# foo\n# bar'),
         '# foo\n# bar',
     )
     self.assertEqual(
         gfm('* foo\n* bar'),
         '* foo\n* bar',
     )
     self.assertEqual(
         gfm('+ foo\n+ bar'),
         '+ foo\n+ bar',
     )
     self.assertEqual(
         gfm('- foo\n- bar'),
         '- foo\n- bar',
     )
Beispiel #9
0
 def test_newlines_list(self):
     """Don't convert newlines in lists."""
     self.assertEqual(
         gfm('# foo\n# bar'),
         '# foo\n# bar',
         )
     self.assertEqual(
         gfm('* foo\n* bar'),
         '* foo\n* bar',
         )
     self.assertEqual(
         gfm('+ foo\n+ bar'),
         '+ foo\n+ bar',
         )
     self.assertEqual(
         gfm('- foo\n- bar'),
         '- foo\n- bar',
         )
Beispiel #10
0
    def test_gfm_code_blocks(self):
        """Turn ```code_blocks``` into 4-space indented code blocks."""
        # Without a syntax header
        self.assertEqual(gfm("```\nprint 'Hello'\n```"), "    print 'Hello'")
        # With a syntax header
        self.assertEqual(gfm("```python\nprint 'Hello'\n```"),
                         "    :::python\n    print 'Hello'")
        # Embedded in some text
        self.assertEqual(
            gfm("Some code:\n"
                "\n"
                "```python\n"
                "print 'Hello world'\n"
                "for x in range(10):\n"
                "    print x\n"
                "```\n"
                "\n"
                "Works?"), "Some code:\n"
            "\n"
            "    :::python\n"
            "    print 'Hello world'\n"
            "    for x in range(10):\n"
            "        print x\n"
            "\n"
            "Works?")

        # Embedded in some text, with \r\n line endings
        self.assertEqual(
            gfm("Some code:\r\n"
                "\r\n"
                "```python\r\n"
                "print 'Hello world'\r\n"
                "for x in range(10):\r\n"
                "    print x\r\n"
                "```\r\n"
                "\r\n"
                "Works?"), "Some code:\r\n"
            "\r\n"
            "    :::python\r\n"
            "    print 'Hello world'\r\n"
            "    for x in range(10):\r\n"
            "        print x\r\n"
            "\r\n"
            "Works?")
Beispiel #11
0
 def test_newlines_simple(self):
     """Turn newlines into br tags in simple cases."""
     self.assertEqual(
         gfm('foo\nbar'),
         'foo  \nbar',
     )
Beispiel #12
0
 def test_underscores_pre_blocks(self):
     """Don't touch underscores in pre blocks."""
     self.assertEqual(
         gfm('<pre>\nfoo_bar_baz\n</pre>'),
         '<pre>\nfoo_bar_baz\n</pre>',
         )
Beispiel #13
0
 def test_underscores_inline_code_blocks(self):
     """Don't touch underscores in code blocks."""
     self.assertEqual(
         gfm('foo `foo_bar_baz`'),
         'foo `foo_bar_baz`',
         )
Beispiel #14
0
 def test_underscores_in_html(self):
     """Don't replace underscores in HTML blocks"""
     self.assertEqual(gfm('<img src="http://example.com/a_b_c" />'),
                      '<img src="http://example.com/a_b_c" />')
Beispiel #15
0
 def test_linkify_naked_urls(self):
     """Wrap naked URLs in []() so they become clickable links."""
     self.assertEqual(
         gfm(" http://www.example.com:80/foo?bar=bar&biz=biz"),
         " [http://www.example.com:80/foo?bar=bar&biz=biz](http://www.example.com:80/foo?bar=bar&biz=biz)"
     )
Beispiel #16
0
 def test_linkify_naked_urls(self):
     """Wrap naked URLs in []() so they become clickable links."""
     self.assertEqual(
         gfm(" http://www.example.com:80/foo?bar=bar&biz=biz"),
         " [http://www.example.com:80/foo?bar=bar&biz=biz](http://www.example.com:80/foo?bar=bar&biz=biz)"
         )
Beispiel #17
0
 def test_underscores_in_html(self):
     """Don't replace underscores in HTML blocks"""
     self.assertEqual(
         gfm('<img src="http://example.com/a_b_c" />'),
         '<img src="http://example.com/a_b_c" />'
         )
Beispiel #18
0
 def test_newlines_list(self):
     """Don't convert newlines in lists."""
     self.assertEqual(gfm("# foo\n# bar"), "# foo\n# bar")
     self.assertEqual(gfm("* foo\n* bar"), "* foo\n* bar")
     self.assertEqual(gfm("+ foo\n+ bar"), "+ foo\n+ bar")
     self.assertEqual(gfm("- foo\n- bar"), "- foo\n- bar")
Beispiel #19
0
 def test_newlines_simple(self):
     """Turn newlines into br tags in simple cases."""
     self.assertEqual(
         gfm('foo\nbar'),
         'foo  \nbar',
         )
Beispiel #20
0
 def test_single_underscores(self):
     """Don't touch single underscores inside words."""
     self.assertEqual(
         gfm('foo_bar'),
         'foo_bar',
     )
Beispiel #21
0
 def test_underscores_inline_code_blocks(self):
     """Don't touch underscores in code blocks."""
     self.assertEqual(
         gfm('foo `foo_bar_baz`'),
         'foo `foo_bar_baz`',
     )
Beispiel #22
0
 def test_underscores_pre_blocks(self):
     """Don't touch underscores in pre blocks."""
     self.assertEqual(
         gfm('<pre>\nfoo_bar_baz\n</pre>'),
         '<pre>\nfoo_bar_baz\n</pre>',
     )
Beispiel #23
0
 def test_single_underscores(self):
     """Don't touch single underscores inside words."""
     self.assertEqual(
         gfm('foo_bar'),
         'foo_bar',
         )
Beispiel #24
0
 def test_newlines_long_group(self):
     """Convert newlines in even long groups."""
     self.assertEqual(
         gfm('apple\npear\norange\nbanana\n\nruby\npython\nerlang'),
         'apple  \npear  \norange  \nbanana\n\nruby  \npython  \nerlang',
     )
Beispiel #25
0
 def test_newlines_long_group(self):
     """Convert newlines in even long groups."""
     self.assertEqual(
         gfm('apple\npear\norange\nbanana\n\nruby\npython\nerlang'),
         'apple  \npear  \norange  \nbanana\n\nruby  \npython  \nerlang',
         )
Beispiel #26
0
 def test_underscores_urls(self):
     """Don't replace underscores in URLs"""
     self.assertEqual(gfm('[foo](http://example.com/a_b_c)'),
                      '[foo](http://example.com/a_b_c)')
Beispiel #27
0
 def test_underscores_urls(self):
     """Don't replace underscores in URLs"""
     self.assertEqual(
         gfm('[foo](http://example.com/a_b_c)'),
         '[foo](http://example.com/a_b_c)'
         )
Beispiel #28
0
 def test_newlines_group(self):
     """Convert newlines in all groups."""
     self.assertEqual(
         gfm("apple\npear\norange\n\nruby\npython\nerlang"), "apple  \npear  \norange\n\nruby  \npython  \nerlang"
     )