1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is ChatZilla
15
* The Initial Developer of the Original Code is New Dimensions Consulting,
16
* Inc. Portions created by New Dimensions Consulting, Inc. are
17
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
21
* Robert Ginda, rginda@ndcico.com, original author
22
* Samuel Sieb, samuel@sieb.net, MIRC color codes
28
/((\w[\w-]+):[^<>\[\]()\'\"\s\u201d]+|www(\.[^.<>\[\]()\'\"\s\u201d]+){2,})/;
30
var munger = client.munger = new CMunger();
31
munger.addRule ("quote", /(``|'')/, insertQuote);
32
munger.addRule ("bold", /(?:\s|^)(\*[^*()]*\*)(?:[\s.,]|$)/,
34
munger.addRule ("underline", /(?:\s|^)(\_[^_()]*\_)(?:[\s.,]|$)/,
35
"chatzilla-underline");
36
munger.addRule ("italic", /(?:\s|^)(\/[^\/()]*\/)(?:[\s.,]|$)/,
38
/* allow () chars inside |code()| blocks */
39
munger.addRule ("teletype", /(?:\s|^)(\|[^|]*\|)(?:[\s.,]|$)/,
40
"chatzilla-teletype");
41
munger.addRule (".mirc-colors", /(\x03((\d{1,2})(,\d{1,2}|)|))/,
43
munger.addRule (".mirc-bold", /(\x02)/, mircToggleBold);
44
munger.addRule (".mirc-underline", /(\x1f)/, mircToggleUnder);
45
munger.addRule (".mirc-color-reset", /(\x0f)/, mircResetColor);
46
munger.addRule (".mirc-reverse", /(\x16)/, mircReverseColor);
47
munger.addRule ("ctrl-char", /([\x01-\x1f])/, showCtrlChar);
48
munger.addRule ("link", client.linkRE, insertLink);
49
munger.addRule ("mailto",
50
/(?:\s|\W|^)((mailto:)?[^<>\[\]()\'\"\s\u201d]+@[^.<>\[\]()\'\"\s\u201d]+\.[^<>\[\]()\'\"\s\u201d]+)/i,
52
munger.addRule ("bugzilla-link", /(?:\s|\W|^)(bug\s+#?\d{3,6})/i,
54
munger.addRule ("channel-link",
55
/(?:\s|\W|^)[@+]?(#[^<>\[\](){}\"\s\u201d]*[^:,.<>\[\](){}\'\"\s\u201d])/i,
58
munger.addRule ("face",
59
/((^|\s)[\<\>]?[\;\=\:]\~?[\-\^\v]?[\)\|\(pP\<\>oO0\[\]\/\\](\s|$))/,
61
munger.addRule ("ear", /(?:\s|^)(\(\*)(?:\s|$)/, insertEar, false);
62
munger.addRule ("rheet", /(?:\s|\W|^)(rhee+t\!*)(?:\s|$)/i, insertRheet);
63
munger.addRule ("word-hyphenator",
64
new RegExp ("(\\S{" + client.MAX_WORD_DISPLAY + ",})"),
65
insertHyphenatedWord);
67
client.enableColors = client.prefs["munger.colorCodes"];
68
for (var entry in client.munger.entries)
70
var branch = client.prefManager.prefBranch;
75
munger.entries[entry].enabled =
76
branch.getBoolPref("munger." + entry);
86
function CMungerEntry (name, regex, className, enable, tagName)
90
this.description = getMsg("munger." + name, null, null);
91
this.enabled = (typeof enable == "undefined" ? true : enable);
92
this.enabledDefault = this.enabled;
93
this.tagName = (tagName) ? tagName : "html:span";
95
if (regex instanceof RegExp)
98
this.lambdaMatch = regex;
100
if (typeof className == "function")
101
this.lambdaReplace = className;
103
this.className = className;
108
this.entries = new Object();
109
this.tagName = "html:span";
113
CMunger.prototype.enabled = true;
115
CMunger.prototype.addRule =
116
function mng_addrule (name, regex, className, enable)
118
this.entries[name] = new CMungerEntry (name, regex, className, enable);
121
CMunger.prototype.delRule =
122
function mng_delrule (name)
124
delete this.entries[name];
127
CMunger.prototype.munge =
128
function mng_munge (text, containerTag, data)
137
document.createElementNS ("http://www.w3.org/1999/xhtml",
143
for (entry in this.entries)
145
if (this.entries[entry].enabled)
147
if (typeof this.entries[entry].lambdaMatch == "function")
151
rval = this.entries[entry].lambdaMatch(text, containerTag,
153
this.entries[entry]);
155
ary = [(void 0), rval];
160
ary = text.match(this.entries[entry].regex);
162
if ((ary != null) && (ary[1]))
164
var startPos = text.indexOf(ary[1]);
166
if (typeof this.entries[entry].lambdaReplace == "function")
168
this.munge (text.substr(0,startPos), containerTag,
170
this.entries[entry].lambdaReplace (ary[1], containerTag,
172
this.entries[entry]);
173
this.munge (text.substr (startPos + ary[1].length,
174
text.length), containerTag,
181
this.munge (text.substr(0,startPos), containerTag,
184
var subTag = document.createElementNS
185
("http://www.w3.org/1999/xhtml",
186
this.entries[entry].tagName);
188
newClass = this.entries[entry].className;
190
if ("hasColorInfo" in data)
192
if ("currFgColor" in data)
193
newClass += " chatzilla-fg" + data.currFgColor;
194
if ("currBgColor" in data)
195
newClass += " chatzilla-bg" + data.currBgColor;
196
if ("isBold" in data)
197
newClass += " chatzilla-bold";
198
if ("isUnderline" in data)
199
newClass += " chatzilla-underline";
202
subTag.setAttribute ("class", newClass);
204
/* don't let this rule match again */
205
this.entries[entry].enabled = false;
206
this.munge(ary[1], subTag, data);
207
this.entries[entry].enabled = true;
209
containerTag.appendChild (subTag);
211
this.munge (text.substr (startPos + ary[1].length,
212
text.length), containerTag,
222
var textNode = document.createTextNode (text);
224
if ("hasColorInfo" in data)
228
if ("currFgColor" in data)
229
newClass = "chatzilla-fg" + data.currFgColor;
230
if ("currBgColor" in data)
231
newClass += " chatzilla-bg" + data.currBgColor;
232
if ("isBold" in data)
233
newClass += " chatzilla-bold";
234
if ("isUnderline" in data)
235
newClass += " chatzilla-underline";
238
var newTag = document.createElementNS
239
("http://www.w3.org/1999/xhtml",
241
newTag.setAttribute ("class", newClass);
242
newTag.appendChild (textNode);
243
containerTag.appendChild (newTag);
247
delete data.hasColorInfo;
248
containerTag.appendChild (textNode);
250
wbr = document.createElementNS ("http://www.w3.org/1999/xhtml",
252
containerTag.appendChild (wbr);
255
containerTag.appendChild (textNode);