changeset 3196:08c2e2727641

Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
author Mikko Virkkil? <mvirkkil@cc.hut.fi>
date Wed, 05 Mar 2008 02:49:07 +0100
parents d186dc68f95f
children addc80ebc1cc
files MoinMoin/formatter/text_docbook.py
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/text_docbook.py	Wed Mar 05 02:36:47 2008 +0100
+++ b/MoinMoin/formatter/text_docbook.py	Wed Mar 05 02:49:07 2008 +0100
@@ -651,6 +651,31 @@
             self._emitComment('"~+bigger+~" is not applicable to DocBook')
         return ""
 
+    def rawHTML(self, markup):
+        if markup.strip() == "":
+            return ""
+
+        if "<" not in markup and ">" not in markup:
+            # Seems there are no tags.
+            # Let's get all the "entity references".
+            cleaned = markup
+            import re
+            entities = re.compile("&(?P<e>[a-zA-Z]+);").findall(cleaned)
+            from htmlentitydefs import name2codepoint
+            for ent in entities:
+                if name2codepoint.has_key(ent):
+                    cleaned = cleaned.replace("&%s;" % ent, unichr(name2codepoint[ent]))
+
+            # Then we replace all escaped unicodes.
+            escapedunicodes = re.compile("&#(?P<h>[0-9]+);").findall(markup)
+            for uni in escapedunicodes:
+                cleaned = cleaned.replace("&#%s;" % uni, unichr(int(uni)))
+
+            self.text(cleaned)
+
+        self._emitComment("RAW HTML: "+markup)
+        return ""
+
 ### Tables ##########################################################
 
     def table(self, on, attrs=(), **kw):