Exemple #1
0
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))
Exemple #2
0
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))
Exemple #3
0
def render_creole(source):
    dialect = create_dialect(creole10_base, wiki_links_base_url="/page/",
                             add_heading_ids="")
    parser = Parser(dialect=dialect, method='html', encoding=None)

    html = parser.render(source)

    # add favicons to external URLs
    soup = BeautifulSoup(html, "html5lib")
    for a_tag in soup.find_all('a'):
        url = a_tag['href']
        if is_external(url):
            favicon = soup.new_tag('img')
            favicon['src'] = "//www.google.com/s2/favicons?domain=" + quote(url)
            favicon['class'] = 'favicon'

            a_tag.insert_after(favicon)

    # circular import fix
    from .models import Page

    # build a set of all possible internal links
    page_urls = Page.objects.all_urls()

    # add a class to links to nonexistent pages
    for a_tag in soup.find_all('a'):
        url = a_tag['href']
        if not is_external(url):
            if not url.endswith('/'):
                url = url + '/'

            if url not in page_urls:
                a_tag['class'] = 'nonexistent'

    return soup.find('body').encode_contents().decode('utf8')
Exemple #4
0
def get_parser(wiki_info):
    parser = None
    wiki_id = wiki_info['wiki_id']
    if wiki_id in parsers:
        parser = parsers[wiki_id]
    else:
        parser = Parser(create_dialect(
            creole11_base,
            wiki_links_base_url   = '',
            wiki_links_space_char = '_',
            wiki_links_class_func = (lambda p: '' if page_exists(wiki_info, p) else 'create'),
            wiki_links_path_func  = (lambda n: _gen_link(n, wiki_info))
        ), 'xhtml', True, 'utf-8')
        parsers[wiki_id] = parser
    return parser
Exemple #5
0
def create_lug_dialect():
    iw_bases, iw_spaces, iw_classes = build_interwikis()

    dialect = create_dialect(creole11_base,
        # Markup customizations
        simple_markup = INLINE_MARKUP,
        indent_style = '',
        indent_class = 'quote',
        no_wiki_monospace = False,
        # Internal links
        wiki_links_base_url = "",
        wiki_links_path_func = wiki_link_path,
        wiki_links_class_func = wiki_link_class,
        # Everyone else's links
        external_links_class = 'external-link',
        interwiki_links_base_urls = iw_bases,
        interwiki_links_class_funcs = iw_classes,
        interwiki_links_space_chars = iw_spaces
    )
    dialect.pre = CodeBlock()
    return dialect
Exemple #6
0
        pos, kw = parse_args(arg_string)
        try:
            value = environ['wiki.macros'][name](macro, environ, *pos, **kw)
        except TypeError:
            value = None
        return value
    else:
        return None


def path_func(page_name):
    '''
    Setting wiki_links_base_url doesn't work since that only gets parsed once.
    So we essentially use this as a wrapper around reverse().
    '''
    #page_name = urllib.quote_plus(page_name)
    #TODO: Disallow certain characters here?
    #TODO: Catch exception here
    return reverse('show', args=[page_name])


dialect = dialects.create_dialect(
    dialects.creole11_base,
    #no_wiki_monospace=False,
    #wiki_links_class_func=class_func,
    blog_style_endings=True,
    wiki_links_path_func=path_func,
    macro_func=macro_func)

text2html = core.Parser(dialect)
Exemple #7
0
from common import *
from page import *
from user import *

sys.path.append(os.sep.join((os.getcwd(),'../')))
import genshi
import creoleparser
from creoleparser.dialects import create_dialect, creole10_base, creole11_base
from creoleparser.core import Parser

wiki_parser = Parser(dialect=create_dialect(creole11_base), method='xhtml')

