New header parser allow links and other wiki format in header.

diff -r 873d2942ba36 MoinMoin/parser/text_moin_wiki.py
--- a/MoinMoin/parser/text_moin_wiki.py	Wed Nov 19 10:25:21 2008 +0800
+++ b/MoinMoin/parser/text_moin_wiki.py	Wed Nov 19 10:25:23 2008 +0800
@@ -325,9 +325,11 @@
     (?:\((?P<macro_args>.*?)\))?  # optionally macro arguments
     >>
 )|(?P<heading>
-    ^(?P<hmarker>=+)\s+  # some === at beginning of line, eat trailing blanks
-    (?P<heading_text>.*?)  # capture heading text
-    \s+(?P=hmarker)\s$  # some === at end of line (matching amount as we have seen), eat blanks
+    (
+     (^(?P<heading_on>=+)\s*)  # some === at beginning of line, eat trailing blanks
+    |
+     (?P<heading_off>\s*=*\s$)  # some === at end of line (matching amount as we have seen), eat blanks
+    )
 )|(?P<parser>
     \{\{\{  # parser on
     (?P<parser_unique>(\{*|\w*))  # either some more {{{{ or some chars to solve the nesting problem
@@ -415,6 +417,8 @@
         self.is_big = False
         self.is_small = False
         self.is_remark = False
+        # OSSXP: new header parser
+        self.heading_depth = 0
 
         self.lineno = 0
         self.in_list = 0 # between <ul/ol/dl> and </ul/ol/dl>
@@ -1198,15 +1202,27 @@
 
     def _heading_repl(self, word, groups):
         """Handle section headings."""
-        heading_text = groups.get('heading_text', '')
-        depth = min(len(groups.get('hmarker')), 5)
-        return ''.join([
-            self._closeP(),
-            self.formatter.heading(1, depth, id=heading_text),
-            self.formatter.text(heading_text),
-            self.formatter.heading(0, depth),
-        ])
-    _heading_text_repl = _heading_repl
+        on = groups.get('heading_on', '')
+        if on:
+            depth = min(len(on), 5)
+            self.heading_depth = depth
+            return ''.join([
+                # self._closeP(),
+                self.formatter.heading(1, depth, id=self.formatter.page.page_name),
+            ])
+        else: # end of heading
+            depth = self.heading_depth
+            self.heading_depth = 0
+            if depth:
+                return ''.join([
+                    self._closeP(),
+                    self.formatter.heading(0, depth)
+                ])
+            else:
+                return self.formatter.text(word)
+
+    _heading_on_repl = _heading_repl
+    _heading_off_repl = _heading_repl
 
     def _parser_repl(self, word, groups):
         """Handle parsed code displays."""
