chiark / gitweb /
m.math: properly escape formula sources in the output.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 18 Jun 2018 09:42:07 +0000 (11:42 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 18 Jun 2018 13:23:43 +0000 (15:23 +0200)
doxygen/test/contents_math/index.html
pelican-plugins/latex2svgextra.py
pelican-plugins/m/math.py
pelican-plugins/m/test/math/page-code-fallback.html
pelican-plugins/m/test/math/page.html
pelican-plugins/m/test/math/page.rst

index 6c9b959259d724d88ee38c9cd97dc516c9af4762..f7cc6df04551faed4659b6d9275dc5b3bae11cb3 100644 (file)
@@ -108,7 +108,7 @@ $c^2$
 </g>
 </svg> should be part of a new paragraph, not stuck out of it. The following formula has a custom environment:</p><div class="m-math"><svg style="width: 11.926em; height: 4.028em;" viewBox="136.775 -38.6648 114.495 38.6648">
 <title>
-\begin{eqnarray*} g &=& \frac{Gm_2}{r^2} \\ &=& 9.82066032\,\mbox{m/s}^2 \end{eqnarray*}
+\begin{eqnarray*} g &amp;=&amp; \frac{Gm_2}{r^2} \\ &amp;=&amp; 9.82066032\,\mbox{m/s}^2 \end{eqnarray*}
 </title>
 <defs>
 <path d='M2.19975 -0.573848C2.19975 -0.920548 1.91283 -1.15965 1.6259 -1.15965C1.2792 -1.15965 1.0401 -0.872727 1.0401 -0.585803C1.0401 -0.239103 1.32702 0 1.61395 0C1.96065 0 2.19975 -0.286924 2.19975 -0.573848Z' id='eq5-g0-58'/>
index a782d30e0454e4eba01f61928412a46a182b63fd..c442e1ac82d99df9d94e7a1cf243d33b8c0586d8 100644 (file)
@@ -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))
index 28010dfbfe43708d150dce2ec3ba7ca803e04094..4c446241fc69704989e8fc774dd84e66e2c04d4b 100644 (file)
@@ -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], []
index ba3df22164d1092ab4c275a2b5f5e4370cd33c71..73e55724e95a75fb41d5dcc34363a539e96bcf79 100644 (file)
@@ -31,6 +31,10 @@ and make sure there's enough space for all the complex <code>W</code> things bet
 the lines <code>W = \sum_{i=0}^{n} \frac{w_i}{h_i}</code> because
 <code>Y = \sum_{i=0}^{n} B</code></p>
 <p>The <code>\cfrac</code> thing doesn't align well: <code>W = \sum_{i=0}^{n} \cfrac{w_i}{h_i}</code></p>
+<p>Properly escape the formula source:</p>
+<pre>\begin{array}{rcl}
+    x &amp; = &amp; 1
+\end{array}</pre>
 <!-- /content -->
       </div>
     </div>
index 8c1669a3861e2d4c8be5acd622b0aef9ce4f682c..bffc2b62b94645b2da49ecf1dbb414f6a51a6252 100644 (file)
@@ -191,6 +191,25 @@ W = \sum_{i=0}^{n} \cfrac{w_i}{h_i}
 <use x='65.9862' xlink:href='#eq7-g1-105' y='9.99393'/>
 </g>
 </svg></p>
