Esempio n. 1
0
 def test_add_heading_ids(self):
     dialect = create_dialect(creole10_base, add_heading_ids=True)
     parse = Parser(dialect)
     self.assertEquals(
         parse("== Level 2"),
         '<h2 id="!level-2">Level 2</h2>\n')
     self.assertEquals(
         parse("= Level 1\n= Level 1"),
         '<h1 id="!level-1">Level 1</h1>\n<h1 id="!level-1_1">Level 1</h1>\n')
     self.assertEquals(
         parse("= [[http://www.google.com|Google]]\n"),
         """<h1 id="!google"><a href="http://www.google.com">Google</a></h1>\n""")
     self.assertEquals(
         parse("== http://www.google.com\n"),
         """<h2 id="!http-www-google-com"><a href="http://www.google.com">http://www.google.com</a></h2>\n""")
     self.assertEquals(
         parse("== ~http://www.google.com\n"),
         '<h2 id="!http-www-google-com">http://www.google.com</h2>\n')
     self.assertEquals(
         parse("[[foo bar#!a-heading_1]]"),
         wrap_result("""<a href="foo_bar#!a-heading_1">foo bar#!a-heading_1</a>"""))
     self.assertEquals(
         parse("[[#!a-heading]]"),
         wrap_result("""<a href="#!a-heading">#!a-heading</a>"""))
     self.assertEquals(
         parse("[[foo bar#1]]"),
         wrap_result("""<a href="foo_bar%231">foo bar#1</a>"""))
     self.assertEquals(
         parse("[[#1]]"),
         wrap_result("""<a href="%231">#1</a>"""))
     dialect = create_dialect(creole10_base, add_heading_ids='')
     parse = Parser(dialect)
     self.assertEquals(
         parse("== Level 2"),
         '<h2 id="level-2">Level 2</h2>\n')
Esempio n. 2
0
 def test_add_heading_ids(self):
     dialect = create_dialect(creole10_base, add_heading_ids=True)
     parse = Parser(dialect)
     self.assertEquals(parse("== Level 2"), '<h2 id="!level-2">Level 2</h2>\n')
     self.assertEquals(
         parse("= Level 1\n= Level 1"), '<h1 id="!level-1">Level 1</h1>\n<h1 id="!level-1_1">Level 1</h1>\n'
     )
     self.assertEquals(
         parse("= [[http://www.google.com|Google]]\n"),
         """<h1 id="!google"><a href="http://www.google.com">Google</a></h1>\n""",
     )
     self.assertEquals(
         parse("== http://www.google.com\n"),
         """<h2 id="!http-www-google-com"><a href="http://www.google.com">http://www.google.com</a></h2>\n""",
     )
     self.assertEquals(
         parse("== ~http://www.google.com\n"), '<h2 id="!http-www-google-com">http://www.google.com</h2>\n'
     )
     self.assertEquals(
         parse("[[foo bar#!a-heading_1]]"),
         wrap_result("""<a href="foo_bar#!a-heading_1">foo bar#!a-heading_1</a>"""),
     )
     self.assertEquals(parse("[[#!a-heading]]"), wrap_result("""<a href="#!a-heading">#!a-heading</a>"""))
     self.assertEquals(parse("[[foo bar#1]]"), wrap_result("""<a href="foo_bar%231">foo bar#1</a>"""))
     self.assertEquals(parse("[[#1]]"), wrap_result("""<a href="%231">#1</a>"""))
     dialect = create_dialect(creole10_base, add_heading_ids="")
     parse = Parser(dialect)
     self.assertEquals(parse("== Level 2"), '<h2 id="level-2">Level 2</h2>\n')
Esempio n. 3
0
 def setUp(self):
     dialect = create_dialect(creole11_base,
         wiki_links_base_url='http://creoleparser.x10hosting.com/cgi-bin/creolepiki/',
         wiki_links_space_char='',
         no_wiki_monospace=False,
         macro_func=self.macroFactory)
     self.parse = Parser(dialect)
