Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2008-05-27 19:28:10 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2008-05-27 19:28:10 (GMT)
commitaa9e24737fe50b6a6abbe690c75471fa6641bcad (patch)
treebab49a1e8f65d10d092caaa99c4f6e60aad25f24
parentb084751af2bd2bdd2c470ae400ef963b5a8b5ce3 (diff)
Better MathML rendering (using Blahtex instead of itex2MML).
-rwxr-xr-xbin/blahtexbin0 -> 1132072 bytes
-rw-r--r--bin/tidy.conf3
-rwxr-xr-xserver.py25
3 files changed, 17 insertions, 11 deletions
diff --git a/bin/blahtex b/bin/blahtex
new file mode 100755
index 0000000..0f143c5
--- /dev/null
+++ b/bin/blahtex
Binary files differ
diff --git a/bin/tidy.conf b/bin/tidy.conf
index 1424b4b..5260577 100644
--- a/bin/tidy.conf
+++ b/bin/tidy.conf
@@ -1,6 +1,7 @@
new-inline-tags: cfif, cfelse, math, mroot,
mrow, mi, mn, mo, msqrt, mfrac, msubsup, munderover,
munder, mover, mmultiscripts, msup, msub, mtext,
- mprescripts, mtable, mtr, mtd, mth, mspace, merror
+ mprescripts, mtable, mtr, mtd, mth, mspace, merror,
+ mstyle, blahtex, mathml, markup,
new-blocklevel-tags: cfoutput, cfquery
diff --git a/server.py b/server.py
index ec2a35a..f86009c 100755
--- a/server.py
+++ b/server.py
@@ -32,6 +32,7 @@ from SimpleHTTPServer import SimpleHTTPRequestHandler
import urllib
import re
import wp
+import xml.dom.minidom
# Uncomment to print out a large dump from the template expander.
#os.environ['DEBUG_EXPANDER'] = '1'
@@ -140,27 +141,31 @@ class HTMLOutputBuffer:
def write(self, obj):
if isinstance(obj, unicode):
- self.buffer += str(obj).encode('utf8')
+ self.buffer += obj.encode('utf8')
else:
- self.buffer += str(obj)
+ self.buffer += obj
def getvalue(self):
return self.buffer
class WPMathRenderer:
def render(self, latex):
-
- process = subprocess.Popen(('bin/itex2MML', '--inline'), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- #process = subprocess.Popen(('bin/blahtex', '--mathml', '--mathml-encoding', 'numeric'), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ #process = subprocess.Popen(('bin/itex2MML', '--inline'), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ process = subprocess.Popen(('bin/blahtex', '--mathml', '--texvc-compatible-commands'), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
(mathml, err) = process.communicate(latex)
if process.returncode is not 0:
return ""
- # Fix case sensitivity of entities that FF is missing somehow.
- # List of all: http://fluxionsdividebyzero.com/p1/comsci/mathmlnotes.xml
- mathml = mathml.replace('&Sum;', '&sum;')
-
+ # Ugly! There is certainly a better way to do this, but my DOM skills are weak, and this works.
+ dom = xml.dom.minidom.parseString(mathml)
+ dom = dom.getElementsByTagName('blahtex')[0]
+ dom = dom.getElementsByTagName('mathml')[0]
+ dom = dom.getElementsByTagName('markup')[0]
+ mathml = dom.toxml()
+ mathml = mathml.replace('markup', 'math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"')
+ dom.unlink()
+
# Straight embedding. Requires parent document to be XHTML.
return mathml
@@ -507,7 +512,7 @@ class WikiRequestHandler(SimpleHTTPRequestHandler):
html = htmlout.getvalue()
# Fix any non-XHTML tags using tidy.
- process = subprocess.Popen(('bin/tidy', '-config', 'bin/tidy.conf', '-numeric', '-utf8', '-asxhtml'), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ process = subprocess.Popen(('bin/tidy', '-q', '-config', 'bin/tidy.conf', '-numeric', '-utf8', '-asxhtml'), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
(xhtml, err) = process.communicate(html)
if len(xhtml):
html = xhtml