ms.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/jax/output/SVG/autoload/ms.js
  6. *
  7. * Implements the SVG output for <ms> elements.
  8. *
  9. * ---------------------------------------------------------------------
  10. *
  11. * Copyright (c) 2011-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.Hub.Register.StartupHook("SVG Jax Ready",function () {
  26. var VERSION = "2.2";
  27. var MML = MathJax.ElementJax.mml,
  28. SVG = MathJax.OutputJax.SVG;
  29. MML.ms.Augment({
  30. toSVG: function () {
  31. this.SVGgetStyles();
  32. var svg = this.SVG(); this.SVGhandleSpace(svg);
  33. var values = this.getValues("lquote","rquote");
  34. var variant = this.SVGgetVariant(), scale = this.SVGgetScale();
  35. var text = this.data.join(""); // FIXME: handle mglyph?
  36. var pattern = [];
  37. if (values.lquote.length === 1) {pattern.push(this.SVGquoteRegExp(values.lquote))}
  38. if (values.rquote.length === 1) {pattern.push(this.SVGquoteRegExp(values.rquote))}
  39. if (pattern.length) {text = text.replace(RegExp("("+pattern.join("|")+")","g"),"\\$1")}
  40. svg.Add(this.SVGhandleVariant(variant,scale,values.lquote+text+values.rquote));
  41. svg.Clean();
  42. this.SVGhandleColor(svg);
  43. this.SVGsaveData(svg);
  44. return svg;
  45. },
  46. SVGquoteRegExp: function (string) {
  47. return string.replace(/([.*+?|{}()\[\]\\])/g,"\\$1");
  48. }
  49. });
  50. MML.ms.prototype.defaults.mathvariant = 'monospace';
  51. MathJax.Hub.Startup.signal.Post("SVG ms Ready");
  52. MathJax.Ajax.loadComplete(SVG.autoloadDir+"/ms.js");
  53. });