Esempio n. 4
0
    def setUp(self):
        def inter_wiki_link_maker(name):
            return name[::-1]

        def simple_class_maker(name):
            return name.lower()

        functions = {
            'moo':inter_wiki_link_maker,
            'goo':inter_wiki_link_maker,
            }
        base_urls = {
            'goo': 'http://example.org',
            'poo': 'http://example.org',
            'Ohana': inter_wiki_url,
            }
        space_characters = {
            'goo': '+',
            'poo': '+',
            }

        class_functions = {
            'moo':simple_class_maker,
            'goo':simple_class_maker,
            }

        dialect = create_dialect(creole10_base,
            interwiki_links_path_funcs=functions,
            interwiki_links_class_funcs=class_functions,
            interwiki_links_base_urls=base_urls,
            interwiki_links_space_chars=space_characters
            )

        self.parse = Parser(dialect)
Esempio n. 5
0
    def test_bodied_macros_option(self):
        def red(macro, e, *args, **kw):
            return builder.tag.__getattr__(macro.isblock and "div" or "span")(macro.parsed_body(), style="color:red")

        red.parse_body = True
        # return {'style':'color:red'}
        def blockquote(macro, e, *args, **kw):
            return builder.tag.blockquote(macro.parsed_body())

        blockquote.parse_body = True
        # return {'tag':'blockquote'}
        MyDialect = create_dialect(creole11_base, bodied_macros=dict(red=red, blockquote=blockquote))
        parse = Parser(MyDialect)
        self.assertEquals(
            parse("This block of <<red>>text **should** be monospace<</red>> now"),
            wrap_result('This block of <span style="color:red">text <strong>should</strong> be monospace</span> now'),
        )
        self.assertEquals(
            parse("<<red>>\ntext **should** be monospace\n<</red>>"),
            '<div style="color:red"><p>text <strong>should</strong> be monospace</p>\n</div>',
        )
        self.assertEquals(
            parse("This block of <<blockquote>>text **should** be monospace<</blockquote>> now"),
            wrap_result("This block of </p><blockquote>text <strong>should</strong> be monospace</blockquote><p> now"),
        )
        self.assertEquals(
            parse("<<blockquote>>\ntext **should** be monospace\n<</blockquote>>"),
            "<blockquote><p>text <strong>should</strong> be monospace</p>\n</blockquote>",
        )
Esempio n. 6
0
 def test_simple_markup_option(self):
     MyDialect = create_dialect(creole10_base, simple_markup=[("*", "strong"), ("#", "code")])
     parse = Parser(MyDialect)
     self.assertEquals(
         parse("This block of #text *should* be monospace# now"),
         wrap_result("This block of <code>text <strong>should</strong> be monospace</code> now"),
     )
Esempio n. 7
0
    def setUp(self):
        def inter_wiki_link_maker(name):
            return name[::-1]

        def simple_class_maker(name):
            return name.lower()

        functions = {
            'moo':inter_wiki_link_maker,
            'goo':inter_wiki_link_maker,
            }
        base_urls = {
            'goo': 'http://example.org',
            'poo': 'http://example.org',
            'Ohana': inter_wiki_url,
            }
        space_characters = {
            'goo': '+',
            'poo': '+',
            }

        class_functions = {
            'moo':simple_class_maker,
            'goo':simple_class_maker,
            }

        dialect = create_dialect(creole10_base,
            interwiki_links_path_funcs=functions,
            interwiki_links_class_funcs=class_functions,
            interwiki_links_base_urls=base_urls,
            interwiki_links_space_chars=space_characters
            )

        self.parse = Parser(dialect)
Esempio n. 8
0
 def test_use_additions_option(self):
     dialect = create_dialect(creole11_base)  # , use_additions=True)
     parse = Parser(dialect)
     self.assertEquals(
         parse("This block of ##text **should** be monospace## now"),
         wrap_result("This block of <code>text <strong>should</strong> be monospace</code> now"),
     )
Esempio n. 9
0
 def test_no_wiki_monospace_option(self):
     dialect = create_dialect(creole10_base, no_wiki_monospace=True)
     parse = Parser(dialect)
     self.assertEquals(
         parse("This block of {{{no_wiki **shouldn't** be monospace}}} now"),
         wrap_result("This block of <code>no_wiki **shouldn't** be monospace</code> now"),
     )
Esempio n. 10
0
 def setUp(self):
     dialect = create_dialect(creole11_base,
         wiki_links_base_url='',
         wiki_links_space_char='_',
         interwiki_links_base_urls={'Ohana': inter_wiki_url},
         no_wiki_monospace=False,
         macro_func=self.macroFactory)
     self.parse = Parser(dialect)
Esempio n. 11
0
 def setUp(self):
     self.parse = Parser(
     dialect=create_dialect(creole11_base,
     wiki_links_base_url='',
     interwiki_links_base_urls={'Ohana': inter_wiki_url},
     #use_additions=True,
     no_wiki_monospace=False
        )
     )
