invalid-markup.js (3840B)
1 // This is a helper for generating invalid MathML markup. 2 // Depends on ./mathml-fragments.js 3 4 function isValid(tagName, mspaceCount) { 5 switch (tagName) { 6 case "mfrac": 7 case "mroot": 8 case "munder": 9 case "mover": 10 case "msub": 11 case "msup": 12 return mspaceCount == 2; 13 case "munderover": 14 case "msubsup": 15 return mspaceCount == 3; 16 case "mmultiscripts": 17 return mspaceCount % 2 == 1; 18 } 19 } 20 21 function generateInvalidMarkup() { 22 let container = document.createElement("div"); 23 ["mfrac", "mroot", "munder", "mover", "munderover", "msub", "msup", "msubsup", "mmultiscripts"].forEach(tag => { 24 let math = FragmentHelper.createElement("math"); 25 let element = FragmentHelper.createElement(tag); 26 let reference = FragmentHelper.createElement("mrow"); 27 math.appendChild(element); 28 math.appendChild(reference); 29 let maxCount = tag == "mmultiscripts" ? 10 : 5; 30 let mspaceCount = 0; 31 for (let count = 0; count <= maxCount; count++) { 32 element.dataset.description = `count == ${count}`; 33 if (!isValid(tag, mspaceCount)) { 34 container.appendChild(math.cloneNode(true)); 35 } 36 if (tag == "mmultiscripts" && count == maxCount / 2) { 37 [element, reference].forEach(el => { 38 el.insertAdjacentHTML("beforeend", `<mprescripts/>`); 39 }); 40 } else { 41 let width = (count + 1) * 10; 42 let height = (count + 1) * (count % 2 ? 15 : 5); 43 let depth = (count + 1) * (count % 2 ? 5 : 15); 44 [element, reference].forEach(el => { 45 el.insertAdjacentHTML("beforeend", `<mspace height="${height}px" depth="${depth}px" width="${width}px" style="background: black"/>`); 46 }); 47 mspaceCount++; 48 } 49 } 50 }); 51 52 container.insertAdjacentHTML("beforeend", ` 53 <math> 54 <mmultiscripts data-description="first in-flow child is an <mprescripts>"> 55 <mprescripts/> 56 <mspace height="5px" depth="15px" width="10px" style="background: black"/> 57 <mspace height="30px" depth="10px" width="20px" style="background: black"/> 58 <mspace height="15px" depth="45px" width="30px" style="background: black"/> 59 <mspace height="60px" depth="20px" width="40px" style="background: black"/> 60 61 </mmultiscripts> 62 <mrow> 63 <mprescripts/> 64 <mspace height="5px" depth="15px" width="10px" style="background: black"/> 65 <mspace height="30px" depth="10px" width="20px" style="background: black"/> 66 <mspace height="15px" depth="45px" width="30px" style="background: black"/> 67 <mspace height="60px" depth="20px" width="40px" style="background: black"/> 68 69 </mrow> 70 </math> 71 <math> 72 <mmultiscripts data-description="one of the even number of children after the first <mprescripts> is an <mprescripts>"> 73 <mspace height="5px" depth="15px" width="10px" style="background: black"/> 74 <mspace height="30px" depth="10px" width="20px" style="background: black"/> 75 <mspace height="15px" depth="45px" width="30px" style="background: black"/> 76 <mprescripts/> 77 <mspace height="60px" depth="20px" width="40px" style="background: black"/> 78 <mprescripts/> 79 <mspace height="25px" depth="75px" width="50px" style="background: black"/> 80 <mspace height="35px" depth="105px" width="70px" style="background: black"/> 81 </mmultiscripts> 82 <mrow> 83 <mspace height="5px" depth="15px" width="10px" style="background: black"/> 84 <mspace height="30px" depth="10px" width="20px" style="background: black"/> 85 <mspace height="15px" depth="45px" width="30px" style="background: black"/> 86 <mprescripts/> 87 <mspace height="60px" depth="20px" width="40px" style="background: black"/> 88 <mprescripts/> 89 <mspace height="25px" depth="75px" width="50px" style="background: black"/> 90 <mspace height="35px" depth="105px" width="70px" style="background: black"/> 91 </mrow> 92 </math> 93 `); 94 95 return container; 96 }