class PagesHandler( BaseRequestHandler ):
  def get( self, page_name , prefix = "/pages" ):
    values = {}
    self.prefix = prefix
    if not page_name:
      page_name = "MainPage"
      
    # find the page
    page_name = page_name.lower()
    query = PageModel.all();
    query.filter( 'name =', page_name );
    page = query.get()
    
    if not page:
      # page not created yet, creating a new one
      values.update( self.create_page(page_name) )
      mode = "edit"
    else:
      # load a page already exists
        if mailtype is 'mailreminder':
            msg = Message('[einfachJabber.de] Jabber-Konto Registrierung')
            msg.body = u'''
    einfachJabber.de

    Du hast eben über http://einfachjabber.de einen neuen
    Jabber-Account registriert.
    Die Benutzerdaten dazu lauten:

    Benutzername: %s
    Passwort: %s

    Auf http://einfachjabber.de findest du Anleitungen für
    verschiedene Client-Programme.
            ''' % (data[1], data[2])
            msg.recipients = [data[0]]

        if mailtype is 'rating':
            msg = Message('[einfachJabber.de] Tutorialbewertung')
            msg.body = u'''
    einfachJabber.de Tutorialbewertung

    Bewertung: %s
    Vorschlag: %s
    Tutorial: %s
            ''' % (data[0], data[1], data[2])
            msg.recipients = ['*****@*****.**']
        mail.send(msg)

my_parser = Parser(dialect=create_dialect(creole11_base), method='html', encoding=None)
Exemple #9
0
#     wiki_links_class_func = class_fn,
#     wiki_links_path_func = TOPIC_LIST.path_fn,
#     macro_func = macro_fn,
#     interwiki_links_base_urls=dict(wikicreole='http://wikicreole.org/wiki/',
#                                    wikipedia='http://wikipedia.org/wiki/',)
#     )

parser = Parser(dialect = create_dialect(\
        creole11_base, 
        wiki_links_base_url = reverse('aswiki_topic_index'), # NOTE: Make this
                                                             # a two element
                                                             # list for images
                                                             # to be loaded
                                                             # from a separate
                                                             # URL
        wiki_links_space_char = '%20', # NOTE: make this a two element list to
                                       # give images a different space
                                       # character.
        no_wiki_monospace = False,
        wiki_links_class_func = class_fn,
        wiki_links_path_func = (TOPIC_LIST.path_fn,
                                TOPIC_LIST.image_fn),
        bodied_macros = { },
        non_bodied_macros = { },
        macro_func = macro_fn,
        # custom_markup = (),
        interwiki_links_base_urls = {
            'wikicreole' : 'http://wikicreole.org/wiki/',
            'wikipedia'  :'http://wikipedia.org/wiki/' }
        ))
Exemple #10
0
from django import template
from django.utils.safestring import mark_safe
from creoleparser.core import Parser
from creoleparser.dialects import create_dialect, creole11_base

register = template.Library()
text2html = Parser(
   dialect=create_dialect(creole11_base, wiki_links_base_url='/piki/',
                          blog_style_endings=True), method='html')

@register.filter
def creole(value):
   print text2html(value)
   return text2html(value)
Exemple #11
0
    except Page.DoesNotExist: 
        return 'cms_link_error'


def internal_link_url(slug):
    return reverse('page_render', args=[make_wiki_slug(slug)])

creole_parser = Parser(
    dialect=create_dialect(
        creole11_base,
        wiki_links_path_func=internal_link_url,
        wiki_links_class_func=internal_link_class,
        non_bodied_macros={
            'otrosusos':macro_otheruses,
            'Archivo':macro_side_bar_file,
            'listen':macro_listen,
            'AP':macro_main_article,
            'listaref':macro_listreferences,
        },
        bodied_macros={
            'ref':macro_reference,
            'wikitable':macro_wikitable,
        }
    ),
method='xhtml')


def make_wiki_slug(text, capitalize=False):
    if type(text) != UnicodeType:
        text = unicode(text, 'utf-8', 'ignore')
    
    text = text.replace(u' ', u'_')
Exemple #12
0
def wiki_parse(content, wiki_links_path_func):
    wiki_parser = Parser(dialect=create_dialect(creole11_base, wiki_links_path_func=wiki_links_path_func))
    return wiki_parser(content)