Esempio n. 12
0
 def setUp(self):
     self.parse = Parser(
     dialect=create_dialect(creole11_base,
     wiki_links_base_url='',
     interwiki_links_base_urls={'Ohana': inter_wiki_url},
     #use_additions=True,
     no_wiki_monospace=False
        )
     )
Esempio n. 13
0
 def test_blog_style_endings_option(self):
     dialect = create_dialect(creole10_base, blog_style_endings=True)
     parse = Parser(dialect)
     self.assertEquals(
         parse("The first line\nthis text **should** be on the second line\n now third"),
         wrap_result("The first line<br />this text <strong>should</strong> be on the second line<br /> now third"))
     self.assertEquals(
         parse("The first line\\\\\nthis text **should** be on the second line\\\\\n now third"),
         wrap_result("The first line<br />this text <strong>should</strong> be on the second line<br /> now third"))
Esempio n. 14
0
 def test_blog_style_endings_option(self):
     dialect = create_dialect(creole10_base, blog_style_endings=True)
     parse = Parser(dialect)
     self.assertEquals(
         parse("The first line\nthis text **should** be on the second line\n now third"),
         wrap_result("The first line<br />this text <strong>should</strong> be on the second line<br /> now third"))
     self.assertEquals(
         parse("The first line\\\\\nthis text **should** be on the second line\\\\\n now third"),
         wrap_result("The first line<br />this text <strong>should</strong> be on the second line<br /> now third"))
Esempio n. 15
0
 def setUp(self):
     creole2html = Parser(
         dialect=create_dialect(creole10_base,
             wiki_links_base_url=base_url,
             interwiki_links_base_urls={'Ohana': inter_wiki_url},
             #use_additions=False,
             no_wiki_monospace=True,
             )
         )
     self.parse = creole2html
Esempio n. 16
0
 def setUp(self):
     creole2html = Parser(
         dialect=create_dialect(creole10_base,
             wiki_links_base_url=base_url,
             interwiki_links_base_urls={'Ohana': inter_wiki_url},
             #use_additions=False,
             no_wiki_monospace=True
             )
         )
     self.parse = creole2html
Esempio n. 17
0
 def setUp(self):
     dialect = create_dialect(creole11_base,
         wiki_links_base_url='',
         wiki_links_space_char='_',
         interwiki_links_base_urls={'Ohana': inter_wiki_url},
         no_wiki_monospace=False,
         macro_func=self.macroFactory,
         bodied_macros=dict(span=self.span, div=self.div),
         non_bodied_macros=dict(luca=self.luca),                                 
                              )
     self.parse = Parser(dialect)
Esempio n. 18
0
 def setUp(self):
     dialect = create_dialect(creole11_base,
         wiki_links_base_url='',
         wiki_links_space_char='_',
         interwiki_links_base_urls={'Ohana': inter_wiki_url},
         no_wiki_monospace=False,
         macro_func=self.macroFactory,
         bodied_macros=dict(span=self.span, div=self.div),
         non_bodied_macros=dict(luca=self.luca),                                 
                              )
     self.parse = Parser(dialect)
Esempio n. 19
0
 def test_external_links_class_option(self):
     dialect = create_dialect(creole10_base, external_links_class='external')
     parse = Parser(dialect)
     self.assertEquals(
         parse("[[campfire.jpg]]"),
         wrap_result("""<a href="campfire.jpg">campfire.jpg</a>"""))
     self.assertEquals(
         parse("[[/campfire.jpg]]"),
         wrap_result("""<a class="external" href="/campfire.jpg">/campfire.jpg</a>"""))
     self.assertEquals(
         parse("[[http://www.somesite.com/campfire.jpg]]"),
         wrap_result("""<a class="external" href="http://www.somesite.com/campfire.jpg">http://www.somesite.com/campfire.jpg</a>"""))
Esempio n. 20
0
 def test_image_link_options(self):
     dialect = create_dialect(
         creole10_base,
         wiki_links_base_url=["/pages/", "/files/"],
         wiki_links_space_char=["_", " "],
         wiki_links_path_func=[lambda s: s.upper(), lambda s: s.capitalize()],
     )
     parse = Parser(dialect)
     self.assertEquals(parse("[[foo bar]]"), wrap_result("""<a href="/pages/FOO_BAR">foo bar</a>"""))
     self.assertEquals(
         parse("{{foo bar}}"), wrap_result("""<img src="/files/Foo bar" alt="foo bar" title="foo bar" />""")
     )
