How to use the creoleparser.Parser 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 re
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),
github pallets / werkzeug / examples / simplewiki / utils.py View on Github external
# calculate the path to the templates an create the template loader
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
    )
github prologic / sahriswiki / sahriswiki / env.py View on Github external
echo=(self.config.get("debug") and self.config.get("verbose")),
        ).register(self)

        self.storage = DefaultStorage(
            self.config,
            self.config.get("repo"),
            charset=self.config.get("encoding"),
        )

        self.search = WikiSearch(
            self.dbm.session,
            self.config.get("language"),
            self.storage,
        )

        self.parser = Parser(
            create_dialect(
                creole11_base,
                macro_func=macros.dispatcher,
                wiki_links_base_url="/",
                wiki_links_class_func=self._wiki_links_class_func,
                wiki_links_path_func=self._wiki_links_path_func,
            ),
            method="xhtml"
        )

        template_config = {
            "allow_exec": False,
            "auto_reload": True,
            "default_encoding": self.config.get("encoding"),
            "search_path": [
                self.storage.path,
github circuits / circuits / examples / web / wiki / wiki.py View on Github external
#!/usr/bin/env python
import os
import sqlite3

import macros
from creoleparser import Parser, create_dialect, creole11_base

import circuits
from circuits.web import Controller, Logger, Server, Static

text2html = Parser(
    create_dialect(creole11_base, macro_func=macros.dispatcher),
    method="xhtml"
)


class Wiki(object):

    def __init__(self, database):
        super(Wiki, self).__init__()

        create = not os.path.exists(database)

        self._cx = sqlite3.connect(database)
        self._cu = self._cx.cursor()

        if create: