def creole(value, default_prefix=None): try: from creoleparser.core import Parser from creoleparser.dialects import create_dialect, creole11_base except ImportError: if settings.TEMPLATE_DEBUG: raise template.TemplateSyntaxError, "Error in {% creole %} filter: The Python creoleparser library isn't installed." return value else: __prepare_global_data_structures() default_prefix = default_prefix or u'en' parser_kwargs = { 'wiki_links_base_url': '/%s/' % default_prefix, 'no_wiki_monospace': True, 'wiki_links_path_func': __interwiki_links_path_funcs[default_prefix], 'wiki_links_class_func': __wiki_links_class_func(default_prefix), 'interwiki_links_base_urls': __interwiki_links_base_urls, # on the next line, we copy the dict first because creoleparser's # create_dialect function modifies it inexplicably! (see # creoleparser issue #50) 'interwiki_links_path_funcs': dict(__interwiki_links_path_funcs), 'interwiki_links_class_funcs': __interwiki_links_class_funcs, 'external_links_class': 'external', 'disable_external_content': True, 'bodied_macros': __bodied_macros, 'non_bodied_macros': __non_bodied_macros, } creole2html = Parser(create_dialect(creole11_base, **parser_kwargs), encoding=None) return mark_safe(creole2html(value))
""" The hot lead that formats pages to whatever we like. This is here in its own module because we want to a) be able to test it nice like (even though we don't yet) b) work out ways to have the format() method come from multiple places, if we don't want creole or what have you """ from creoleparser.dialects import Creole10 from creoleparser.core import Parser # FIXME: this url should come from config!!! dialect = Creole10( wiki_links_base_url='/content/name/', wiki_links_space_char=' ' ) parser = Parser( dialect=dialect ) def format(content): """Turn creole text into html. For the time being does not support CamelCase. This should be fixed.""" return parser(content)