Esempio n. 21
0
 def test_interwiki_image_link_options(self):
     dialect = create_dialect(
         creole10_base,
         interwiki_links_base_urls={"a": ["/pages/", "/files/"]},
         interwiki_links_space_chars={"a": ["_", " "]},
         interwiki_links_path_funcs={"a": [lambda s: s.upper(), lambda s: s.capitalize()]},
     )
     parse = Parser(dialect)
     self.assertEquals(parse("[[a:foo bar|Foo]]"), wrap_result("""<a href="/pages/FOO_BAR">Foo</a>"""))
     self.assertEquals(
         parse("{{a:foo bar|Foo}}"), wrap_result("""<img src="/files/Foo bar" alt="Foo" title="Foo" />""")
     )
Esempio n. 22
0
 def test_disable_external_content(self):
     dialect = create_dialect(creole10_base, disable_external_content=True)
     parse = Parser(dialect)
     self.assertEquals(
         parse("{{campfire.jpg}}"),
         wrap_result("""<img src="campfire.jpg" alt="campfire.jpg" title="campfire.jpg" />"""))
     self.assertEquals(
         parse("{{/campfire.jpg}}"),
         wrap_result("""<span class="external_image">External images are disabled</span>"""))
     self.assertEquals(
         parse("{{http://www.somesite.com/campfire.jpg}}"),
         wrap_result("""<span class="external_image">External images are disabled</span>"""))
Esempio n. 23
0
 def setUp(self):
     noSpaces = Parser(
         dialect=create_dialect(creole11_base,
             wiki_links_base_url=base_url,
             wiki_links_space_char='',
             interwiki_links_base_urls={'Ohana': inter_wiki_url},
             no_wiki_monospace=False,
             wiki_links_class_func=class_name_function,
             wiki_links_path_func=path_name_function
             )
         )
     self.parse = noSpaces
Esempio n. 24
0
 def setUp(self):
     noSpaces = Parser(
         dialect=create_dialect(creole11_base,
             wiki_links_base_url=base_url,
             wiki_links_space_char='',
             interwiki_links_base_urls={'Ohana': inter_wiki_url},
             no_wiki_monospace=False,
             wiki_links_class_func=class_name_function,
             wiki_links_path_func=path_name_function
             )
         )
     self.parse = noSpaces
Esempio n. 25
0
 def setUp(self):
     noSpaces = Parser(
         dialect=create_dialect(
             wiki_links_base_url=base_url,
             wiki_links_space_char='',
             use_additions=True,
             no_wiki_monospace=False,
             wiki_links_class_func=class_name_function,
             wiki_links_path_func=path_name_function
             )
         )
     self.parse = noSpaces
Esempio n. 26
0
 def test_disable_external_content(self):
     dialect = create_dialect(creole10_base, disable_external_content=True)
     parse = Parser(dialect)
     self.assertEquals(
         parse("{{campfire.jpg}}"),
         wrap_result("""<img src="campfire.jpg" alt="campfire.jpg" title="campfire.jpg" />"""))
     self.assertEquals(
         parse("{{/campfire.jpg}}"),
         wrap_result("""<span class="external_image">External images are disabled</span>"""))
     self.assertEquals(
         parse("{{http://www.somesite.com/campfire.jpg}}"),
         wrap_result("""<span class="external_image">External images are disabled</span>"""))
Esempio n. 27
0
 def test_external_links_class_option(self):
     dialect = create_dialect(creole10_base, external_links_class='external')
     parse = Parser(dialect)
     self.assertEquals(
         parse("[[campfire.jpg]]"),
         wrap_result("""<a href="campfire.jpg">campfire.jpg</a>"""))
     self.assertEquals(
         parse("[[/campfire.jpg]]"),
         wrap_result("""<a class="external" href="/campfire.jpg">/campfire.jpg</a>"""))
     self.assertEquals(
         parse("[[http://www.somesite.com/campfire.jpg]]"),
         wrap_result("""<a class="external" href="http://www.somesite.com/campfire.jpg">http://www.somesite.com/campfire.jpg</a>"""))
