Permalink
Browse files

Fix rendering of h[1-6] titles in text post-processing

  • Loading branch information...
1 parent 7f7a0a1 commit b45e6c297bb4dd45b3f8a1edb051a7a21ee6bd21 Christoph Burgmer committed Apr 16, 2012
Showing with 66 additions and 7 deletions.
  1. +10 −0 README.rst
  2. +50 −0 tests/test_text_postprocessor.py
  3. +6 −7 text.py
View
@@ -27,7 +27,17 @@ and the wikitext will be rendered as HTML in the article.htm file.
Other ways might be implemented in the future.
+Unit tests
+----------
+Install nose and run:
+
+::
+
+ cd /PATH/TO/mediawiki-parser/
+ ln -s ../mediawiki-parser/ mediawiki_parser
+ export PYTHONPATH=/PATH/TO/mediawiki-parser/:/PATH/TO/pijnu/
+ nosetests tests
How to use in a program
=======================
@@ -4,16 +4,66 @@
class TextBackendTests(PostprocessorTestCase):
+ def test_simple_title(self):
+ source = '= A title =\n'
+ result = ' A title \n'
+ self.parsed_equal_string(source, result, 'wikitext', {}, 'text')
+
def test_simple_title2(self):
source = '== A title ==\n'
result = ' A title \n'
self.parsed_equal_string(source, result, 'wikitext', {}, 'text')
+ def test_simple_title3(self):
+ source = '=== A title ===\n'
+ result = ' A title \n'
+ self.parsed_equal_string(source, result, 'wikitext', {}, 'text')
+
+ def test_simple_title4(self):
+ source = '==== A title ====\n'
+ result = ' A title \n'
+ self.parsed_equal_string(source, result, 'wikitext', {}, 'text')
+
+ def test_simple_title5(self):
+ source = '==== A title ====\n'
+ result = ' A title \n'
+ self.parsed_equal_string(source, result, 'wikitext', {}, 'text')
+
def test_simple_title6(self):
source = '====== Test! ======\n'
result = ' Test! \n'
self.parsed_equal_string(source, result, 'wikitext', {}, 'text')
+ def test_simple_title_without_method(self):
+ source = '= A title =\n'
+ result = ' A title \n'
+ self.parsed_equal_string(source, result, None, {}, 'text')
+
+ def test_simple_title2_without_method(self):
+ source = '== A title ==\n'
+ result = ' A title \n'
+ self.parsed_equal_string(source, result, None, {}, 'text')
+
+ def test_simple_title3_without_method(self):
+ source = '=== A title ===\n'
+ result = ' A title \n'
+ self.parsed_equal_string(source, result, None, {}, 'text')
+
+ def test_simple_title4_without_method(self):
+ source = '==== A title ====\n'
+ result = ' A title \n'
+ self.parsed_equal_string(source, result, None, {}, 'text')
+
+ def test_simple_title5_without_method(self):
+ source = '==== A title ====\n'
+ result = ' A title \n'
+ self.parsed_equal_string(source, result, None, {}, 'text')
+
+ def test_simple_title6_without_method(self):
+ source = '====== Test! ======\n'
+ result = ' Test! \n'
+ self.parsed_equal_string(source, result, None, {}, 'text')
+
def test_simple_allowed_open_tag(self):
source = 'a<p>test'
result = 'a\ntest'
View
@@ -13,22 +13,22 @@ def render_tag_br(attributes):
'br': render_tag_br}
def render_title1(node):
- node.value += '\n'
+ node.value = '%s\n' % node.leaf()
def render_title2(node):
- node.value += '\n'
+ node.value = '%s\n' % node.leaf()
def render_title3(node):
- node.value += '\n'
+ node.value = '%s\n' % node.leaf()
def render_title4(node):
- node.value += '\n'
+ node.value = '%s\n' % node.leaf()
def render_title5(node):
- node.value += '\n'
+ node.value = '%s\n' % node.leaf()
def render_title6(node):
- node.value += '\n'
+ node.value = '%s\n' % node.leaf()
def render_raw_text(node):
pass
@@ -41,7 +41,6 @@ def render_wikitext(node):
def render_body(node):
tags = {'bold': '*', 'bold_close': '*', 'italic': '_', 'italic_close': '_'}
- print node
node.value = apostrophes.parse(node.leaf(), tags)
def render_entity(node):

0 comments on commit b45e6c2

Please sign in to comment.