+<p>Properly escape the formula source:</p>
+<div class="m-math">
+<svg style="width: 4.327em; height: 0.803em;" viewBox="173.504 -12.0382 41.535 7.70444">
+<title>
+\begin{array}{rcl}
+    x &amp; = &amp; 1
+\end{array}
+</title>
+<defs>
+<path d='M5.66675 -4.87771C5.28418 -4.80598 5.14072 -4.51905 5.14072 -4.29191C5.14072 -4.00498 5.36787 -3.90934 5.53524 -3.90934C5.8939 -3.90934 6.14496 -4.22017 6.14496 -4.54296C6.14496 -5.04508 5.57111 -5.27223 5.06899 -5.27223C4.33973 -5.27223 3.93325 -4.55492 3.82565 -4.32777C3.55068 -5.22441 2.80946 -5.27223 2.59427 -5.27223C1.37484 -5.27223 0.729265 -3.7061 0.729265 -3.44309C0.729265 -3.39527 0.777086 -3.33549 0.860772 -3.33549C0.956413 -3.33549 0.980324 -3.40722 1.00423 -3.45504C1.41071 -4.78207 2.21171 -5.03313 2.55841 -5.03313C3.09639 -5.03313 3.20399 -4.53101 3.20399 -4.24408C3.20399 -3.98107 3.13225 -3.7061 2.98879 -3.13225L2.58232 -1.4944C2.40299 -0.777086 2.05629 -0.119552 1.42267 -0.119552C1.36289 -0.119552 1.06401 -0.119552 0.812951 -0.274969C1.24334 -0.358655 1.33898 -0.71731 1.33898 -0.860772C1.33898 -1.09988 1.15965 -1.24334 0.932503 -1.24334C0.645579 -1.24334 0.334745 -0.992279 0.334745 -0.609714C0.334745 -0.107597 0.896638 0.119552 1.41071 0.119552C1.98456 0.119552 2.39103 -0.334745 2.64209 -0.824907C2.83337 -0.119552 3.43113 0.119552 3.87347 0.119552C5.0929 0.119552 5.73848 -1.44658 5.73848 -1.70959C5.73848 -1.76936 5.69066 -1.81719 5.61893 -1.81719C5.51133 -1.81719 5.49938 -1.75741 5.46351 -1.66177C5.14072 -0.609714 4.44732 -0.119552 3.90934 -0.119552C3.49091 -0.119552 3.26376 -0.430386 3.26376 -0.920548C3.26376 -1.18356 3.31158 -1.37484 3.50286 -2.16389L3.9213 -3.78979C4.10062 -4.5071 4.5071 -5.03313 5.05704 -5.03313C5.08095 -5.03313 5.41569 -5.03313 5.66675 -4.87771Z' id='eq8-g0-120'/>
+<path d='M3.44309 -7.66326C3.44309 -7.93823 3.44309 -7.95019 3.20399 -7.95019C2.91706 -7.6274 2.3193 -7.18506 1.08792 -7.18506V-6.83836C1.36289 -6.83836 1.96065 -6.83836 2.61818 -7.14919V-0.920548C2.61818 -0.490162 2.58232 -0.3467 1.53026 -0.3467H1.15965V0C1.48244 -0.0239103 2.64209 -0.0239103 3.03661 -0.0239103S4.57883 -0.0239103 4.90162 0V-0.3467H4.53101C3.47895 -0.3467 3.44309 -0.490162 3.44309 -0.920548V-7.66326Z' id='eq8-g1-49'/>
+<path d='M8.06974 -3.87347C8.23711 -3.87347 8.4523 -3.87347 8.4523 -4.08867C8.4523 -4.31582 8.24907 -4.31582 8.06974 -4.31582H1.02814C0.860772 -4.31582 0.645579 -4.31582 0.645579 -4.10062C0.645579 -3.87347 0.848817 -3.87347 1.02814 -3.87347H8.06974ZM8.06974 -1.64981C8.23711 -1.64981 8.4523 -1.64981 8.4523 -1.86501C8.4523 -2.09215 8.24907 -2.09215 8.06974 -2.09215H1.02814C0.860772 -2.09215 0.645579 -2.09215 0.645579 -1.87696C0.645579 -1.64981 0.848817 -1.64981 1.02814 -1.64981H8.06974Z' id='eq8-g1-61'/>
+</defs>
+<g id='eq8-page1'>
+<use x='173.504' xlink:href='#eq8-g0-120' y='-4.33378'/>
+<use x='190.119' xlink:href='#eq8-g1-61' y='-4.33378'/>
+<use x='209.186' xlink:href='#eq8-g1-49' y='-4.33378'/>
+</g>
+</svg></div>
 <!-- /content -->
       </div>
     </div>
index d5e8c3c27ad5e0cff7ac1f61c46f70fb0edafe18..c18670885a22409a4ff48acb5bd1beb5010feb2e 100644 (file)
@@ -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}