Esempio n. 28
0
 def test_image_link_options(self):
     dialect = create_dialect(creole10_base, wiki_links_base_url=['/pages/',
                                                                  '/files/'],
                              wiki_links_space_char=['_',' '],
                              wiki_links_path_func=[lambda s:s.upper(),
                                                    lambda s:s.capitalize()])
     parse = Parser(dialect)
     self.assertEquals(
         parse("[[foo bar]]"),
         wrap_result("""<a href="/pages/FOO_BAR">foo bar</a>"""))
     self.assertEquals(
         parse("{{foo bar}}"),
         wrap_result("""<img src="/files/Foo bar" alt="foo bar" title="foo bar" />"""))
Esempio n. 29
0
 def test_custom_markup_option(self):
     def wikiword(mo, e):
         return builder.tag.a(mo.group(1),href=mo.group(1))
     dialect = create_dialect(creole10_base,
                              custom_markup=[('(c)','&copy;'),
                                             (re.compile(esc_neg_look + r'\b([A-Z]\w+[A-Z]+\w+)'),wikiword)])
     parse = Parser(dialect)
     self.assertEquals(
         parse("The copyright symbol (c), escaped ~(c)"),
         wrap_result("The copyright symbol &copy;, escaped (c)"))
     self.assertEquals(
         parse("A WikiPage name that is a ~WikiWord"),
         wrap_result('A <a href="WikiPage">WikiPage</a> name that is a WikiWord'))
Esempio n. 30
0
 def test_interwiki_image_link_options(self):
     dialect = create_dialect(creole10_base,
                              interwiki_links_base_urls={'a': ['/pages/','/files/']},
                              interwiki_links_space_chars={'a': ['_',' ']},
                              interwiki_links_path_funcs={'a': [lambda s:s.upper(),
                                                                 lambda s:s.capitalize()]})
     parse = Parser(dialect)
     self.assertEquals(
         parse("[[a:foo bar|Foo]]"),
         wrap_result("""<a href="/pages/FOO_BAR">Foo</a>"""))
     self.assertEquals(
         parse("{{a:foo bar|Foo}}"),
         wrap_result("""<img src="/files/Foo bar" alt="Foo" title="Foo" />"""))
Esempio n. 31
0
 def test_custom_markup_option(self):
     def wikiword(mo, e):
         return builder.tag.a(mo.group(1),href=mo.group(1))
     dialect = create_dialect(creole10_base,
                              custom_markup=[('(c)','&copy;'),
                                             (re.compile(esc_neg_look + r'\b([A-Z]\w+[A-Z]+\w+)'),wikiword)])
     parse = Parser(dialect)
     self.assertEquals(
         parse("The copyright symbol (c), escaped ~(c)"),
         wrap_result("The copyright symbol &copy;, escaped (c)"))
     self.assertEquals(
         parse("A WikiPage name that is a ~WikiWord"),
         wrap_result('A <a href="WikiPage">WikiPage</a> name that is a WikiWord'))
Esempio n. 32
0
    def setUp(self):
        def inter_wiki_link_maker(name):
            return name[::-1]

        def simple_class_maker(name):
            return name.lower()

        functions = {"moo": inter_wiki_link_maker, "goo": inter_wiki_link_maker}
        base_urls = {"goo": "http://example.org", "poo": "http://example.org", "Ohana": inter_wiki_url}
        space_characters = {"goo": "+", "poo": "+"}

        class_functions = {"moo": simple_class_maker, "goo": simple_class_maker}

        dialect = create_dialect(
            creole10_base,
            interwiki_links_path_funcs=functions,
            interwiki_links_class_funcs=class_functions,
            interwiki_links_base_urls=base_urls,
            interwiki_links_space_chars=space_characters,
        )

        self.parse = Parser(dialect)
Esempio n. 33
0
    def setUp(self):
        def inter_wiki_link_maker(name):
            return name[::-1]

        functions = {
            'moo':inter_wiki_link_maker,
            'goo':inter_wiki_link_maker,
            }
        base_urls = {
            'goo': 'http://example.org',
            'poo': 'http://example.org',
            }
        space_characters = {
            'goo': '+',
            'poo': '+',
            }

        dialect = create_dialect(
            interwiki_links_funcs=functions,
            interwiki_links_base_urls=base_urls,
            interwiki_links_space_chars=space_characters
            )

        self.parse = Parser(dialect)
