3 window.walk = function(node, handler) {
4 var child, nxt, textHandler, _results;
6 textHandler = handler.text;
10 switch (node.nodeType) {
14 child = node.firstChild;
17 nxt = child.nextSibling;
19 _results.push(child = nxt);
24 return textHandler(node);
28 window.wrapInTag = function(regex, tagName) {
30 return fun = function(node) {
31 var alien, frm, m, matches, node_rest, to, wrapper, _i, _len;
33 while (m = regex.exec(node.nodeValue)) {
34 matches.push([regex.lastIndex, m[0]]);
37 for (_i = 0, _len = matches.length; _i < _len; _i++) {
40 frm = m[0] - m[1].length;
41 node_rest = node.splitText(to);
42 alien = node.splitText(frm);
43 wrapper = node.ownerDocument.createElement(tagName);
44 node.parentNode.insertBefore(wrapper, node_rest);
45 wrapper.appendChild(alien);