# wiki scripts
'js/wiki/wikiapi.js',
'js/wiki/xslt.js',
+ 'js/wiki/xml-tools.js',
# base UI
'js/wiki/base.js',
--- /dev/null
+
+window.walk = (node, handler) ->
+ if handler.text
+ textHandler = handler.text
+ else
+ textHandler = handler
+
+ switch node.nodeType
+ when 1, 9, 11
+ child = node.firstChild
+ while child
+ nxt = child.nextSibling
+ walk(child, handler)
+ child = nxt
+ when 3
+ textHandler node
+
+
+window.wrapInTag = (regex, tagName) ->
+ fun = (node) ->
+ matches = []
+ while m = regex.exec(node.nodeValue)
+ matches.push [regex.lastIndex, m[0]]
+
+ matches.reverse()
+
+ for m in matches
+ to = m[0]
+ frm = m[0] - m[1].length
+
+ node_rest = node.splitText(to)
+ alien = node.splitText(frm)
+ wrapper = node.ownerDocument.createElement tagName
+ node.parentNode.insertBefore wrapper, node_rest
+ wrapper.appendChild alien
+ node
+
+
+# window._test_xml_tools = ->
+# p = new DOMParser()
+# dom = p.parseFromString("<a><b>łuków</b><c>jakaś jeszcze ~</c></a>", 'text/xml')
+
+# walk(dom.firstChild, wrapInTag(ALIEN_REGEX, 'alien'))
+# dom
+
+
+# window.ALIEN_REGEX = /[^a-zA-Z0-9ąćęłńóśźżĄĆĘŁŃÓŚŹŻ\s<>«»\\*_!,:;?&%."'=#()\/-]+/g
+# " just for syntax coloring.
--- /dev/null
+(function() {
+
+ window.walk = function(node, handler) {
+ var child, nxt, textHandler, _results;
+ if (handler.text) {
+ textHandler = handler.text;
+ } else {
+ textHandler = handler;
+ }
+ switch (node.nodeType) {
+ case 1:
+ case 9:
+ case 11:
+ child = node.firstChild;
+ _results = [];
+ while (child) {
+ nxt = child.nextSibling;
+ walk(child, handler);
+ _results.push(child = nxt);
+ }
+ return _results;
+ break;
+ case 3:
+ return textHandler(node);
+ }
+ };
+
+ window.wrapInTag = function(regex, tagName) {
+ var fun;
+ return fun = function(node) {
+ var alien, frm, m, matches, node_rest, to, wrapper, _i, _len;
+ matches = [];
+ while (m = regex.exec(node.nodeValue)) {
+ matches.push([regex.lastIndex, m[0]]);
+ }
+ matches.reverse();
+ for (_i = 0, _len = matches.length; _i < _len; _i++) {
+ m = matches[_i];
+ to = m[0];
+ frm = m[0] - m[1].length;
+ node_rest = node.splitText(to);
+ alien = node.splitText(frm);
+ wrapper = node.ownerDocument.createElement(tagName);
+ node.parentNode.insertBefore(wrapper, node_rest);
+ wrapper.appendChild(alien);
+ }
+ return node;
+ };
+ };
+
+}).call(this);
function xml2html(options) {
+ ALIEN_REGEX = /([^a-zA-Z0-9ąćęłńóśźżĄĆĘŁŃÓŚŹŻ\s<>«»\\*_!,:;?&%."'=#()\/-]+)/g;
+
withStylesheets(function() {
var xml = options.xml.replace(/\/(\s+)/g, '<br />$1');
- xml = xml.replace(/([^a-zA-Z0-9ąćęłńóśźżĄĆĘŁŃÓŚŹŻ\s<>«»\\*_!,:;?&%."'=#()\/-]+)/g, '<alien>$1</alien>');
+// xml = xml.replace(/([^a-zA-Z0-9ąćęłńóśźżĄĆĘŁŃÓŚŹŻ\s<>«»\\*_!,:;?&%."'=#()\/-]+)/g, '<alien>$1</alien>');
var parser = new DOMParser();
var serializer = new XMLSerializer();
var doc = parser.parseFromString(xml, 'text/xml');
+ walk(doc.firstChild, wrapInTag(ALIEN_REGEX, 'alien'))
var error = $('parsererror', doc);
if (error.length == 0) {