Esempio n. 34
0
 def test_bodied_macros_option(self):
     def red(macro,e,*args,**kw):
         return builder.tag.__getattr__(macro.isblock and 'div' or 'span')(
             macro.parsed_body(),style='color:red')
     red.parse_body = True
         #return {'style':'color:red'}
     def blockquote(macro,e,*args,**kw):
         return builder.tag.blockquote(macro.parsed_body())
     blockquote.parse_body = True
         #return {'tag':'blockquote'}
     MyDialect = create_dialect(creole11_base, bodied_macros=dict(red=red, blockquote=blockquote))
     parse = Parser(MyDialect)
     self.assertEquals(
         parse("This block of <<red>>text **should** be monospace<</red>> now"),
         wrap_result('This block of <span style="color:red">text <strong>should</strong> be monospace</span> now'))
     self.assertEquals(
         parse("<<red>>\ntext **should** be monospace\n<</red>>"),
         '<div style="color:red"><p>text <strong>should</strong> be monospace</p>\n</div>')
     self.assertEquals(
         parse("This block of <<blockquote>>text **should** be monospace<</blockquote>> now"),
         wrap_result('This block of </p><blockquote>text <strong>should</strong> be monospace</blockquote><p> now'))
     self.assertEquals(
         parse("<<blockquote>>\ntext **should** be monospace\n<</blockquote>>"),
         '<blockquote><p>text <strong>should</strong> be monospace</p>\n</blockquote>')
Esempio n. 35
0
#
# This module is part of Creoleparser and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
#
import string
import keyword

from core import Parser, ArgParser
from dialects import (creole11_base, creole10_base, creepy10_base,
                      create_dialect)

__docformat__ = 'restructuredtext en'

__version__ = '0.7.2'

creole2html = Parser(dialect=create_dialect(creole10_base), method='html')
"""This is a pure Creole 1.0 parser created for convenience"""

text2html = Parser(dialect=create_dialect(creole11_base), method='html')
"""This is a Creole 1.0 parser (+ additions) created for convenience"""

parse_args = ArgParser(
    dialect=creepy10_base(),
    key_func=string.lower,
    illegal_keys=keyword.kwlist +
    ['macro_name', 'arg_string', 'body', 'isblock', 'environ', 'macro'])
"""Function for parsing macro arg_strings using a relaxed xml style"""


def _test():
    import doctest
Esempio n. 36
0
 def test_wiki_links_base_url_option(self):
     dialect = create_dialect(creole10_base, wiki_links_base_url='http://www.example.com')
     parse = Parser(dialect)
     self.assertEquals(
         parse("[[foobar]]"),
         wrap_result("""<a href="http://www.example.com/foobar">foobar</a>"""))
macros = {'include':include,
          'include-raw':include_raw,
          'include-source':include_source,
          'source':source,
          'pre':pre
          }

def macro_dispatcher(macro_name,arg_string,body,isblock,environ):
    if macro_name in macros:
        return macros[macro_name](arg_string,body,isblock)
    
dialect = dialects.create_dialect(dialects.creole11_base,
    wiki_links_base_url='http://creoleparser.srcom.org/cgi-bin/creolepiki/',
    wiki_links_space_char='',
#    use_additions=True,
    no_wiki_monospace=False,
    wiki_links_class_func=class_func,
    wiki_links_path_func=path_func,
    macro_func=macro_dispatcher)

text2html = core.Parser(dialect)


if __name__ == '__main__':
    
    text = Page('CheatSheetPlus').get_raw_body()
    f = open(os.path.join('test_pages','CheatSheetPlus.html'),'r')
    rendered = f.read()
    f.close()
    f = open(os.path.join('test_pages','template.html'),'r')
    template = f.read()
Esempio n. 38
0
 def test_no_wiki_monospace_option(self):
     dialect = create_dialect(creole10_base, no_wiki_monospace=True)
     parse = Parser(dialect)
     self.assertEquals(
         parse("This block of {{{no_wiki **shouldn't** be monospace}}} now"),
         wrap_result("This block of <code>no_wiki **shouldn't** be monospace</code> now"))
Esempio n. 39
0
 def test_use_additions_option(self):
     dialect = create_dialect(creole11_base) #, use_additions=True)
     parse = Parser(dialect)
     self.assertEquals(
         parse("This block of ##text **should** be monospace## now"),
         wrap_result("This block of <code>text <strong>should</strong> be monospace</code> now"))
