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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-wikimarkup-2.3.0.tar.gz (34.6 kB view hashes)

Uploaded Source

Built Distribution

py_wikimarkup-2.3.0-py3-none-any.whl (34.4 kB view hashes)

Uploaded Python 3

Supported by

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