Skip to content

Commit

Permalink
support syntaxhighlight nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
v0lk3r committed Feb 29, 2012
1 parent 724108d commit 571c205
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mwlib/tagext.py
Expand Up @@ -144,6 +144,15 @@ def __call__(self, source, attributes):
return self.parse('<source lang="idl">%s</source>' % source)
register(IDLExtension)

class Syntaxhighlight(TagExtension):
'''http://www.mediawiki.org/wiki/Syntaxhighlight'''
name = "syntaxhighlight"
def __call__(self, source, attributes):
return self.parse('<source%s>%s</source>' % (''.join(' %s=%s' % (k, v)
for k, v in attributes.items()),
source))
register(Syntaxhighlight)

class RDFExtension(TagExtension):
# http://www.mediawiki.org/wiki/Extension:RDF
# uses turtle notation :(
Expand Down
15 changes: 15 additions & 0 deletions tests/test_tagext.py
Expand Up @@ -26,6 +26,21 @@ def test_idl():
assert isinstance(c, parser.Text)
assert stuff == u"".join(c.caption for c in tn.children)

def test_syntaxhightlight():
raw = '''<syntaxhighlight lang="php">
<?php
$v = "string"; // sample initialization
?>
html text
<?
echo $v; // end of php code
?>
</syntaxhighlight>
'''
p = parse(raw)
src = p.find(parser.TagNode)[0]
assert src and src.tagname == 'source', 'Syntaxhighight node not treated as source'

def test_listing():
raw = u'''
Expand Down

0 comments on commit 571c205

Please sign in to comment.