asciimath.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*************************************************************
  2. *
  3. * Copyright (c) 2017-2022 The MathJax Consortium
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @fileoverview Implements the AsciiMath InputJax object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {AbstractInputJax} from '../core/InputJax.js';
  23. import {LegacyAsciiMath} from './asciimath/mathjax2/input/AsciiMath.js';
  24. import {separateOptions, OptionList} from '../util/Options.js';
  25. import {MathDocument} from '../core/MathDocument.js';
  26. import {MathItem} from '../core/MathItem.js';
  27. import {FindAsciiMath} from './asciimath/FindAsciiMath.js';
  28. /*****************************************************************/
  29. /**
  30. * Implements the AsciiMath class (extends AbstractInputJax)
  31. *
  32. * @template N The HTMLElement node class
  33. * @template T The Text node class
  34. * @template D The Document class
  35. */
  36. export class AsciiMath<N, T, D> extends AbstractInputJax<N, T, D> {
  37. /**
  38. * The name of the input jax
  39. */
  40. public static NAME: string = 'AsciiMath';
  41. /**
  42. * @override
  43. */
  44. public static OPTIONS: OptionList = {
  45. ...AbstractInputJax.OPTIONS,
  46. FindAsciiMath: null
  47. };
  48. /**
  49. * The FindMath object used to search for AsciiMath in the document
  50. */
  51. protected findAsciiMath: FindAsciiMath<N, T, D>;
  52. /**
  53. * @override
  54. */
  55. constructor(options: OptionList) {
  56. let [ , find, am] = separateOptions(options, FindAsciiMath.OPTIONS, AsciiMath.OPTIONS);
  57. super(am);
  58. this.findAsciiMath = this.options['FindAsciiMath'] || new FindAsciiMath(find);
  59. }
  60. /**
  61. * Use legacy AsciiMath input jax for now
  62. *
  63. * @override
  64. */
  65. public compile(math: MathItem<N, T, D>, _document: MathDocument<N, T, D>) {
  66. return LegacyAsciiMath.Compile(math.math, math.display);
  67. }
  68. /**
  69. * @override
  70. */
  71. public findMath(strings: string[]) {
  72. return this.findAsciiMath.findMath(strings);
  73. }
  74. }