Esempio n. 40
0
 def test_wiki_links_base_url_option(self):
     dialect = create_dialect(creole10_base, wiki_links_base_url='http://www.example.com')
     parse = Parser(dialect)
     self.assertEquals(
         parse("[[foobar]]"),
         wrap_result("""<a href="http://www.example.com/foobar">foobar</a>"""))
Esempio n. 41
0
 def test_simple_markup_option(self):
     MyDialect = create_dialect(creole10_base, simple_markup=[('*','strong'),('#','code')])
     parse = Parser(MyDialect)
     self.assertEquals(
         parse("This block of #text *should* be monospace# now"),
         wrap_result("This block of <code>text <strong>should</strong> be monospace</code> now"))
Esempio n. 42
0
        return 'nonexistent'


def path_name_function(page_name):
    if page_name == 'ThisPageHere':
        path = 'Special/ThisPageHere'
    else:
        path = urllib.quote(page_name.encode('utf-8'))
    return path



text2html = Parser(
    dialect=create_dialect(
        wiki_links_base_url=base_url,
        interwiki_links_base_urls={'Ohana': inter_wiki_url},
        use_additions=True,
        no_wiki_monospace=False
        )
    )


def wrap_result(expected):
    return "<p>%s</p>\n" % expected


        
class BaseTest(object):
    """

    """
    parse = lambda x: None
Esempio n. 43
0
        return 'nonexistent'


def path_name_function(page_name):
    if page_name == 'ThisPageHere':
        path = 'Special/ThisPageHere'
    else:
        path = urllib.quote(page_name.encode('utf-8'))
    return path



text2html = Parser(
    dialect=create_dialect(creole11_base,
        wiki_links_base_url=base_url,
        interwiki_links_base_urls={'Ohana': inter_wiki_url},
        no_wiki_monospace=False
        )
    )


def wrap_result(expected):
    return "<p>%s</p>\n" % expected


        
class BaseTest(object):
    """

    """
    #parse = lambda x: None
macros = {'include':include,
          'include-raw':include_raw,
          'include-source':include_source,
          'source':source,
          'pre':pre
          }

def macro_dispatcher(macro_name,arg_string,body,isblock,environ):
    if macro_name in macros:
        return macros[macro_name](arg_string,body,isblock)
    
dialect = dialects.create_dialect(dialects.creole11_base,
    wiki_links_base_url='',
    wiki_links_space_char='',
#    use_additions=True,
    no_wiki_monospace=False,
    wiki_links_class_func=class_func,
    wiki_links_path_func=path_func,
    macro_func=macro_dispatcher)

text2html = core.Parser(dialect)


if __name__ == '__main__':
    
    text = Page('CheatSheetPlus').get_raw_body()
    f = open(os.path.join('test_pages','CheatSheetPlus.html'),'r')
    rendered = f.read()
    f.close()
    f = open(os.path.join('test_pages','template.html'),'r')
    template = f.read()
Esempio n. 45
0
#
# This module is part of Creoleparser and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
#
import string
import keyword

from core import Parser, ArgParser
from dialects import (creole11_base, creole10_base, creepy10_base,
                    create_dialect, parse_args)

__docformat__ = 'restructuredtext en'

__version__ = '0.7.4'

creole2html = Parser(dialect=create_dialect(creole10_base), method='html')
"""This is a pure Creole 1.0 parser created for convenience"""

text2html = Parser(dialect=create_dialect(creole11_base), method='html')
"""This is a Creole 1.0 parser (+ additions) created for convenience"""

#parse_args = ArgParser(dialect=creepy10_base(),key_func=string.lower,
#                       illegal_keys=keyword.kwlist + ['macro_name',
#                         'arg_string', 'body', 'isblock', 'environ', 'macro'])
#"""Function for parsing macro arg_strings using a relaxed xml style"""

def _test():
    import doctest
    doctest.testmod()

if __name__ == "__main__":
Esempio n. 46
0
        return 'nonexistent'


def path_name_function(page_name):
    if page_name == 'ThisPageHere':
        path = 'Special/ThisPageHere'
    else:
        path = urllib.quote(page_name.encode('utf-8'))
    return path



text2html = Parser(
    dialect=create_dialect(creole11_base,
        wiki_links_base_url=base_url,
        interwiki_links_base_urls={'Ohana': inter_wiki_url},
        no_wiki_monospace=False
        )
    )


def wrap_result(expected):
    return "<p>%s</p>\n" % expected


        
class BaseTest(object):
    """

    """
    #parse = lambda x: None