示例#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:],
     )
示例#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:],
         )
示例#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',
     )
示例#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',
         )
示例#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',
     )
示例#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',
         )
示例#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?")
示例#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',
     )
示例#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',
         )
示例#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?")
示例#11
0
 def test_newlines_simple(self):
     """Turn newlines into br tags in simple cases."""
     self.assertEqual(
         gfm('foo\nbar'),
         'foo  \nbar',
     )
示例#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>',
         )
示例#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`',
         )
示例#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" />')
示例#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)"
     )
示例#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)"
         )
示例#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" />'
         )
示例#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")
示例#19
0
 def test_newlines_simple(self):
     """Turn newlines into br tags in simple cases."""
     self.assertEqual(
         gfm('foo\nbar'),
         'foo  \nbar',
         )
示例#20
0
 def test_single_underscores(self):
     """Don't touch single underscores inside words."""
     self.assertEqual(
         gfm('foo_bar'),
         'foo_bar',
     )
示例#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`',
     )
示例#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>',
     )
示例#23
0
 def test_single_underscores(self):
     """Don't touch single underscores inside words."""
     self.assertEqual(
         gfm('foo_bar'),
         'foo_bar',
         )
示例#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',
     )
示例#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',
         )
示例#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)')
示例#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)'
         )
示例#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"
     )