1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* The contents of this file are subject to the Mozilla Public License
4
* Version 1.1 (the "License"); you may not use this file except in
5
* compliance with the License. You may obtain a copy of the License at
6
* http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS IS" basis,
9
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10
* for the specific language governing rights and limitations under the
13
* The Original Code is The JavaScript Debugger
15
* The Initial Developer of the Original Code is
16
* Netscape Communications Corporation
17
* Portions created by Netscape are
18
* Copyright (C) 1998 Netscape Communications Corporation.
20
* Alternatively, the contents of this file may be used under the
21
* terms of the GNU Public License (the "GPL"), in which case the
22
* provisions of the GPL are applicable instead of those above.
23
* If you wish to allow use of your version of this file only
24
* under the terms of the GPL and not to allow others to use your
25
* version of this file under the MPL, indicate your decision by
26
* deleting the provisions above and replace them with the notice
27
* and other provisions required by the GPL. If you do not delete
28
* the provisions above, a recipient may use your version of this
29
* file under either the MPL or the GPL.
32
* Robert Ginda, <rginda@netscape.com>, original author
36
function CMungerEntry (name, regex, className, tagName)
40
this.tagName = (tagName) ? tagName : "html:span";
42
if (regex instanceof RegExp)
45
this.lambdaMatch = regex;
47
if (typeof className == "function")
48
this.lambdaReplace = className;
50
this.className = className;
57
this.entries = new Object();
61
CMunger.prototype.enabled = true;
63
CMunger.prototype.addRule =
64
function mng_addrule (name, regex, className)
67
this.entries[name] = new CMungerEntry (name, regex, className);
71
CMunger.prototype.delRule =
72
function mng_delrule (name)
75
delete this.entries[name];
79
CMunger.prototype.munge =
80
function mng_munge (text, containerTag, data)
85
if (!text) //(ASSERT(text, "no text to munge"))
88
if (typeof text != "string")
94
document.createElementNS (NS_XHTML, this.tagName);
99
for (entry in this.entries)
101
if (typeof this.entries[entry].lambdaMatch == "function")
105
rval = this.entries[entry].lambdaMatch(text, containerTag,
107
this.entries[entry]);
109
ary = [(void 0), rval];
114
ary = text.match(this.entries[entry].regex);
116
if ((ary != null) && (ary[1]))
118
var startPos = text.indexOf(ary[1]);
120
if (typeof this.entries[entry].lambdaReplace == "function")
122
this.munge (text.substr(0,startPos), containerTag,
124
this.entries[entry].lambdaReplace (ary[1], containerTag,
126
this.entries[entry]);
127
this.munge (text.substr (startPos + ary[1].length,
128
text.length), containerTag,
135
this.munge (text.substr(0,startPos), containerTag,
139
document.createElementNS (NS_XHTML,
140
this.entries[entry].tagName);
142
subTag.setAttribute ("class",
143
this.entries[entry].className);
144
var wordParts = splitLongWord (ary[1],
145
client.MAX_WORD_DISPLAY);
146
for (var i in wordParts)
148
subTag.appendChild (document.createTextNode (wordParts[i]));
149
subTag.appendChild (htmlWBR());
152
containerTag.appendChild (subTag);
153
this.munge (text.substr (startPos + ary[1].length,
154
text.length), containerTag, data);
162
containerTag.appendChild (document.createTextNode (text));