Skip to main content

A basic MediaWiki markup parser.

Project description

Summary

Formats text following the MediaWiki syntax.

Usage

To return HTML from Wiki:

from wikimarkup.parser import Parser

parser = Parser()
html = parser.parse(text[, show_toc=True])

To return HTML without certain “annoying” (TODO: define annoying) elements, such as headings:

from wikimarkup.parser import parselite

parselite(text)

Adding New Tags

You can add new tags with the registerTagHook method.:

from wikimarkup.parser import Parser
import cgi

def blockquoteTagHook(parser_env, body, attributes={}):
    """<quote[ cite="Person"]>A paragraph of text.</quote>"""
    text = ['<blockquote>']
    if 'cite' in attributes:
        text.append('<cite>%s</cite>' % (cgi.escape(attributes['cite']),))
    text.append(parse(body.strip()))
    text.append('</blockquote>')
    return u'\n'.join(text)

parser = Parser()
parser.registerTagHook('quote', blockquoteTagHook)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page