File: invalid-markup.js

package info (click to toggle)
firefox-esr 140.4.0esr-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,539,284 kB
  • sloc: cpp: 7,381,286; javascript: 6,388,710; ansic: 3,710,139; python: 1,393,780; xml: 628,165; asm: 426,916; java: 184,004; sh: 65,742; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (96 lines) | stat: -rw-r--r-- 3,840 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// This is a helper for generating invalid MathML markup.
// Depends on ./mathml-fragments.js

function isValid(tagName, mspaceCount) {
  switch (tagName) {
    case "mfrac":
    case "mroot":
    case "munder":
    case "mover":
    case "msub":
    case "msup":
      return mspaceCount == 2;
    case "munderover":
    case "msubsup":
      return mspaceCount == 3;
    case "mmultiscripts":
      return mspaceCount % 2 == 1;
  }
}

function generateInvalidMarkup() {
  let container = document.createElement("div");
  ["mfrac", "mroot", "munder", "mover", "munderover", "msub", "msup", "msubsup", "mmultiscripts"].forEach(tag => {
    let math = FragmentHelper.createElement("math");
    let element = FragmentHelper.createElement(tag);
    let reference = FragmentHelper.createElement("mrow");
    math.appendChild(element);
    math.appendChild(reference);
    let maxCount = tag == "mmultiscripts" ? 10 : 5;
    let mspaceCount = 0;
    for (let count = 0; count <= maxCount; count++) {
      element.dataset.description = `count == ${count}`;
      if (!isValid(tag, mspaceCount)) {
        container.appendChild(math.cloneNode(true));
      }
      if (tag == "mmultiscripts" && count == maxCount / 2) {
        [element, reference].forEach(el => {
          el.insertAdjacentHTML("beforeend", `<mprescripts/>`);
        });
      } else {
        let width = (count + 1) * 10;
        let height = (count + 1) * (count % 2 ? 15 : 5);
        let depth = (count + 1) * (count % 2 ? 5 : 15);
        [element, reference].forEach(el => {
          el.insertAdjacentHTML("beforeend", `<mspace height="${height}px" depth="${depth}px" width="${width}px" style="background: black"/>`);
        });
        mspaceCount++;
      }
    }
  });

  container.insertAdjacentHTML("beforeend", `
<math>
  <mmultiscripts data-description="first in-flow child is an <mprescripts>">
    <mprescripts/>
    <mspace height="5px" depth="15px" width="10px" style="background: black"/>
    <mspace height="30px" depth="10px" width="20px" style="background: black"/>
    <mspace height="15px" depth="45px" width="30px" style="background: black"/>
    <mspace height="60px" depth="20px" width="40px" style="background: black"/>

  </mmultiscripts>
  <mrow>
    <mprescripts/>
    <mspace height="5px" depth="15px" width="10px" style="background: black"/>
    <mspace height="30px" depth="10px" width="20px" style="background: black"/>
    <mspace height="15px" depth="45px" width="30px" style="background: black"/>
    <mspace height="60px" depth="20px" width="40px" style="background: black"/>

  </mrow>
</math>
<math>
  <mmultiscripts data-description="one of the even number of children after the first <mprescripts> is an <mprescripts>">
    <mspace height="5px" depth="15px" width="10px" style="background: black"/>
    <mspace height="30px" depth="10px" width="20px" style="background: black"/>
    <mspace height="15px" depth="45px" width="30px" style="background: black"/>
    <mprescripts/>
    <mspace height="60px" depth="20px" width="40px" style="background: black"/>
    <mprescripts/>
    <mspace height="25px" depth="75px" width="50px" style="background: black"/>
    <mspace height="35px" depth="105px" width="70px" style="background: black"/>
  </mmultiscripts>
  <mrow>
    <mspace height="5px" depth="15px" width="10px" style="background: black"/>
    <mspace height="30px" depth="10px" width="20px" style="background: black"/>
    <mspace height="15px" depth="45px" width="30px" style="background: black"/>
    <mprescripts/>
    <mspace height="60px" depth="20px" width="40px" style="background: black"/>
    <mprescripts/>
    <mspace height="25px" depth="75px" width="50px" style="background: black"/>
    <mspace height="35px" depth="105px" width="70px" style="background: black"/>
  </mrow>
</math>
  `);

  return container;
}