Mercurial > repos > public > wdown
comparison katex/contrib/render-a11y-string.js @ 8:4a25b534c81c javascript-experiment
Add v8 engine and include katex
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Wed, 17 Jun 2020 21:43:52 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 7:a5aa39557726 | 8:4a25b534c81c |
|---|---|
| 1 (function webpackUniversalModuleDefinition(root, factory) { | |
| 2 if(typeof exports === 'object' && typeof module === 'object') | |
| 3 module.exports = factory(require("katex")); | |
| 4 else if(typeof define === 'function' && define.amd) | |
| 5 define(["katex"], factory); | |
| 6 else { | |
| 7 var a = typeof exports === 'object' ? factory(require("katex")) : factory(root["katex"]); | |
| 8 for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; | |
| 9 } | |
| 10 })((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE__0__) { | |
| 11 return /******/ (function(modules) { // webpackBootstrap | |
| 12 /******/ // The module cache | |
| 13 /******/ var installedModules = {}; | |
| 14 /******/ | |
| 15 /******/ // The require function | |
| 16 /******/ function __webpack_require__(moduleId) { | |
| 17 /******/ | |
| 18 /******/ // Check if module is in cache | |
| 19 /******/ if(installedModules[moduleId]) { | |
| 20 /******/ return installedModules[moduleId].exports; | |
| 21 /******/ } | |
| 22 /******/ // Create a new module (and put it into the cache) | |
| 23 /******/ var module = installedModules[moduleId] = { | |
| 24 /******/ i: moduleId, | |
| 25 /******/ l: false, | |
| 26 /******/ exports: {} | |
| 27 /******/ }; | |
| 28 /******/ | |
| 29 /******/ // Execute the module function | |
| 30 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | |
| 31 /******/ | |
| 32 /******/ // Flag the module as loaded | |
| 33 /******/ module.l = true; | |
| 34 /******/ | |
| 35 /******/ // Return the exports of the module | |
| 36 /******/ return module.exports; | |
| 37 /******/ } | |
| 38 /******/ | |
| 39 /******/ | |
| 40 /******/ // expose the modules object (__webpack_modules__) | |
| 41 /******/ __webpack_require__.m = modules; | |
| 42 /******/ | |
| 43 /******/ // expose the module cache | |
| 44 /******/ __webpack_require__.c = installedModules; | |
| 45 /******/ | |
| 46 /******/ // define getter function for harmony exports | |
| 47 /******/ __webpack_require__.d = function(exports, name, getter) { | |
| 48 /******/ if(!__webpack_require__.o(exports, name)) { | |
| 49 /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); | |
| 50 /******/ } | |
| 51 /******/ }; | |
| 52 /******/ | |
| 53 /******/ // define __esModule on exports | |
| 54 /******/ __webpack_require__.r = function(exports) { | |
| 55 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | |
| 56 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | |
| 57 /******/ } | |
| 58 /******/ Object.defineProperty(exports, '__esModule', { value: true }); | |
| 59 /******/ }; | |
| 60 /******/ | |
| 61 /******/ // create a fake namespace object | |
| 62 /******/ // mode & 1: value is a module id, require it | |
| 63 /******/ // mode & 2: merge all properties of value into the ns | |
| 64 /******/ // mode & 4: return value when already ns object | |
| 65 /******/ // mode & 8|1: behave like require | |
| 66 /******/ __webpack_require__.t = function(value, mode) { | |
| 67 /******/ if(mode & 1) value = __webpack_require__(value); | |
| 68 /******/ if(mode & 8) return value; | |
| 69 /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | |
| 70 /******/ var ns = Object.create(null); | |
| 71 /******/ __webpack_require__.r(ns); | |
| 72 /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | |
| 73 /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | |
| 74 /******/ return ns; | |
| 75 /******/ }; | |
| 76 /******/ | |
| 77 /******/ // getDefaultExport function for compatibility with non-harmony modules | |
| 78 /******/ __webpack_require__.n = function(module) { | |
| 79 /******/ var getter = module && module.__esModule ? | |
| 80 /******/ function getDefault() { return module['default']; } : | |
| 81 /******/ function getModuleExports() { return module; }; | |
| 82 /******/ __webpack_require__.d(getter, 'a', getter); | |
| 83 /******/ return getter; | |
| 84 /******/ }; | |
| 85 /******/ | |
| 86 /******/ // Object.prototype.hasOwnProperty.call | |
| 87 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | |
| 88 /******/ | |
| 89 /******/ // __webpack_public_path__ | |
| 90 /******/ __webpack_require__.p = ""; | |
| 91 /******/ | |
| 92 /******/ | |
| 93 /******/ // Load entry module and return exports | |
| 94 /******/ return __webpack_require__(__webpack_require__.s = 1); | |
| 95 /******/ }) | |
| 96 /************************************************************************/ | |
| 97 /******/ ([ | |
| 98 /* 0 */ | |
| 99 /***/ (function(module, exports) { | |
| 100 | |
| 101 module.exports = __WEBPACK_EXTERNAL_MODULE__0__; | |
| 102 | |
| 103 /***/ }), | |
| 104 /* 1 */ | |
| 105 /***/ (function(module, __webpack_exports__, __webpack_require__) { | |
| 106 | |
| 107 "use strict"; | |
| 108 __webpack_require__.r(__webpack_exports__); | |
| 109 /* harmony import */ var katex__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0); | |
| 110 /* harmony import */ var katex__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(katex__WEBPACK_IMPORTED_MODULE_0__); | |
| 111 /** | |
| 112 * renderA11yString returns a readable string. | |
| 113 * | |
| 114 * In some cases the string will have the proper semantic math | |
| 115 * meaning,: | |
| 116 * renderA11yString("\\frac{1}{2}"") | |
| 117 * -> "start fraction, 1, divided by, 2, end fraction" | |
| 118 * | |
| 119 * However, other cases do not: | |
| 120 * renderA11yString("f(x) = x^2") | |
| 121 * -> "f, left parenthesis, x, right parenthesis, equals, x, squared" | |
| 122 * | |
| 123 * The commas in the string aim to increase ease of understanding | |
| 124 * when read by a screenreader. | |
| 125 */ | |
| 126 // NOTE: since we're importing types here these files won't actually be | |
| 127 // included in the build. | |
| 128 // $FlowIgnore: we import the types directly anyways | |
| 129 | |
| 130 var stringMap = { | |
| 131 "(": "left parenthesis", | |
| 132 ")": "right parenthesis", | |
| 133 "[": "open bracket", | |
| 134 "]": "close bracket", | |
| 135 "\\{": "left brace", | |
| 136 "\\}": "right brace", | |
| 137 "\\lvert": "open vertical bar", | |
| 138 "\\rvert": "close vertical bar", | |
| 139 "|": "vertical bar", | |
| 140 "\\uparrow": "up arrow", | |
| 141 "\\Uparrow": "up arrow", | |
| 142 "\\downarrow": "down arrow", | |
| 143 "\\Downarrow": "down arrow", | |
| 144 "\\updownarrow": "up down arrow", | |
| 145 "\\leftarrow": "left arrow", | |
| 146 "\\Leftarrow": "left arrow", | |
| 147 "\\rightarrow": "right arrow", | |
| 148 "\\Rightarrow": "right arrow", | |
| 149 "\\langle": "open angle", | |
| 150 "\\rangle": "close angle", | |
| 151 "\\lfloor": "open floor", | |
| 152 "\\rfloor": "close floor", | |
| 153 "\\int": "integral", | |
| 154 "\\intop": "integral", | |
| 155 "\\lim": "limit", | |
| 156 "\\ln": "natural log", | |
| 157 "\\log": "log", | |
| 158 "\\sin": "sine", | |
| 159 "\\cos": "cosine", | |
| 160 "\\tan": "tangent", | |
| 161 "\\cot": "cotangent", | |
| 162 "\\sum": "sum", | |
| 163 "/": "slash", | |
| 164 ",": "comma", | |
| 165 ".": "point", | |
| 166 "-": "negative", | |
| 167 "+": "plus", | |
| 168 "~": "tilde", | |
| 169 ":": "colon", | |
| 170 "?": "question mark", | |
| 171 "'": "apostrophe", | |
| 172 "\\%": "percent", | |
| 173 " ": "space", | |
| 174 "\\ ": "space", | |
| 175 "\\$": "dollar sign", | |
| 176 "\\angle": "angle", | |
| 177 "\\degree": "degree", | |
| 178 "\\circ": "circle", | |
| 179 "\\vec": "vector", | |
| 180 "\\triangle": "triangle", | |
| 181 "\\pi": "pi", | |
| 182 "\\prime": "prime", | |
| 183 "\\infty": "infinity", | |
| 184 "\\alpha": "alpha", | |
| 185 "\\beta": "beta", | |
| 186 "\\gamma": "gamma", | |
| 187 "\\omega": "omega", | |
| 188 "\\theta": "theta", | |
| 189 "\\sigma": "sigma", | |
| 190 "\\lambda": "lambda", | |
| 191 "\\tau": "tau", | |
| 192 "\\Delta": "delta", | |
| 193 "\\delta": "delta", | |
| 194 "\\mu": "mu", | |
| 195 "\\rho": "rho", | |
| 196 "\\nabla": "del", | |
| 197 "\\ell": "ell", | |
| 198 "\\ldots": "dots", | |
| 199 // TODO: add entries for all accents | |
| 200 "\\hat": "hat", | |
| 201 "\\acute": "acute" | |
| 202 }; | |
| 203 var powerMap = { | |
| 204 "prime": "prime", | |
| 205 "degree": "degrees", | |
| 206 "circle": "degrees", | |
| 207 "2": "squared", | |
| 208 "3": "cubed" | |
| 209 }; | |
| 210 var openMap = { | |
| 211 "|": "open vertical bar", | |
| 212 ".": "" | |
| 213 }; | |
| 214 var closeMap = { | |
| 215 "|": "close vertical bar", | |
| 216 ".": "" | |
| 217 }; | |
| 218 var binMap = { | |
| 219 "+": "plus", | |
| 220 "-": "minus", | |
| 221 "\\pm": "plus minus", | |
| 222 "\\cdot": "dot", | |
| 223 "*": "times", | |
| 224 "/": "divided by", | |
| 225 "\\times": "times", | |
| 226 "\\div": "divided by", | |
| 227 "\\circ": "circle", | |
| 228 "\\bullet": "bullet" | |
| 229 }; | |
| 230 var relMap = { | |
| 231 "=": "equals", | |
| 232 "\\approx": "approximately equals", | |
| 233 "≠": "does not equal", | |
| 234 "\\geq": "is greater than or equal to", | |
| 235 "\\ge": "is greater than or equal to", | |
| 236 "\\leq": "is less than or equal to", | |
| 237 "\\le": "is less than or equal to", | |
| 238 ">": "is greater than", | |
| 239 "<": "is less than", | |
| 240 "\\leftarrow": "left arrow", | |
| 241 "\\Leftarrow": "left arrow", | |
| 242 "\\rightarrow": "right arrow", | |
| 243 "\\Rightarrow": "right arrow", | |
| 244 ":": "colon" | |
| 245 }; | |
| 246 var accentUnderMap = { | |
| 247 "\\underleftarrow": "left arrow", | |
| 248 "\\underrightarrow": "right arrow", | |
| 249 "\\underleftrightarrow": "left-right arrow", | |
| 250 "\\undergroup": "group", | |
| 251 "\\underlinesegment": "line segment", | |
| 252 "\\utilde": "tilde" | |
| 253 }; | |
| 254 | |
| 255 var buildString = function buildString(str, type, a11yStrings) { | |
| 256 if (!str) { | |
| 257 return; | |
| 258 } | |
| 259 | |
| 260 var ret; | |
| 261 | |
| 262 if (type === "open") { | |
| 263 ret = str in openMap ? openMap[str] : stringMap[str] || str; | |
| 264 } else if (type === "close") { | |
| 265 ret = str in closeMap ? closeMap[str] : stringMap[str] || str; | |
| 266 } else if (type === "bin") { | |
| 267 ret = binMap[str] || str; | |
| 268 } else if (type === "rel") { | |
| 269 ret = relMap[str] || str; | |
| 270 } else { | |
| 271 ret = stringMap[str] || str; | |
| 272 } // If the text to add is a number and there is already a string | |
| 273 // in the list and the last string is a number then we should | |
| 274 // combine them into a single number | |
| 275 | |
| 276 | |
| 277 if (/^\d+$/.test(ret) && a11yStrings.length > 0 && // TODO(kevinb): check that the last item in a11yStrings is a string | |
| 278 // I think we might be able to drop the nested arrays, which would make | |
| 279 // this easier to type - $FlowFixMe | |
| 280 /^\d+$/.test(a11yStrings[a11yStrings.length - 1])) { | |
| 281 a11yStrings[a11yStrings.length - 1] += ret; | |
| 282 } else if (ret) { | |
| 283 a11yStrings.push(ret); | |
| 284 } | |
| 285 }; | |
| 286 | |
| 287 var buildRegion = function buildRegion(a11yStrings, callback) { | |
| 288 var regionStrings = []; | |
| 289 a11yStrings.push(regionStrings); | |
| 290 callback(regionStrings); | |
| 291 }; | |
| 292 | |
| 293 var handleObject = function handleObject(tree, a11yStrings, atomType) { | |
| 294 // Everything else is assumed to be an object... | |
| 295 switch (tree.type) { | |
| 296 case "accent": | |
| 297 { | |
| 298 buildRegion(a11yStrings, function (a11yStrings) { | |
| 299 buildA11yStrings(tree.base, a11yStrings, atomType); | |
| 300 a11yStrings.push("with"); | |
| 301 buildString(tree.label, "normal", a11yStrings); | |
| 302 a11yStrings.push("on top"); | |
| 303 }); | |
| 304 break; | |
| 305 } | |
| 306 | |
| 307 case "accentUnder": | |
| 308 { | |
| 309 buildRegion(a11yStrings, function (a11yStrings) { | |
| 310 buildA11yStrings(tree.base, a11yStrings, atomType); | |
| 311 a11yStrings.push("with"); | |
| 312 buildString(accentUnderMap[tree.label], "normal", a11yStrings); | |
| 313 a11yStrings.push("underneath"); | |
| 314 }); | |
| 315 break; | |
| 316 } | |
| 317 | |
| 318 case "accent-token": | |
| 319 { | |
| 320 // Used internally by accent symbols. | |
| 321 break; | |
| 322 } | |
| 323 | |
| 324 case "atom": | |
| 325 { | |
| 326 var text = tree.text; | |
| 327 | |
| 328 switch (tree.family) { | |
| 329 case "bin": | |
| 330 { | |
| 331 buildString(text, "bin", a11yStrings); | |
| 332 break; | |
| 333 } | |
| 334 | |
| 335 case "close": | |
| 336 { | |
| 337 buildString(text, "close", a11yStrings); | |
| 338 break; | |
| 339 } | |
| 340 // TODO(kevinb): figure out what should be done for inner | |
| 341 | |
| 342 case "inner": | |
| 343 { | |
| 344 buildString(tree.text, "inner", a11yStrings); | |
| 345 break; | |
| 346 } | |
| 347 | |
| 348 case "open": | |
| 349 { | |
| 350 buildString(text, "open", a11yStrings); | |
| 351 break; | |
| 352 } | |
| 353 | |
| 354 case "punct": | |
| 355 { | |
| 356 buildString(text, "punct", a11yStrings); | |
| 357 break; | |
| 358 } | |
| 359 | |
| 360 case "rel": | |
| 361 { | |
| 362 buildString(text, "rel", a11yStrings); | |
| 363 break; | |
| 364 } | |
| 365 | |
| 366 default: | |
| 367 { | |
| 368 tree.family; | |
| 369 throw new Error("\"" + tree.family + "\" is not a valid atom type"); | |
| 370 } | |
| 371 } | |
| 372 | |
| 373 break; | |
| 374 } | |
| 375 | |
| 376 case "color": | |
| 377 { | |
| 378 var color = tree.color.replace(/katex-/, ""); | |
| 379 buildRegion(a11yStrings, function (regionStrings) { | |
| 380 regionStrings.push("start color " + color); | |
| 381 buildA11yStrings(tree.body, regionStrings, atomType); | |
| 382 regionStrings.push("end color " + color); | |
| 383 }); | |
| 384 break; | |
| 385 } | |
| 386 | |
| 387 case "color-token": | |
| 388 { | |
| 389 // Used by \color, \colorbox, and \fcolorbox but not directly rendered. | |
| 390 // It's a leaf node and has no children so just break. | |
| 391 break; | |
| 392 } | |
| 393 | |
| 394 case "delimsizing": | |
| 395 { | |
| 396 if (tree.delim && tree.delim !== ".") { | |
| 397 buildString(tree.delim, "normal", a11yStrings); | |
| 398 } | |
| 399 | |
| 400 break; | |
| 401 } | |
| 402 | |
| 403 case "genfrac": | |
| 404 { | |
| 405 buildRegion(a11yStrings, function (regionStrings) { | |
| 406 // genfrac can have unbalanced delimiters | |
| 407 var leftDelim = tree.leftDelim, | |
| 408 rightDelim = tree.rightDelim; // NOTE: Not sure if this is a safe assumption | |
| 409 // hasBarLine true -> fraction, false -> binomial | |
| 410 | |
| 411 if (tree.hasBarLine) { | |
| 412 regionStrings.push("start fraction"); | |
| 413 leftDelim && buildString(leftDelim, "open", regionStrings); | |
| 414 buildA11yStrings(tree.numer, regionStrings, atomType); | |
| 415 regionStrings.push("divided by"); | |
| 416 buildA11yStrings(tree.denom, regionStrings, atomType); | |
| 417 rightDelim && buildString(rightDelim, "close", regionStrings); | |
| 418 regionStrings.push("end fraction"); | |
| 419 } else { | |
| 420 regionStrings.push("start binomial"); | |
| 421 leftDelim && buildString(leftDelim, "open", regionStrings); | |
| 422 buildA11yStrings(tree.numer, regionStrings, atomType); | |
| 423 regionStrings.push("over"); | |
| 424 buildA11yStrings(tree.denom, regionStrings, atomType); | |
| 425 rightDelim && buildString(rightDelim, "close", regionStrings); | |
| 426 regionStrings.push("end binomial"); | |
| 427 } | |
| 428 }); | |
| 429 break; | |
| 430 } | |
| 431 | |
| 432 case "kern": | |
| 433 { | |
| 434 // No op: we don't attempt to present kerning information | |
| 435 // to the screen reader. | |
| 436 break; | |
| 437 } | |
| 438 | |
| 439 case "leftright": | |
| 440 { | |
| 441 buildRegion(a11yStrings, function (regionStrings) { | |
| 442 buildString(tree.left, "open", regionStrings); | |
| 443 buildA11yStrings(tree.body, regionStrings, atomType); | |
| 444 buildString(tree.right, "close", regionStrings); | |
| 445 }); | |
| 446 break; | |
| 447 } | |
| 448 | |
| 449 case "leftright-right": | |
| 450 { | |
| 451 // TODO: double check that this is a no-op | |
| 452 break; | |
| 453 } | |
| 454 | |
| 455 case "lap": | |
| 456 { | |
| 457 buildA11yStrings(tree.body, a11yStrings, atomType); | |
| 458 break; | |
| 459 } | |
| 460 | |
| 461 case "mathord": | |
| 462 { | |
| 463 buildString(tree.text, "normal", a11yStrings); | |
| 464 break; | |
| 465 } | |
| 466 | |
| 467 case "op": | |
| 468 { | |
| 469 var body = tree.body, | |
| 470 name = tree.name; | |
| 471 | |
| 472 if (body) { | |
| 473 buildA11yStrings(body, a11yStrings, atomType); | |
| 474 } else if (name) { | |
| 475 buildString(name, "normal", a11yStrings); | |
| 476 } | |
| 477 | |
| 478 break; | |
| 479 } | |
| 480 | |
| 481 case "op-token": | |
| 482 { | |
| 483 // Used internally by operator symbols. | |
| 484 buildString(tree.text, atomType, a11yStrings); | |
| 485 break; | |
| 486 } | |
| 487 | |
| 488 case "ordgroup": | |
| 489 { | |
| 490 buildA11yStrings(tree.body, a11yStrings, atomType); | |
| 491 break; | |
| 492 } | |
| 493 | |
| 494 case "overline": | |
| 495 { | |
| 496 buildRegion(a11yStrings, function (a11yStrings) { | |
| 497 a11yStrings.push("start overline"); | |
| 498 buildA11yStrings(tree.body, a11yStrings, atomType); | |
| 499 a11yStrings.push("end overline"); | |
| 500 }); | |
| 501 break; | |
| 502 } | |
| 503 | |
| 504 case "phantom": | |
| 505 { | |
| 506 a11yStrings.push("empty space"); | |
| 507 break; | |
| 508 } | |
| 509 | |
| 510 case "raisebox": | |
| 511 { | |
| 512 buildA11yStrings(tree.body, a11yStrings, atomType); | |
| 513 break; | |
| 514 } | |
| 515 | |
| 516 case "rule": | |
| 517 { | |
| 518 a11yStrings.push("rectangle"); | |
| 519 break; | |
| 520 } | |
| 521 | |
| 522 case "sizing": | |
| 523 { | |
| 524 buildA11yStrings(tree.body, a11yStrings, atomType); | |
| 525 break; | |
| 526 } | |
| 527 | |
| 528 case "spacing": | |
| 529 { | |
| 530 a11yStrings.push("space"); | |
| 531 break; | |
| 532 } | |
| 533 | |
| 534 case "styling": | |
| 535 { | |
| 536 // We ignore the styling and just pass through the contents | |
| 537 buildA11yStrings(tree.body, a11yStrings, atomType); | |
| 538 break; | |
| 539 } | |
| 540 | |
| 541 case "sqrt": | |
| 542 { | |
| 543 buildRegion(a11yStrings, function (regionStrings) { | |
| 544 var body = tree.body, | |
| 545 index = tree.index; | |
| 546 | |
| 547 if (index) { | |
| 548 var indexString = flatten(buildA11yStrings(index, [], atomType)).join(","); | |
| 549 | |
| 550 if (indexString === "3") { | |
| 551 regionStrings.push("cube root of"); | |
| 552 buildA11yStrings(body, regionStrings, atomType); | |
| 553 regionStrings.push("end cube root"); | |
| 554 return; | |
| 555 } | |
| 556 | |
| 557 regionStrings.push("root"); | |
| 558 regionStrings.push("start index"); | |
| 559 buildA11yStrings(index, regionStrings, atomType); | |
| 560 regionStrings.push("end index"); | |
| 561 return; | |
| 562 } | |
| 563 | |
| 564 regionStrings.push("square root of"); | |
| 565 buildA11yStrings(body, regionStrings, atomType); | |
| 566 regionStrings.push("end square root"); | |
| 567 }); | |
| 568 break; | |
| 569 } | |
| 570 | |
| 571 case "supsub": | |
| 572 { | |
| 573 var base = tree.base, | |
| 574 sub = tree.sub, | |
| 575 sup = tree.sup; | |
| 576 var isLog = false; | |
| 577 | |
| 578 if (base) { | |
| 579 buildA11yStrings(base, a11yStrings, atomType); | |
| 580 isLog = base.type === "op" && base.name === "\\log"; | |
| 581 } | |
| 582 | |
| 583 if (sub) { | |
| 584 var regionName = isLog ? "base" : "subscript"; | |
| 585 buildRegion(a11yStrings, function (regionStrings) { | |
| 586 regionStrings.push("start " + regionName); | |
| 587 buildA11yStrings(sub, regionStrings, atomType); | |
| 588 regionStrings.push("end " + regionName); | |
| 589 }); | |
| 590 } | |
| 591 | |
| 592 if (sup) { | |
| 593 buildRegion(a11yStrings, function (regionStrings) { | |
| 594 var supString = flatten(buildA11yStrings(sup, [], atomType)).join(","); | |
| 595 | |
| 596 if (supString in powerMap) { | |
| 597 regionStrings.push(powerMap[supString]); | |
| 598 return; | |
| 599 } | |
| 600 | |
| 601 regionStrings.push("start superscript"); | |
| 602 buildA11yStrings(sup, regionStrings, atomType); | |
| 603 regionStrings.push("end superscript"); | |
| 604 }); | |
| 605 } | |
| 606 | |
| 607 break; | |
| 608 } | |
| 609 | |
| 610 case "text": | |
| 611 { | |
| 612 // TODO: handle other fonts | |
| 613 if (tree.font === "\\textbf") { | |
| 614 buildRegion(a11yStrings, function (regionStrings) { | |
| 615 regionStrings.push("start bold text"); | |
| 616 buildA11yStrings(tree.body, regionStrings, atomType); | |
| 617 regionStrings.push("end bold text"); | |
| 618 }); | |
| 619 break; | |
| 620 } | |
| 621 | |
| 622 buildRegion(a11yStrings, function (regionStrings) { | |
| 623 regionStrings.push("start text"); | |
| 624 buildA11yStrings(tree.body, regionStrings, atomType); | |
| 625 regionStrings.push("end text"); | |
| 626 }); | |
| 627 break; | |
| 628 } | |
| 629 | |
| 630 case "textord": | |
| 631 { | |
| 632 buildString(tree.text, atomType, a11yStrings); | |
| 633 break; | |
| 634 } | |
| 635 | |
| 636 case "smash": | |
| 637 { | |
| 638 buildA11yStrings(tree.body, a11yStrings, atomType); | |
| 639 break; | |
| 640 } | |
| 641 | |
| 642 case "enclose": | |
| 643 { | |
| 644 // TODO: create a map for these. | |
| 645 // TODO: differentiate between a body with a single atom, e.g. | |
| 646 // "cancel a" instead of "start cancel, a, end cancel" | |
| 647 if (/cancel/.test(tree.label)) { | |
| 648 buildRegion(a11yStrings, function (regionStrings) { | |
| 649 regionStrings.push("start cancel"); | |
| 650 buildA11yStrings(tree.body, regionStrings, atomType); | |
| 651 regionStrings.push("end cancel"); | |
| 652 }); | |
| 653 break; | |
| 654 } else if (/box/.test(tree.label)) { | |
| 655 buildRegion(a11yStrings, function (regionStrings) { | |
| 656 regionStrings.push("start box"); | |
| 657 buildA11yStrings(tree.body, regionStrings, atomType); | |
| 658 regionStrings.push("end box"); | |
| 659 }); | |
| 660 break; | |
| 661 } else if (/sout/.test(tree.label)) { | |
| 662 buildRegion(a11yStrings, function (regionStrings) { | |
| 663 regionStrings.push("start strikeout"); | |
| 664 buildA11yStrings(tree.body, regionStrings, atomType); | |
| 665 regionStrings.push("end strikeout"); | |
| 666 }); | |
| 667 break; | |
| 668 } | |
| 669 | |
| 670 throw new Error("KaTeX-a11y: enclose node with " + tree.label + " not supported yet"); | |
| 671 } | |
| 672 | |
| 673 case "vphantom": | |
| 674 { | |
| 675 throw new Error("KaTeX-a11y: vphantom not implemented yet"); | |
| 676 } | |
| 677 | |
| 678 case "hphantom": | |
| 679 { | |
| 680 throw new Error("KaTeX-a11y: hphantom not implemented yet"); | |
| 681 } | |
| 682 | |
| 683 case "operatorname": | |
| 684 { | |
| 685 buildA11yStrings(tree.body, a11yStrings, atomType); | |
| 686 break; | |
| 687 } | |
| 688 | |
| 689 case "array": | |
| 690 { | |
| 691 throw new Error("KaTeX-a11y: array not implemented yet"); | |
| 692 } | |
| 693 | |
| 694 case "raw": | |
| 695 { | |
| 696 throw new Error("KaTeX-a11y: raw not implemented yet"); | |
| 697 } | |
| 698 | |
| 699 case "size": | |
| 700 { | |
| 701 // Although there are nodes of type "size" in the parse tree, they have | |
| 702 // no semantic meaning and should be ignored. | |
| 703 break; | |
| 704 } | |
| 705 | |
| 706 case "url": | |
| 707 { | |
| 708 throw new Error("KaTeX-a11y: url not implemented yet"); | |
| 709 } | |
| 710 | |
| 711 case "tag": | |
| 712 { | |
| 713 throw new Error("KaTeX-a11y: tag not implemented yet"); | |
| 714 } | |
| 715 | |
| 716 case "verb": | |
| 717 { | |
| 718 buildString("start verbatim", "normal", a11yStrings); | |
| 719 buildString(tree.body, "normal", a11yStrings); | |
| 720 buildString("end verbatim", "normal", a11yStrings); | |
| 721 break; | |
| 722 } | |
| 723 | |
| 724 case "environment": | |
| 725 { | |
| 726 throw new Error("KaTeX-a11y: environment not implemented yet"); | |
| 727 } | |
| 728 | |
| 729 case "horizBrace": | |
| 730 { | |
| 731 buildString("start " + tree.label.slice(1), "normal", a11yStrings); | |
| 732 buildA11yStrings(tree.base, a11yStrings, atomType); | |
| 733 buildString("end " + tree.label.slice(1), "normal", a11yStrings); | |
| 734 break; | |
| 735 } | |
| 736 | |
| 737 case "infix": | |
| 738 { | |
| 739 // All infix nodes are replace with other nodes. | |
| 740 break; | |
| 741 } | |
| 742 | |
| 743 case "includegraphics": | |
| 744 { | |
| 745 throw new Error("KaTeX-a11y: includegraphics not implemented yet"); | |
| 746 } | |
| 747 | |
| 748 case "font": | |
| 749 { | |
| 750 // TODO: callout the start/end of specific fonts | |
| 751 // TODO: map \BBb{N} to "the naturals" or something like that | |
| 752 buildA11yStrings(tree.body, a11yStrings, atomType); | |
| 753 break; | |
| 754 } | |
| 755 | |
| 756 case "href": | |
| 757 { | |
| 758 throw new Error("KaTeX-a11y: href not implemented yet"); | |
| 759 } | |
| 760 | |
| 761 case "cr": | |
| 762 { | |
| 763 // This is used by environments. | |
| 764 throw new Error("KaTeX-a11y: cr not implemented yet"); | |
| 765 } | |
| 766 | |
| 767 case "underline": | |
| 768 { | |
| 769 buildRegion(a11yStrings, function (a11yStrings) { | |
| 770 a11yStrings.push("start underline"); | |
| 771 buildA11yStrings(tree.body, a11yStrings, atomType); | |
| 772 a11yStrings.push("end underline"); | |
| 773 }); | |
| 774 break; | |
| 775 } | |
| 776 | |
| 777 case "xArrow": | |
| 778 { | |
| 779 throw new Error("KaTeX-a11y: xArrow not implemented yet"); | |
| 780 } | |
| 781 | |
| 782 case "mclass": | |
| 783 { | |
| 784 // \neq and \ne are macros so we let "htmlmathml" render the mathmal | |
| 785 // side of things and extract the text from that. | |
| 786 var _atomType = tree.mclass.slice(1); // $FlowFixMe: drop the leading "m" from the values in mclass | |
| 787 | |
| 788 | |
| 789 buildA11yStrings(tree.body, a11yStrings, _atomType); | |
| 790 break; | |
| 791 } | |
| 792 | |
| 793 case "mathchoice": | |
| 794 { | |
| 795 // TODO: track which which style we're using, e.g. dispaly, text, etc. | |
| 796 // default to text style if even that may not be the correct style | |
| 797 buildA11yStrings(tree.text, a11yStrings, atomType); | |
| 798 break; | |
| 799 } | |
| 800 | |
| 801 case "htmlmathml": | |
| 802 { | |
| 803 buildA11yStrings(tree.mathml, a11yStrings, atomType); | |
| 804 break; | |
| 805 } | |
| 806 | |
| 807 case "middle": | |
| 808 { | |
| 809 buildString(tree.delim, atomType, a11yStrings); | |
| 810 break; | |
| 811 } | |
| 812 | |
| 813 default: | |
| 814 tree.type; | |
| 815 throw new Error("KaTeX a11y un-recognized type: " + tree.type); | |
| 816 } | |
| 817 }; | |
| 818 | |
| 819 var buildA11yStrings = function buildA11yStrings(tree, a11yStrings, atomType) { | |
| 820 if (a11yStrings === void 0) { | |
| 821 a11yStrings = []; | |
| 822 } | |
| 823 | |
| 824 if (tree instanceof Array) { | |
| 825 for (var i = 0; i < tree.length; i++) { | |
| 826 buildA11yStrings(tree[i], a11yStrings, atomType); | |
| 827 } | |
| 828 } else { | |
| 829 handleObject(tree, a11yStrings, atomType); | |
| 830 } | |
| 831 | |
| 832 return a11yStrings; | |
| 833 }; | |
| 834 | |
| 835 var flatten = function flatten(array) { | |
| 836 var result = []; | |
| 837 array.forEach(function (item) { | |
| 838 if (item instanceof Array) { | |
| 839 result = result.concat(flatten(item)); | |
| 840 } else { | |
| 841 result.push(item); | |
| 842 } | |
| 843 }); | |
| 844 return result; | |
| 845 }; | |
| 846 | |
| 847 var renderA11yString = function renderA11yString(text, settings) { | |
| 848 var tree = katex__WEBPACK_IMPORTED_MODULE_0___default.a.__parse(text, settings); | |
| 849 | |
| 850 var a11yStrings = buildA11yStrings(tree, [], "normal"); | |
| 851 return flatten(a11yStrings).join(", "); | |
| 852 }; | |
| 853 | |
| 854 /* harmony default export */ __webpack_exports__["default"] = (renderA11yString); | |
| 855 | |
| 856 /***/ }) | |
| 857 /******/ ])["default"]; | |
| 858 }); |
