Debian Codegraph @

unpacked/extensions/TeX/HTML.js

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