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.

Files for py-wikimarkup, version 2.0.0
Filename, size File type Python version Upload date Hashes
Filename, size py_wikimarkup-2.0.0-py3-none-any.whl (26.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size py-wikimarkup-2.0.0.tar.gz (25.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page