-function Colourise(line, entity) {
+function Colourise(line, entity, execfn) {
var fg;
var bg;
var underline = false;
function emitEndToken() {
if(out.length > 0) {
- urlificate(element, out.join(""));
+ urlificate(element, out.join(""), execfn);
entity.appendChild(element);
out = [];
}
var url_re = /https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/;
+var chan_re = /\B#[^ ,]+/;
-function urlificate(element, text) {
+function txtprocess(text, regex, appendfn, matchfn) {
+ for(;;) {
+ var index = text.search(regex);
+ if(index == -1) {
+ appendfn(text);
+ break;
+ }
+ var match = text.match(regex);
+
+ var before = text.substring(0, index);
+ var matched = match[0];
+ var after = text.substring(index + matched.length);
+
+ text = after;
+ appendfn(before);
+ matchfn(matched);
+ }
+}
+
+function urlificate(element, text, execfn) {
function appendText(text) {
- element.appendChild(document.createTextNode(text));
+ chanficate(element, text, execfn);
}
function appendA(text) {
var a = document.createElement("a");
element.appendChild(a);
}
-
- for(;;) {
- var index = text.search(url_re);
- if(index == -1) {
- appendText(text);
- break;
- }
- var match = text.match(url_re);
-
- before = text.substring(0, index);
- matched = match[0];
- after = text.substring(index + matched.length);
- text = after;
- appendText(before);
- appendA(matched, before);
+ txtprocess(text, url_re, appendText, appendA);
+}
+
+function chanficate(element, text, execfn) {
+ function appendText(text) {
+ element.appendChild(document.createTextNode(text));
+ }
+ function appendA(text) {
+ var a = document.createElement("a");
+ a.href = "#";
+ a.addEvent("click", function(e) {
+ new Event(e).stop();
+ execfn("/JOIN " + text);
+ });
+ a.appendChild(document.createTextNode(text));
+
+ element.appendChild(a);
}
+ txtprocess(text, chan_re, appendText, appendA);
}