tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mathml-fragments.js (5958B)


      1 var MathMLFragments = {
      2    "annotation": "\
      3 <semantics>\
      4  <mrow></mrow>\
      5  <annotation class='element text-container'></annotation>\
      6 </semantics>",
      7    "annotation-xml": "\
      8 <semantics>\
      9  <mrow></mrow>\
     10  <annotation-xml class='element text-container foreign-container'></annotation-xml>\
     11 </semantics>",
     12    "maction": "\
     13 <maction class='element' actiontype='statusline'>\
     14  <mrow class='mathml-container'></mrow>\
     15  <mtext class='text-container'></mtext>\
     16 </maction>",
     17    "menclose": "<menclose class='element mathml-container'></menclose>",
     18    "merror": "<merror class='element mathml-container'></merror>",
     19    "mfrac": "\
     20 <mfrac class='element'>\
     21  <mrow class='mathml-container'></mrow>\
     22  <mrow class='mathml-container'></mrow>\
     23 </mfrac>",
     24    "mi": "<mi class='element text-container foreign-container'></mi>",
     25    "mmultiscripts": "\
     26 <mmultiscripts class='element'>\
     27  <mrow class='mathml-container'></mrow>\
     28  <mrow class='mathml-container'></mrow>\
     29  <mrow class='mathml-container'></mrow>\
     30 </mmultiscripts>",
     31    "mn": "<mn class='element text-container foreign-container'></mn>",
     32    "mo": "<mo class='element text-container foreign-container'></mo>",
     33    "mover": "\
     34 <mover class='element'>\
     35  <mrow class='mathml-container'></mrow>\
     36  <mrow class='mathml-container'></mrow>\
     37 </mover>",
     38    "mpadded": "<mpadded class='element mathml-container'></mpadded>",
     39    "mphantom": "<mphantom class='element mathml-container'></mphantom>",
     40    "mprescripts": "\
     41 <mmultiscripts>\
     42  <mrow class='mathml-container'></mrow>\
     43  <mprescripts class='element'/>\
     44  <mrow class='mathml-container'></mrow>\
     45  <mrow class='mathml-container'></mrow>\
     46 </mmultiscripts>",
     47    "mroot": "\
     48 <mroot class='element'>\
     49  <mrow class='mathml-container'></mrow>\
     50  <mrow class='mathml-container'></mrow>\
     51 </mroot>",
     52    "mrow": "<mrow class='element mathml-container'></mrow>",
     53    "ms": "<ms class='element text-container foreign-container'></ms>",
     54    "mspace": "<mspace class='element'></mspace>",
     55    "msqrt": "<msqrt class='element mathml-container'></msqrt>",
     56    "mstyle": "<mstyle class='element mathml-container'></mstyle>",
     57    "msub": "\
     58 <msub class='element'>\
     59  <mrow class='mathml-container'></mrow>\
     60  <mrow class='mathml-container'></mrow>\
     61 </msub>",
     62    "msubsup": "\
     63 <msubsup class='element'>\
     64  <mrow class='mathml-container'></mrow>\
     65  <mrow class='mathml-container'></mrow>\
     66  <mrow class='mathml-container'></mrow>\
     67 </msubsup>",
     68    "msup": "\
     69 <msup class='element'>\
     70  <mrow class='mathml-container'></mrow>\
     71  <mrow class='mathml-container'></mrow>\
     72 </msup>",
     73    "mtable": "\
     74 <mtable class='element'>\
     75  <mtr>\
     76    <mtd class='mathml-container'>\
     77    </mtd>\
     78  </mtr>\
     79 </mtable>",
     80    "mtd": "\
     81 <mtable>\
     82  <mtr>\
     83    <mtd class='element mathml-container'>\
     84    </mtd>\
     85  </mtr>\
     86 </mtable>",
     87    "mtext": "<mtext class='element text-container foreign-container'></mtext>",
     88    "mtr": "\
     89 <mtable>\
     90  <mtr class='element'>\
     91    <mtd class='mathml-container'>\
     92    </mtd>\
     93  </mtr>\
     94 </mtable>",
     95    "munder": "\
     96 <munder class='element'>\
     97  <mrow class='mathml-container'></mrow>\
     98  <mrow class='mathml-container'></mrow>\
     99 </munder>",
    100    "munderover": "\
    101 <munderover class='element'>\
    102  <mrow class='mathml-container'></mrow>\
    103  <mrow class='mathml-container'></mrow>\
    104  <mrow class='mathml-container'></mrow>\
    105 </munderover>",
    106    "none": "\
    107 <mmultiscripts>\
    108  <mrow class='mathml-container'></mrow>\
    109  <none class='element'/>\
    110  <mrow class='mathml-container'></mrow>\
    111 </mmultiscripts>",
    112    "semantics": "\
    113 <semantics class='element'>\
    114  <mrow class='mathml-container'></mrow>\
    115  <annotation class='text-container'></annotation>\
    116 </semantics>"
    117 };
    118 
    119 var FragmentHelper = {
    120    mathml_namespace: "http://www.w3.org/1998/Math/MathML",
    121 
    122    createElement: function(tag) {
    123        return document.createElementNS(this.mathml_namespace, tag);
    124    },
    125 
    126    isValidChildOfMrow: function(tag) {
    127        return !(tag == "annotation" ||
    128                 tag == "annotation-xml" ||
    129                 tag == "mprescripts" ||
    130                 tag == "none" ||
    131                 tag == "mtr" ||
    132                 tag == "mtd");
    133    },
    134 
    135    isTokenElement: function(tag) {
    136        return (tag == "mi" ||
    137                tag == "mtext" ||
    138                tag == "mo" ||
    139                tag == "mn" ||
    140                tag == "ms")
    141    },
    142 
    143    isEmpty: function(tag) {
    144        return tag === "mspace" || tag == "mprescripts" || tag == "none";
    145    },
    146 
    147    element: function(fragment) {
    148        return fragment.getElementsByClassName('element')[0];
    149    },
    150 
    151    appendChild: function(fragment, allowInvalid) {
    152        var element = this.element(fragment) || fragment;
    153        if (element.classList.contains("foreign-container")) {
    154            var el = document.createElement("span");
    155            el.textContent = "a";
    156            return element.appendChild(el);
    157        }
    158        if (element.classList.contains("mathml-container") || allowInvalid) {
    159            var el = this.createElement("mtext");
    160            el.textContent = "a";
    161            return element.appendChild(el);
    162        }
    163        throw "Cannot append child to the element";
    164    },
    165 
    166    forceNonEmptyElement: function(fragment) {
    167        var element = this.element(fragment) || fragment;
    168        if (element.firstElementChild)
    169            return element.firstElementChild;
    170        return this.appendChild(fragment);
    171    },
    172 
    173    forceNonEmptyDescendants: function(fragment) {
    174        var element = this.element(fragment) || fragment;
    175        if (element.classList.contains("mathml-container") ||
    176            element.classList.contains("foreign-container")) {
    177            for (var i = 0; i < 10; i++)
    178                this.appendChild(element);
    179            return;
    180        }
    181        var child = element.firstElementChild;
    182        if (child) {
    183            for (; child; child = child.nextElementSibling) {
    184                this.forceNonEmptyDescendants(child);
    185            }
    186            return;
    187        }
    188    },
    189 }