1 /* This work is licensed under Creative Commons GNU LGPL License.
3 License: http://creativecommons.org/licenses/LGPL/2.1/
5 Author: Stefan Goessner/2005-06
6 Web: http://goessner.net/
7 inspired by: http://xml-maiden.com/
12 // { rex:/[ ]/g, tmplt:"`"}, // omit due to charset support ie6
13 { rex:/\+\-/g, tmplt:"±"},
14 { rex:/\/O|\\Oslash/g, tmplt:"Ø"},
15 { rex:/\/o|\\oslash/g, tmplt:"ø"},
16 { rex:/<->|\\harr/g, tmplt:"↔"},
17 { rex:/<-|\\larr/g, tmplt:"←"},
18 { rex:/->|\\rarr/g, tmplt:"→"},
19 { rex:/<=>|\\hArr/g, tmplt:"⇔"},
20 { rex:/=>|\\rArr/g, tmplt:"⇒"},
21 { rex:/-=|\\equiv/g, tmplt:"≡"},
22 { rex:/<=|\\le/g, tmplt:"≤"},
23 { rex:/>=|\\ge/g, tmplt:"≥"},
24 { rex:/</g, tmplt:"<"},
25 { rex:/>/g, tmplt:">"}
28 { rex:/\*|\\middot/g, tmplt:"·"},
29 { rex:/\\x|\\times/g, tmplt:"×"},
30 { rex:/~=|\\cong/g, tmplt:"≅"},
31 { rex:/~~|\\asymp/g, tmplt:"≈"},
32 { rex:/~|\\sim/g, tmplt:"∼"},
33 { rex:/!=|\\neq|\\ne/g, tmplt:"≠"},
34 { rex:/\.\.\.|\\ldots/g, tmplt:"…"},
35 { rex:/\\in|\\isin/g, tmplt:"∈"},
36 { rex:/([0-9])x([0-9])/g, tmplt:"$1×$2"},
37 { rex:/([A-Za-z]) x ([A-Za-z])/g, tmplt:"$1×$2"},
38 // { rex:/[`]{4}/g, tmplt:" "}, // omit due to charset support ie6
39 // { rex:/[`]{3}/g, tmplt:" "},
40 // { rex:/[`]{2}/g, tmplt:" "},
41 // { rex:/[`]/g, tmplt:" "},
42 { rex:/\{/g, tmplt:"‎"}, // unvisible left-to-right mark,
43 { rex:/\}/g, tmplt:"‏"} // unvisible right-to-left mark,
46 { rex:/\^\^/g, tmplt:"^^"}, // ^ overindex
47 { rex:/(\\sum|\\prod|\\int)_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"o\"><span class=\"x\">$3</span>$1<span class=\"x\">$2</span></span>"}, // over-/underscript (\sum, \prod, \int)
48 { rex:/(\\sum|\\prod|\\int)\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"o\"><span class=\"x\">$2</span>$1<span> </span></span>"},
49 { rex:/(\\sum|\\prod|\\int)_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"o\"><span> </span>$1<span class=\"x\">$2</span></span>"},
50 { rex:/_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"s\"><span class=\"i\">$2</span><span class=\"i\">$1</span></span>"}, // over-/underindex
51 { rex:/\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<sup class=\"i\">$1</sup>"}, // overindex
52 { rex:/_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<sub class=\"i\">$1</sub>"}, // underindex
53 { rex:/-/g, tmplt:"−"},
54 { rex:/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"f\"><span class=\"n\">$1</span><span class=\"d\">$2</span></span>"}, // fraction
55 { rex:/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\/\/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<sup>$1</sup>⁄<sub>$2</sub>"}, // fraction
56 { rex:/\[((\[(([^,\]]+[,]){1,}[^\]]+)\][ \n]*){1,})\]/g, tmplt:function($0,$1){var m=Wiky.math.transpose($1.replace(/(^\[|\]$)/g,"").replace(/(\][ \n]*\[)/g,"|").split("|")),sz=" style=\"font-size:"+(m.len)+"00%;\"";/*alert("{("+m.mat.join(")}\n{(").split(",").join(")(")+")}");*/ return "<span class=\"lb\""+sz+">"+Wiky.math.fence()+"</span><span class=\"m\"><span class=\"e\">"+m.mat.join("</span></span>\n<span class=\"m\"><span class=\"e\">").split(",").join("</span><span class=\"e\">")+"</span></span><span class=\"rb\""+sz+">"+Wiky.math.fence()+"</span>";}}, // matrix
57 { rex:/\[((?:[^,\]]){1,}[^\]]+)\]/g, tmplt:function($0,$1){var v=$1.split(","),sz=" style=\"font-size:"+v.length+"00%;\""; return "<span class=\"lb\""+sz+">"+Wiky.math.fence()+"</span><span class=\"v\"><span class=\"e\">"+v.join("</span><span class=\"e\">")+"</span></span><span class=\"rb\""+sz+">"+Wiky.math.fence()+"</span>";}}, // vector
58 { rex:/!([a-zA-Z0-9\.&;]+)/g, tmplt:"<span class=\"b\">$1</span>" }, // bold vector symbol ..
59 { rex:/\\prod/g, tmplt:"<span class=\"h\">∏</span>"},
60 { rex:/\\sum/g, tmplt:"<span class=\"h\">∑</span>"},
61 { rex:/\\int/g, tmplt:"<span class=\"h\">∫</span>"},
62 "Wiky.rules.math.postshortcuts"
65 { rex:/\\Alpha/g, tmplt:"Α"},
66 { rex:/\\Beta/g, tmplt:"Β"},
67 { rex:/\\Gamma/g, tmplt:"Γ"},
68 { rex:/\\Delta/g, tmplt:"Δ"},
69 { rex:/\\Epsilon/g, tmplt:"Ε"},
70 { rex:/\\Zeta/g, tmplt:"Ζ"},
71 { rex:/\\Eta/g, tmplt:"Η"},
72 { rex:/\\Theta/g, tmplt:"Θ"},
73 { rex:/\\Iota/g, tmplt:"Ι"},
74 { rex:/\\Kappa/g, tmplt:"Κ"},
75 { rex:/\\Lambda/g, tmplt:"Λ"},
76 { rex:/\\Mu/g, tmplt:"Μ"},
77 { rex:/\\Nu/g, tmplt:"Ν"},
78 { rex:/\\Xi/g, tmplt:"Ξ"},
79 { rex:/\\Omicron/g, tmplt:"Ο"},
80 { rex:/\\Pi/g, tmplt:"Π"},
81 { rex:/\\Rho/g, tmplt:"Ρ"},
82 { rex:/\\Sigma/g, tmplt:"Σ"},
83 { rex:/\\Tau/g, tmplt:"Τ"},
84 { rex:/\\Upsilon/g, tmplt:"Υ"},
85 { rex:/\\Phi/g, tmplt:"Φ"},
86 { rex:/\\Chi/g, tmplt:"Χ"},
87 { rex:/\\Psi/g, tmplt:"Ψ"},
88 { rex:/\\Omega/g, tmplt:"Ω"},
89 { rex:/\\alpha/g, tmplt:"α"},
90 { rex:/\\beta/g, tmplt:"β"},
91 { rex:/\\gamma/g, tmplt:"γ"},
92 { rex:/\\delta/g, tmplt:"δ"},
93 { rex:/\\epsilon/g, tmplt:"ε"},
94 { rex:/\\zeta/g, tmplt:"ζ"},
95 { rex:/\\eta/g, tmplt:"η"},
96 { rex:/\\thetasym/g, tmplt:"ϑ"},
97 { rex:/\\theta/g, tmplt:"θ"},
98 { rex:/\\iota/g, tmplt:"ι"},
99 { rex:/\\kappa/g, tmplt:"κ"},
100 { rex:/\\lambda/g, tmplt:"λ"},
101 { rex:/\\mu/g, tmplt:"μ"},
102 { rex:/\\nu/g, tmplt:"ν"},
103 { rex:/\\xi/g, tmplt:"ξ"},
104 { rex:/\\omicron/g, tmplt:"ο"},
105 { rex:/\\piv/g, tmplt:"ϖ"},
106 { rex:/\\pi/g, tmplt:"π"},
107 { rex:/\\rho/g, tmplt:"ρ"},
108 { rex:/\\sigmaf/g, tmplt:"ς"},
109 { rex:/\\sigma/g, tmplt:"σ"},
110 { rex:/\\tau/g, tmplt:"τ"},
111 { rex:/\\upsilon/g, tmplt:"υ"},
112 { rex:/\\phi/g, tmplt:"φ"},
113 { rex:/\\chi/g, tmplt:"χ"},
114 { rex:/\\psi/g, tmplt:"ψ"},
115 { rex:/\\omega/g, tmplt:"ω"},
116 { rex:/\\upsih/g, tmplt:"ϒ"},
117 // miscellaneous symbols
118 { rex:/\\bull/g, tmplt:"•"},
119 { rex:/\\uarr/g, tmplt:"↑"},
120 { rex:/\\darr/g, tmplt:"↓"},
121 { rex:/\\crarr/g, tmplt:"↵"},
122 { rex:/\\lArr/g, tmplt:"⇐"},
123 { rex:/\\uArr/g, tmplt:"⇑"},
124 { rex:/\\dArr/g, tmplt:"⇓"},
125 { rex:/\\forall/g, tmplt:"∀"},
126 { rex:/\\part/g, tmplt:"∂"},
127 { rex:/\\exist/g, tmplt:"∃"},
128 { rex:/\\empty/g, tmplt:"∅"},
129 { rex:/\\nabla/g, tmplt:"∇"},
130 { rex:/\\notin/g, tmplt:"∉"},
131 { rex:/\\ni/g, tmplt:"∋"},
132 { rex:/\\minus/g, tmplt:"−"},
133 { rex:/\\lowast/g, tmplt:"∗"},
134 { rex:/\\sqrt|\\radic/g, tmplt:"√"},
135 { rex:/\\prop/g, tmplt:"∝"},
136 { rex:/\\infin/g, tmplt:"∞"},
137 { rex:/\\ang/g, tmplt:"∠"},
138 { rex:/\\and/g, tmplt:"∧"},
139 { rex:/\\or/g, tmplt:"∨"},
140 { rex:/\\cap/g, tmplt:"∩"},
141 { rex:/\\cup/g, tmplt:"∪"},
142 { rex:/\\there4/g, tmplt:"∴"},
143 { rex:/\\sub/g, tmplt:"⊂"},
144 { rex:/\\sup/g, tmplt:"⊃"},
145 { rex:/\\nsub/g, tmplt:"⊄"},
146 { rex:/\\sube/g, tmplt:"⊆"},
147 { rex:/\\supe/g, tmplt:"⊇"},
148 { rex:/\\oplus/g, tmplt:"⊕"},
149 { rex:/\\otimes/g, tmplt:"⊗"},
150 { rex:/\\perp/g, tmplt:"⊥"},
151 { rex:/\\sdot/g, tmplt:"⋅"}
155 Wiky.inverse.math = {
157 { rex:/−|\u2212/g, tmplt:"-"},
158 { rex:/ |\u2009/g, tmplt:" "},
159 { rex:/‎|\u200E/g, tmplt:"{"},
160 { rex:/‏|\u200F/g, tmplt:"}"}
163 // { rex:/([$])/g, tmplt:"\\$1" },
164 { rex:/^|\x5E/g, tmplt:"^"},
165 { rex:/</g, tmplt:"<"},
166 { rex:/>/g, tmplt:">"}
169 // { rex:/ |\u2003/g, tmplt:" "}, // omit due to charset support ie6
170 // { rex:/ |\u2002/g, tmplt:" "},
171 // { rex:/ |\u2009/g, tmplt:" "},
172 { rex:/±|\xB1/g, tmplt:"+-"},
173 { rex:/·|\xB7/g, tmplt:"*"},
174 { rex:/×|\xD7/g, tmplt:"\\x"},
175 { rex:/Ø|\xD8/g, tmplt:"/O"},
176 { rex:/ø|\xF8/g, tmplt:"/o"},
177 { rex:/←|\u2190/g, tmplt:"<-"},
178 { rex:/→|\u2192/g, tmplt:"->"},
179 { rex:/↔|\u2194/g, tmplt:"<->"},
180 { rex:/⇒|\u21D2/g, tmplt:"=>"},
181 { rex:/⇔|\u21D4/g, tmplt:"<=>"},
182 { rex:/∼|\u223C/g, tmplt:"~"},
183 { rex:/≅|\u2245/g, tmplt:"~="},
184 { rex:/≈|\u2248/g, tmplt:"~~"},
185 { rex:/≠|\u2260/g, tmplt:"!="},
186 { rex:/…/g, tmplt:"..."},
187 { rex:/≡|\u2261/g, tmplt:"-="},
188 { rex:/≤|\u2264/g, tmplt:"<="},
189 { rex:/≥|\u2265/g, tmplt:">="}
192 { rex:/<span class=\"s\"><span class=\"i\">(\{?@[0-9]+@\}?)<\/span><span class="i">(\{?@[0-9]+@\}?)<\/span><\/span>/g, tmplt:"_$2^$1"}, // superscript + subscript
193 { rex:/<span class=\"o\"><span class=\"x\">(\{?@[0-9]+@\}?)<\/span>(\\prod|\\sum|\\int)<span class=\"x\">(\{?@[0-9]+@\}?)<\/span><\/span>/g, tmplt:"$2_$3^$1"}, // overscript + underscript
194 { rex:/<span class=\"o\"><span>@[0-9]+@<\/span>(\\prod|\\sum|\\int)<span class=\"x\">(\{?@[0-9]+@\}?)<\/span><\/span>/mgi, tmplt:"$1_$2", dbg:true}, // underscript
195 { rex:/<span class=\"o\"><span class=\"x\">(\{?@[0-9]+@\}?)<\/span>(\\prod|\\sum|\\int)<span>@[0-9]+@<\/span><\/span>/mgi, tmplt:"$2^$1"}, // overscript
196 { rex:/<span class=\"f\"><span class=\"n\">(\{?@[0-9]+@\}?)<\/span><span class="d">(\{?@[0-9]+@\}?)<\/span><\/span>/mgi, tmplt:"$1/$2"}, // fraction
197 { rex:/<span class=\"lb\"[^>]*>&[^;]+;<\/span><span class=\"v\">((?:<span class=\"e\">[^>]*<\/span>){2,})<\/span><span class=\"rb\"[^>]*>&[^;]+;<\/span>/mgi, tmplt:function($0,$1){return "["+$1.replace(/(?:^<span class=\"e\">|<\/span>$)/g,"").replace(/<\/span><span class=\"e\">/g,",")+"]";}}, // vector ..
198 { rex:/<span class=\"lb\"[^>]*>&[^;]+;<\/span>((?:<span class=\"m\">(?:(?:<span class=\"e\">[^>]*<\/span>){2,})<\/span>[^>]*){2,})<span class=\"rb\"[^>]*>&[^;]+;<\/span>/mgi, tmplt:function($0,$1){return "[["+Wiky.math.transpose($1.replace(/(?:^<span class=\"m\"><span class=\"e\">|<\/span><\/span>$)/g,"").replace(/<\/span><span class=\"e\">/g,",").replace(/<\/span><\/span>[^>]*<span class=\"m\"><span class=\"e\">/g,"|").split("|")).mat.join("][")+"]]";}}, // matrix ..
199 { rex:/<span class=\"b\">(@[0-9]+@)<\/span>/mgi, tmplt:"!$1"}, // bold vector ..
200 { rex:/<sup>(\{?@[0-9]+@\}?)<\/sup>⁄<sub>(\{?@[0-9]+@\}?)<\/sub>/mgi, tmplt:"$1//$2"},
201 { rex:/<sup class=\"i\">(\{?@[0-9]+@\}?)<\/sup>/mgi, tmplt:"^$1" },
202 { rex:/<sub class=\"i\">(\{?@[0-9]+@\}?)<\/sub>/mgi, tmplt:"_$1" }
206 { rex:/Α|\u391/g, tmplt:"\\Alpha"},
207 { rex:/Β|\u392/g, tmplt:"\\Beta"},
208 { rex:/Γ|\u393/g, tmplt:"\\Gamma"},
209 { rex:/Δ|\u394/g, tmplt:"\\Delta"},
210 { rex:/Ε|\u395/g, tmplt:"\\Epsilon"},
211 { rex:/Ζ|\u396/g, tmplt:"\\Zeta"},
212 { rex:/Η|\u397/g, tmplt:"\\Eta"},
213 { rex:/Θ|\u398/g, tmplt:"\\Theta"},
214 { rex:/Ι|\u399/g, tmplt:"\\Iota"},
215 { rex:/Κ|\u39A/g, tmplt:"\\Kappa"},
216 { rex:/Λ|\u39B/g, tmplt:"\\Lambda"},
217 { rex:/Μ|\u39C/g, tmplt:"\\Mu"},
218 { rex:/Ν|\u39D/g, tmplt:"\\Nu"},
219 { rex:/Ξ|\u39E/g, tmplt:"\\Xi"},
220 { rex:/Ο|\u39F/g, tmplt:"\\Omicron"},
221 { rex:/Π|\u3A0/g, tmplt:"\\Pi"},
222 { rex:/Ρ|\u3A1/g, tmplt:"\\Rho"},
223 { rex:/Σ|\u3A3/g, tmplt:"\\Sigma"},
224 { rex:/Τ|\u3A4/g, tmplt:"\\Tau"},
225 { rex:/Υ|\u3A5/g, tmplt:"\\Upsilon"},
226 { rex:/Φ|\u3A6/g, tmplt:"\\Phi"},
227 { rex:/Χ|\u3A7/g, tmplt:"\\Chi"},
228 { rex:/Ψ|\u3A8/g, tmplt:"\\Psi"},
229 { rex:/Ω|\u3A9/g, tmplt:"\\Omega"},
230 { rex:/α|\u3B1/g, tmplt:"\\alpha"},
231 { rex:/β|\u3B2/g, tmplt:"\\beta"},
232 { rex:/γ|\u3B3/g, tmplt:"\\gamma"},
233 { rex:/δ|\u3B4/g, tmplt:"\\delta"},
234 { rex:/ε|\u3B5/g, tmplt:"\\epsilon"},
235 { rex:/ζ|\u3B6/g, tmplt:"\\zeta"},
236 { rex:/η|\u3B7/g, tmplt:"\\eta"},
237 { rex:/ϑ|\u3D1/g, tmplt:"\\thetasym"},
238 { rex:/θ|\u3B8/g, tmplt:"\\theta"},
239 { rex:/ι|\u3B9/g, tmplt:"\\iota"},
240 { rex:/κ|\u3BA/g, tmplt:"\\kappa"},
241 { rex:/λ|\u3BB/g, tmplt:"\\lambda"},
242 { rex:/μ|\u3BC/g, tmplt:"\\mu"},
243 { rex:/ν|\u3BD/g, tmplt:"\\nu"},
244 { rex:/ξ|\u3BE/g, tmplt:"\\xi"},
245 { rex:/ο|\u3BF/g, tmplt:"\\omicron"},
246 { rex:/π|\u3C0/g, tmplt:"\\pi"},
247 { rex:/ρ|\u3C1/g, tmplt:"\\rho"},
248 { rex:/ς|\u3C2/g, tmplt:"\\sigmaf"},
249 { rex:/σ|\u3C3/g, tmplt:"\\sigma"},
250 { rex:/τ|\u3C4/g, tmplt:"\\tau"},
251 { rex:/υ|\u3C5/g, tmplt:"\\upsilon"},
252 { rex:/φ|\u3C6/g, tmplt:"\\phi"},
253 { rex:/χ|\u3C7/g, tmplt:"\\chi"},
254 { rex:/ψ|\u3C8/g, tmplt:"\\psi"},
255 { rex:/ω|\u3C9/g, tmplt:"\\omega"},
256 // miscellaneous symbols
257 { rex:/ϒ|\u3D2/g, tmplt:"\\upsih"},
258 { rex:/ϖ|\u3D6/g, tmplt:"\\piv"},
259 { rex:/•|\u2022/g, tmplt:"\\bull"},
260 { rex:/↑|\u2191/g, tmplt:"\\uarr"},
261 { rex:/↓|\u2193/g, tmplt:"\\darr"},
262 { rex:/↵|\u21B5/g, tmplt:"\\crarr"},
263 { rex:/⇐|\u21D0/g, tmplt:"\\lArr"},
264 { rex:/⇑|\u21D1/g, tmplt:"\\uArr"},
265 { rex:/⇓|\u21D3/g, tmplt:"\\dArr"},
266 { rex:/∀|\u2200/g, tmplt:"\\forall"},
267 { rex:/∂|\u2202/g, tmplt:"\\part"},
268 { rex:/∃|\u2203/g, tmplt:"\\exist"},
269 { rex:/∅|\u2205/g, tmplt:"\\empty"},
270 { rex:/∇|\u2207/g, tmplt:"\\nabla"},
271 { rex:/∈|\u2208/g, tmplt:"\\isin"},
272 { rex:/∉|\u2209/g, tmplt:"\\notin"},
273 { rex:/∋|\u220B/g, tmplt:"\\ni"},
274 { rex:/<span class=\"h\">(∏|\u220F)<\/span>/g, tmplt:"\\prod"},
275 { rex:/<span class=\"h\">(∑|\u2211)<\/span>/g, tmplt:"\\sum"},
276 { rex:/∗|\u2217/g, tmplt:"\\lowast"},
277 { rex:/√|\u221A/g, tmplt:"\\sqrt"},
278 { rex:/∝|\u221D/g, tmplt:"\\prop"},
279 { rex:/∞|\u221E/g, tmplt:"\\infin"},
280 { rex:/∠|\u2220/g, tmplt:"\\ang"},
281 { rex:/∧|\u2227/g, tmplt:"\\and"},
282 { rex:/∨|\u2228/g, tmplt:"\\or"},
283 { rex:/∩|\u2229/g, tmplt:"\\cap"},
284 { rex:/∪|\u222A/g, tmplt:"\\cup"},
285 { rex:/<span class=\"h\">(?:∫|\u222B)<\/span>/g, tmplt:"\\int"},
286 { rex:/∴|\u2234/g, tmplt:"\\there4"},
287 { rex:/⊂|\u2282/g, tmplt:"\\sub"},
288 { rex:/⊃|\u2283/g, tmplt:"\\sup"},
289 { rex:/⊄|\u2284/g, tmplt:"\\nsub"},
290 { rex:/⊆|\u2286/g, tmplt:"\\sube"},
291 { rex:/⊇|\u2287/g, tmplt:"\\supe"},
292 { rex:/⊕|\u2295/g, tmplt:"\\oplus"},
293 { rex:/⊗|\u2297/g, tmplt:"\\otimes"},
294 { rex:/⊥|\u22A5/g, tmplt:"\\perp"},
295 { rex:/⋅|\u22C5/g, tmplt:"\\sdot"}
300 toHtml: function(str) {
301 var expr = function(itr) { // region from "{" to "}", nesting allowed ..
303 for (var c = itr.str.charAt(itr.pos++); itr.pos <= itr.str.length && c != "}"; c = itr.str.charAt(itr.pos++))
304 s += (c == "{") ? ("{"+expr(itr)+"}") : c;
305 return Wiky.store(Wiky.apply(s, Wiky.rules.math.expr));
307 str = Wiky.apply(str, Wiky.rules.math.preshortcuts);
308 str = Wiky.apply(str, Wiky.rules.math.symbols);
309 str = expr({str:str,pos:0});
312 toWiki: function(str) {
313 var parseTree = function(itr, endtag) {
314 var c, s="",gt,nam,idxof=function(s,c,p){var i=s.indexOf(c,p);return i>=0?i:s.length;}
315 for (itr.buf=itr.str.substr(itr.pos,endtag.length);
316 itr.pos<itr.str.length && (!endtag || itr.buf!=endtag);
317 itr.buf=itr.str.substr(++itr.pos,endtag.length)) {
318 if ((c=itr.str.charAt(itr.pos))=="<" && (gt=idxof(itr.str,">",itr.pos)) < idxof(itr.str,"/",itr.pos)) { // start tags .. no empty elements or endtags ..
319 nam = itr.str.substring(itr.pos+1,Math.min(idxof(itr.str," ",itr.pos),gt));
320 s += itr.str.substring(itr.pos,itr.pos=gt+1) + parseTree(itr, "</" + nam + ">") + "</" + nam + ">";
321 itr.pos += nam.length+3;
327 return Wiky.store(s, true);
329 str = Wiky.apply(str, Wiky.inverse.math.pre);
330 str = Wiky.apply(str, Wiky.inverse.math.symbols);
331 str = parseTree({str:str,pos:0,buf:null}, "");
332 while (str.match(/@[0-9]+@/g) != null)
333 str = Wiky.apply(str.replace(/@([0-9]+)@/g, function($0,$1){return Wiky.restore($1);}), Wiky.inverse.math.expr);
334 str = Wiky.apply(str, Wiky.inverse.math.shortcuts);
335 str = Wiky.apply(str, Wiky.inverse.math.post);
338 fence: function(str) {
339 return window && window.ActiveXObject ? " " : " ";
341 transpose: function (m) {
344 m[i] = m[i].split(",");
345 for (var j in m[i]) {
351 t[i] = t[i].join(",");
352 return {mat:t, len:m.length};
356 Wiky.rules.pre = Wiky.rules.pre.concat({ rex:/\\([$])/g, tmplt:function($0,$1){return Wiky.store($1);} });
357 Wiky.rules.nonwikiblocks = Wiky.rules.nonwikiblocks.concat(
359 { rex:/\[\(([a-zA-Z0-9\.-]+)\)\$([^$]*)\$\]/g, tmplt:function($0,$1,$2){return ":p]<div class=\"eq\"><a name=\"eq"+$1+"\">("+$1+")</a>" + Wiky.math.toHtml($2) + "</div>[p:";} }, // numbered equation
360 { rex:/\[\$([^$]*)\$\]/g, tmplt:function($0,$1){return ":p]<div class=\"eq\">" + Wiky.math.toHtml($1) + "</div>[p:";} }, // equation
362 Wiky.rules.nonwikiinlines = Wiky.rules.nonwikiinlines.concat(
363 { rex:/\$([^$]*)\$/g, tmplt:function($0,$1){return "<dfn>" + Wiky.math.toHtml($1) + "</dfn>";} } // inline equation
366 Wiky.inverse.pre = Wiky.inverse.pre.concat({ rex:/([\$])/g, tmplt:"\\$1" });
367 Wiky.inverse.nonwikiblocks = Wiky.inverse.nonwikiblocks.concat(
369 { rex:/<div class=\"eq\"><a name=\"eq([0-9]+)\">(?:.*?)<\/a>(.*?)<\/div>/g, tmplt:function($0,$1,$2){return Wiky.store("[("+$1+")$"+Wiky.math.toWiki($2)+"$]");} }, // numbered equation
370 { rex:/<div class=\"eq\">(.*?)<\/div>/g, tmplt:function($0,$1){return Wiky.store("[$"+Wiky.math.toWiki($1)+"$]");} }, // equation
372 Wiky.inverse.nonwikiinlines = Wiky.inverse.nonwikiinlines.concat(
373 { rex:/<dfn>(.*?)<\/dfn>/g, tmplt:function($0,$1){return Wiky.store("$"+Wiky.math.toWiki($1)+"$");} } // inline equation