render-a11y-string.js 24 KB

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