How to use the creoleparser.creole10_base function in Creoleparser

To help you get started, we’ve selected a few Creoleparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mitsuhiko / solace / solace / utils / formatting.py View on Github external
import creoleparser
from difflib import SequenceMatcher
from operator import itemgetter
from itertools import chain
from genshi.core import Stream, QName, Attrs, START, END, TEXT
from contextlib import contextmanager

from jinja2 import Markup


_leading_space_re = re.compile(r'^(\s+)(?u)')
_diff_split_re = re.compile(r'(\s+)(?u)')


_parser = creoleparser.Parser(
    dialect=creoleparser.create_dialect(creoleparser.creole10_base),
    method='html'
)


def format_creole(text, inline=False):
    """Format creole markup."""
    kwargs = {}
    if inline:
        kwargs['context'] = 'inline'
    return Markup(_parser.render(text, encoding=None, **kwargs))


def format_creole_diff(old, new):
    """Renders a creole diff for two texts."""
    differ = StreamDiffer(_parser.generate(old),
                          _parser.generate(new))
github pallets / werkzeug / examples / simplewiki / utils.py View on Github external
TEMPLATE_PATH = path.join(path.dirname(__file__), 'templates')
template_loader = TemplateLoader(TEMPLATE_PATH, auto_reload=True,
                                 variable_lookup='lenient')


# context locals.  these two objects are use by the application to
# bind objects to the current context.  A context is defined as the
# current thread and the current greenlet if there is greenlet support.
local = Local()
local_manager = LocalManager([local])
request = local('request')
application = local('application')

# create a new creole parser
creole_parser = creoleparser.Parser(
    dialect=creoleparser.create_dialect(creoleparser.creole10_base,
        wiki_links_base_url='',
        wiki_links_path_func=lambda page_name: href(page_name),
        wiki_links_space_char='_',
        no_wiki_monospace=True
    ),
    method='html'
)


def generate_template(template_name, **context):
    """Load and generate a template."""
    context.update(
        href=href,
        format_datetime=format_datetime
    )
    return template_loader.load(template_name).generate(**context)