changeset 68:7a4a72d9e003

HTML output converter - De-duplicate header code
author Bastian Blank <bblank@thinkmo.de>
date Thu, 03 Mar 2011 00:17:23 +0100
parents d43c7fb728e0
children cc742990942e
files MoinMoin/converter/html_out.py
diffstat 1 files changed, 9 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/html_out.py	Thu Mar 03 00:04:52 2011 +0100
+++ b/MoinMoin/converter/html_out.py	Thu Mar 03 00:17:23 2011 +0100
@@ -240,7 +240,9 @@
             level = 1
         elif level > 6:
             level = 6
-        return self.new_copy(ET.QName('h%d' % level, html), elem)
+        ret = self.new_copy(html('h%d' % level), elem)
+        ret.level = level
+        return ret
 
     def visit_moinpage_inline_part(self, elem):
         body = error = None
@@ -649,24 +651,16 @@
         else:
             return super(ConverterPage, self).visit(elem)
 
-    def visit_moinpage_h(self, elem):
-        level = elem.get(moin_page.outline_level, 1)
-        try:
-            level = int(level)
-        except ValueError:
-            raise ElementException('page:outline-level needs to be an integer')
-        if level < 1:
-            level = 1
-        elif level > 6:
-            level = 6
-        elem = self.new_copy(html('h%d' % level), elem)
+    def visit_moinpage_h(self, elem,
+            _tag_html_id=html.id):
+        elem = super(ConverterPage, self).visit_moinpage_h(elem)
 
-        id = elem.get(html.id)
+        id = elem.get(_tag_html_id)
         if not id:
             id = self._id.gen_text(''.join(elem.itertext()))
-            elem.set(html.id, id)
+            elem.set(_tag_html_id, id)
 
-        self._special_stack[-1].add_heading(elem, level, id)
+        self._special_stack[-1].add_heading(elem, elem.level, id)
         return elem
 
     def visit_moinpage_note(self, elem):