From: Vladimír Vondruš Date: Mon, 18 Jun 2018 09:42:07 +0000 (+0200) Subject: m.math: properly escape formula sources in the output. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=0761aebb8ff6c5b55e1c2a4f3d5e4cfad53a327e;p=blog.git m.math: properly escape formula sources in the output. --- diff --git a/doxygen/test/contents_math/index.html b/doxygen/test/contents_math/index.html index 6c9b9592..f7cc6df0 100644 --- a/doxygen/test/contents_math/index.html +++ b/doxygen/test/contents_math/index.html @@ -108,7 +108,7 @@ $c^2$ should be part of a new paragraph, not stuck out of it. The following formula has a custom environment:

-\begin{eqnarray*} g &=& \frac{Gm_2}{r^2} \\ &=& 9.82066032\,\mbox{m/s}^2 \end{eqnarray*} +\begin{eqnarray*} g &=& \frac{Gm_2}{r^2} \\ &=& 9.82066032\,\mbox{m/s}^2 \end{eqnarray*} diff --git a/pelican-plugins/latex2svgextra.py b/pelican-plugins/latex2svgextra.py index a782d30e..c442e1ac 100644 --- a/pelican-plugins/latex2svgextra.py +++ b/pelican-plugins/latex2svgextra.py @@ -22,6 +22,7 @@ # DEALINGS IN THE SOFTWARE. # +import html import pickle import re from hashlib import sha1 @@ -143,6 +144,6 @@ def patch(formula, svg, depth, attribs): style=style, viewBox=match.group('viewBox'), attribs=attribs, - formula=formula) + formula=html.escape(formula)) return _unique_src.sub(_unique_dst.format(counter=counter), _patch_src.sub(repl, svg)) diff --git a/pelican-plugins/m/math.py b/pelican-plugins/m/math.py index 28010dfb..4c446241 100644 --- a/pelican-plugins/m/math.py +++ b/pelican-plugins/m/math.py @@ -22,6 +22,7 @@ # DEALINGS IN THE SOFTWARE. # +import html import os import re @@ -48,7 +49,7 @@ class Math(rst.Directive): # Fallback rendering as code requested if render_as_code: - content = nodes.raw('', '\n'.join(self.content), format='html') + content = nodes.raw('', html.escape('\n'.join(self.content)), format='html') pre = nodes.literal_block('') pre.append(content) return [pre] @@ -87,7 +88,7 @@ def math(role, rawtext, text, lineno, inliner, options={}, content=[]): classes += options['classes'] del options['classes'] - content = nodes.raw('', utils.unescape(text), format='html') + content = nodes.raw('', html.escape(utils.unescape(text)), format='html') node = nodes.literal(rawtext, '', **options) node.append(content) return [node], [] diff --git a/pelican-plugins/m/test/math/page-code-fallback.html b/pelican-plugins/m/test/math/page-code-fallback.html index ba3df221..73e55724 100644 --- a/pelican-plugins/m/test/math/page-code-fallback.html +++ b/pelican-plugins/m/test/math/page-code-fallback.html @@ -31,6 +31,10 @@ and make sure there's enough space for all the complex W things bet the lines W = \sum_{i=0}^{n} \frac{w_i}{h_i} because Y = \sum_{i=0}^{n} B

The \cfrac thing doesn't align well: W = \sum_{i=0}^{n} \cfrac{w_i}{h_i}

+

Properly escape the formula source:

+
\begin{array}{rcl}
+    x & = & 1
+\end{array}
diff --git a/pelican-plugins/m/test/math/page.html b/pelican-plugins/m/test/math/page.html index 8c1669a3..bffc2b62 100644 --- a/pelican-plugins/m/test/math/page.html +++ b/pelican-plugins/m/test/math/page.html @@ -191,6 +191,25 @@ W = \sum_{i=0}^{n} \cfrac{w_i}{h_i}

+

Properly escape the formula source:

+
+ + +\begin{array}{rcl} + x & = & 1 +\end{array} + + + + + + + + + + + +
diff --git a/pelican-plugins/m/test/math/page.rst b/pelican-plugins/m/test/math/page.rst index d5e8c3c2..c1867088 100644 --- a/pelican-plugins/m/test/math/page.rst +++ b/pelican-plugins/m/test/math/page.rst @@ -20,3 +20,11 @@ the lines :math:`W = \sum_{i=0}^{n} \frac{w_i}{h_i}` because :math:`Y = \sum_{i=0}^{n} B` The ``\cfrac`` thing doesn't align well: :math:`W = \sum_{i=0}^{n} \cfrac{w_i}{h_i}` + +Properly escape the formula source: + +.. math:: + + \begin{array}{rcl} + x & = & 1 + \end{array}