From: <pau...@us...> - 2011-10-15 04:50:20
|
Author: paultremblay Date: 2011-10-15 06:50:12 +0200 (Sat, 15 Oct 2011) New Revision: 7176 Modified: trunk/sandbox/paultremblay/scripts/rstxml2mathml.py Log: Script now only process the math_block when the attribute classes has a value of asciimath. Modified: trunk/sandbox/paultremblay/scripts/rstxml2mathml.py =================================================================== --- trunk/sandbox/paultremblay/scripts/rstxml2mathml.py 2011-10-15 04:48:22 UTC (rev 7175) +++ trunk/sandbox/paultremblay/scripts/rstxml2mathml.py 2011-10-15 04:50:12 UTC (rev 7176) @@ -15,7 +15,7 @@ def __init__(self): self.__characters = '' - self.__math_element= True + self.__ascii_math = False self.__ns_dict = {'http://www.w3.org/XML/1998/namespace': "xml"} @@ -27,7 +27,12 @@ ns = name[0] el_name = name[1] if el_name == 'math_block': - self.__math_element= True + the_keys = list(attrs.keys()) + for the_key in the_keys: + att_name = the_key[1] + value = attrs[the_key] + if att_name == 'classes' and value == 'asciimath': + self.__ascii_math= True sys.stdout.write('<') if ns: sys.stdout.write('ns1:%s' % el_name) @@ -70,12 +75,13 @@ def endElementNS(self, name, qname): ns = name[0] el_name = name[1] - if el_name == 'math_block': + if el_name == 'math_block' and self.__ascii_math == True: self.__math_element= False math_string = '$$ %s $$' % (self.__characters) new_tree = asciimathml.parse(self.__characters)[0] string_tree = tostring(new_tree, encoding="utf-8").decode() - sys.stdout.write('<math xmlns="http://www.w3.org/1998/Math/MathML">') + title = xml.sax.saxutils.escape(self.__characters) + sys.stdout.write('<math title="%s" xmlns="http://www.w3.org/1998/Math/MathML">' % (title)) sys.stdout.write(string_tree) sys.stdout.write('</math>') self.__characters = '' |