Skip to content

Commit 5a4da5f

Browse files
committed
Same as last commit, but this adds "table" to the list that requires children.
1 parent f065ee4 commit 5a4da5f

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/canonicalize.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ impl CanonicalizeContext {
760760
name(parent).to_string()
761761
};
762762
let parent_requires_child = ELEMENTS_WITH_FIXED_NUMBER_OF_CHILDREN.contains(&parent_name) ||
763-
parent_name == "mtd" || parent_name == "mtr" || parent_name == "mlabeledtr";
763+
matches!(parent_name.as_ref(), "mtd" | "mtr" | "mlabeledtr" | "mtable");
764764

765765
// handle empty leaves -- leaving it empty causes problems with the speech rules
766766
if is_leaf(mathml) && !EMPTY_ELEMENTS.contains(element_name) && as_text(mathml).is_empty() {
@@ -4777,9 +4777,9 @@ mod canonicalize_tests {
47774777
}
47784778

47794779
#[test]
4780-
fn canonical_mtext_in_mrow() {
4780+
fn canonical_mtext_in_mtr() {
47814781
// make sure mtext doesn't go away
4782-
let test_str = "<math> <mtable> <mtr> <mtext> </mtext> </mtr> <mtr> <mtext> </mtext> </mtr> </mtable> </math>";
4782+
let test_str = "<math> <mtable> <mtr> <mtext> </mtext> </mtr> <mtr> <mtext> </mtext> </mtr> </mtable> </math>";
47834783
let target_str = " <math>
47844784
<mtable>
47854785
<mtr>
@@ -4793,6 +4793,36 @@ mod canonicalize_tests {
47934793
assert!(are_strs_canonically_equal(test_str, target_str, &[]));
47944794
}
47954795

4796+
#[test]
4797+
fn canonical_mtext_in_mtable() {
4798+
// make sure mtext doesn't go away
4799+
let test_str = r"<math> <mtable> <mtr> <mtd> <mi>L</mi> </mtd> <mtd> <mrow> <mi>&lt;mi/&gt;</mi> <mo>=</mo>
4800+
<mrow> <mo>[</mo> <mtable> <mtext> </mtext> </mtable> <mo>]</mo> </mrow> </mrow> </mtd> </mtr> </mtable> </math>";
4801+
let target_str = r"<math>
4802+
<mtable>
4803+
<mtr>
4804+
<mtd>
4805+
<mi>L</mi>
4806+
</mtd>
4807+
<mtd>
4808+
<mrow>
4809+
<mi>&lt;mi/&gt;</mi>
4810+
<mo>=</mo>
4811+
<mrow>
4812+
<mo>[</mo>
4813+
<mtable>
4814+
<mtext data-changed='empty_content' data-width='0' data-empty-in-2D='true'> </mtext>
4815+
</mtable>
4816+
<mo>]</mo>
4817+
</mrow>
4818+
</mrow>
4819+
</mtd>
4820+
</mtr>
4821+
</mtable>
4822+
</math>";
4823+
assert!(are_strs_canonically_equal(test_str, target_str, &[]));
4824+
}
4825+
47964826
#[test]
47974827
fn mrow_with_intent_and_single_child() {
47984828
use crate::interface::*;

0 commit comments

Comments
 (0)