Skip to content

Commit

Permalink
[mathml] Fix parsing of <mo> text content.
Browse files Browse the repository at this point in the history
Currently MathMLOperatorElement::ParseOperatorContent() relies on
Node::HasOneTextChild() to check and parse the text content of an <mo>
element. This does not work well if the element contains a comment
(e.g. <mo>&#0x2211;<!-- sum --></mo>) or was constructed dynamically
by appending two characters (e.g. <mo>==</mo>). This CL fixes that
issue by letting ParseOperatorContent() check the node children
directly.

Bug: 6606
Change-Id: I5642f2cef254ee0e005b4a0b7e45624a8066e2fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3076234
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Frédéric Wang <[email protected]>
Cr-Commit-Position: refs/heads/master@{#909399}
  • Loading branch information
fred-wang authored and chromium-wpt-export-bot committed Aug 6, 2021
1 parent 8558f84 commit 0d1609c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>&lt;mo&gt; with a single character and children (reference)</title>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css"/>
<style>
math { font: 50px/1 Ahem; }
math { font: 25px/1 Ahem; }
</style>
</head>
<body>
Expand All @@ -20,5 +20,11 @@

<p><math><mn>p</mn><mo stretchy="false" lspace="0" rspace="0">X</mo><mn>p</mn></math></p>
<p><math><mn>p</mn><mo id="dynamic-remove" stretchy="false" lspace="0" rspace="0"><span></span>X</mo><mn>p</mn></math></p>
<p><math><mn>p</mn><mo stretchy="false" lspace="0" rspace="0"><!-- COMMENT -->X</mo><mn>p</mn></math></p>

<p>There should be 4/18em horizontal gaps around the middle rectangles:</p>
<p><math><mn>p</mn><mo lspace="0.2222222222222222em" rspace="0.2222222222222222em">XX</mo><mn>p</mn></math></p>
<p><math><mn>p</mn><mo id="dynamic-text-add-2" lspace="0.2222222222222222em" rspace="0.2222222222222222em">XX</mo><mn>p</mn></math></p>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css"/>
<link rel="match" href="mo-single-char-and-children-ref.html">
<style>
math { font: 50px/1 Ahem; }
math { font: 25px/1 Ahem; }
</style>
</head>
<body>
Expand All @@ -17,12 +17,17 @@
<p><math><mn>p</mn><mo>(<span></span></mo><mn>p</mn></math></p>
<p><math><mn>p</mn><mo><span></span>(</mo><mn>p</mn></math></p>
<p><math><mn>p</mn><mo id="dynamic-add">(</mo><mn>p</mn></math></p>
<p><math><mn>p</mn><mo id="dynamic-text-add">|</mo><mn>p</mn></math></p>
<p><math><mn>p</mn><mo id="dynamic-text-add">=</mo><mn>p</mn></math></p>

<p>There should be no horizontal gap around the middle rectangles:</p>

<p><math><mn>p</mn><mo stretchy="false">(</mo><mn>p</mn></math></p>
<p><math><mn>p</mn><mo id="dynamic-remove" stretchy="false"><span></span>(</mo><mn>p</mn></math></p>
<p><math><mn>p</mn><mo stretchy="false"><!-- COMMENT -->(</mo><mn>p</mn></math></p>

<p>There should be 4/18em horizontal gaps around the middle rectangles:</p>
<p><math><mn>p</mn><mo>&amp;<!-- COMMENT -->&amp;</mo><mn>p</mn></math></p>
<p><math><mn>p</mn><mo id="dynamic-text-add-2">&amp;</mo><mn>p</mn></math></p>

<script src="/mathml/support/feature-detection.js"></script>
<script>
Expand All @@ -32,7 +37,10 @@
mo.appendChild(document.createElement("span"));

mo = document.getElementById("dynamic-text-add");
mo.appendChild(document.createTextNode("|"));
mo.appendChild(document.createTextNode("="));

mo = document.getElementById("dynamic-text-add-2");
mo.appendChild(document.createTextNode("&"));

mo = document.getElementById("dynamic-remove");
mo.removeChild(mo.firstElementChild);
Expand Down

0 comments on commit 0d1609c

Please sign in to comment.