Annotation of loncom/html/adm/jsMath/extensions/HTML.js, revision 1.2
1.1 albertel 1: /*
2: * extensions/HTML.js
3: *
4: * Part of the jsMath package for mathematics on the web.
5: *
6: * This file implements a number of HTML-specific extensions to TeX,
7: * including \color, \style, \class, \unicode, etc. It will be loaded
8: * automatically when needed, or can be loaded by
9: *
10: * jsMath.Extension.Require('HTML');
11: *
12: * ---------------------------------------------------------------------
13: *
14: * Copyright 2005-2006 by Davide P. Cervone
15: *
16: * Licensed under the Apache License, Version 2.0 (the "License");
17: * you may not use this file except in compliance with the License.
18: * You may obtain a copy of the License at
19: *
20: * http://www.apache.org/licenses/LICENSE-2.0
21: *
22: * Unless required by applicable law or agreed to in writing, software
23: * distributed under the License is distributed on an "AS IS" BASIS,
24: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25: * See the License for the specific language governing permissions and
26: * limitations under the License.
27: */
28:
29: /********************************************************************/
30:
31: jsMath.Package(jsMath.Parser,{
32:
33: macros: {
34: color: 'Color',
35: href: 'Href',
36: 'class': 'Class',
37: style: 'Style',
38: cssId: 'CSSId',
39: unicode: 'Unicode'
40: },
41:
42: /*
43: * Show the argument in a particular color
44: */
45: Color: function (name) {
46: var color = this.GetArgument(this.cmd+name); if (this.error) return;
47: // check that it looks like a color?
48: this.AddHTML(name,['<span style="color: '+color+'">','</span>']);
49: },
50:
51: /*
52: * Make the argument be a link
53: */
54: Href: function (name) {
55: var href = this.GetArgument(this.cmd+name); if (this.error) return;
56: this.AddHTML(name,['<a class="link" href="'+href+'">','</a>']);
57: },
58:
59: /*
60: * Apply a CSS class to the argument
61: */
62: Class: function (name) {
63: var clss = this.GetArgument(this.cmd+name); if (this.error) return;
64: this.AddHTML(name,['<span class="'+clss+'">','</span>']);
65: },
66:
67: /*
68: * Apply a CSS style to the argument
69: */
70: Style: function (name) {
71: var style = this.GetArgument(this.cmd+name); if (this.error) return;
72: this.AddHTML(name,['<span style="'+style+'">','</span>']);
73: },
74:
75: /*
76: * Add a CSS element ID to the argument
77: */
78: CSSId: function (name) {
79: var id = this.GetArgument(this.cmd+name); if (this.error) return;
80: this.AddHTML(name,['<span id="'+id+'">','</span>']);
81: },
82:
83: /*
84: * Insert some raw HTML around the argument (this will not affect
85: * the spacing or other TeX features)
86: */
87: AddHTML: function (name,params) {
88: var data = this.mlist.data;
89: var arg = this.GetArgument(this.cmd+name); if (this.error) return;
90: arg = jsMath.Parse(arg,data.font,data.size,data.style);
91: if (arg.error) {this.Error(arg); return}
92: this.mlist.Add(jsMath.mItem.HTML(params[0]));
93: for (var i = 0; i < arg.mlist.Length(); i++) {this.mlist.Add(arg.mlist.Get(i))}
94: this.mlist.Add(jsMath.mItem.HTML(params[1]));
95: },
96:
97: /*
98: * Insert a unicode reference as an Ord atom. Its argument should
99: * be the unicode code point, e.g. \unicode{8211}, or \unicode{x203F}.
1.2 ! albertel 100: * You can also specify the height (offset from the x height) and depth
! 101: * in ems, together with a CSS class for the character, e.g.,
! 102: * \unicode{8211,class,.2,-.3}
1.1 albertel 103: */
104: Unicode: function (name) {
105: var arg = this.GetArgument(this.cmd+name); if (this.error) return;
106: arg = arg.split(','); arg[0] = '&#'+arg[0]+';';
107: if (!arg[1]) {arg[1] = 'normal'}
108: this.mlist.Add(jsMath.mItem.TextAtom('ord',arg[0],arg[1],arg[2],arg[3]));
109: }
110:
111: });
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>