HTML.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
  2. /* vim: set ts=2 et sw=2 tw=80: */
  3. /*************************************************************
  4. *
  5. * MathJax/extensions/TeX/HTML.js
  6. *
  7. * Implements the \href, \class, \style, \cssId macros.
  8. *
  9. * ---------------------------------------------------------------------
  10. *
  11. * Copyright (c) 2010-2013 The MathJax Consortium
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License");
  14. * you may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. MathJax.Extension["TeX/HTML"] = {
  26. version: "2.2"
  27. };
  28. MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
  29. var TEX = MathJax.InputJax.TeX;
  30. var TEXDEF = TEX.Definitions;
  31. TEXDEF.Add({
  32. macros: {
  33. href: 'HREF_attribute',
  34. "class": 'CLASS_attribute',
  35. style: 'STYLE_attribute',
  36. cssId: 'ID_attribute'
  37. }
  38. },null,true);
  39. TEX.Parse.Augment({
  40. //
  41. // Implements \href{url}{math}
  42. //
  43. HREF_attribute: function (name) {
  44. var url = this.GetArgument(name),
  45. arg = this.GetArgumentMML(name);
  46. this.Push(arg.With({href:url}));
  47. },
  48. //
  49. // Implements \class{name}{math}
  50. //
  51. CLASS_attribute: function (name) {
  52. var CLASS = this.GetArgument(name),
  53. arg = this.GetArgumentMML(name);
  54. if (arg["class"] != null) {CLASS = arg["class"] + " " + CLASS}
  55. this.Push(arg.With({"class":CLASS}));
  56. },
  57. //
  58. // Implements \style{style-string}{math}
  59. //
  60. STYLE_attribute: function (name) {
  61. var style = this.GetArgument(name),
  62. arg = this.GetArgumentMML(name);
  63. // check that it looks like a style string
  64. if (arg.style != null) {
  65. if (style.charAt(style.length-1) !== ";") {style += ";"}
  66. style = arg.style + " " + style;
  67. }
  68. this.Push(arg.With({style: style}));
  69. },
  70. //
  71. // Implements \cssId{id}{math}
  72. //
  73. ID_attribute: function (name) {
  74. var ID = this.GetArgument(name),
  75. arg = this.GetArgumentMML(name);
  76. this.Push(arg.With({id:ID}));
  77. },
  78. //
  79. // returns an argument that is a single MathML element
  80. // (in an mrow if necessary)
  81. //
  82. GetArgumentMML: function (name) {
  83. var arg = this.ParseArg(name);
  84. if (arg.inferred && arg.data.length == 1)
  85. {arg = arg.data[0]} else {delete arg.inferred}
  86. return arg;
  87. }
  88. });
  89. MathJax.Hub.Startup.signal.Post("TeX HTML Ready");
  90. });
  91. MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/HTML.js");