Edit color parser
This commit is contained in:
parent
95bebfe12c
commit
1b476bfefd
6
client/js/libs.min.js
vendored
6
client/js/libs.min.js
vendored
File diff suppressed because one or more lines are too long
@ -37,7 +37,6 @@ function escape(text) {
|
|||||||
function uri(text) {
|
function uri(text) {
|
||||||
return URI.withinString(text, function(url) {
|
return URI.withinString(text, function(url) {
|
||||||
if (url.indexOf("javascript:") !== 0) {
|
if (url.indexOf("javascript:") !== 0) {
|
||||||
console.log(url);
|
|
||||||
return "<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>";
|
return "<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>";
|
||||||
} else {
|
} else {
|
||||||
return url;
|
return url;
|
||||||
@ -45,14 +44,20 @@ function uri(text) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var regex = {
|
||||||
|
color: /\003([0-9]{1,2})[,]?([0-9]{1,2})?([^\003]+)/,
|
||||||
|
styles: [
|
||||||
|
[/\002([^\002]+)(\002)?/, ["<b>", "</b>"]],
|
||||||
|
[/\037([^\037]+)(\037)?/, ["<u>", "</u>"]],
|
||||||
|
]
|
||||||
|
};
|
||||||
function colors(text) {
|
function colors(text) {
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
var regex = /\003([0-9]{1,2})[,]?([0-9]{1,2})?([^\003]+)/;
|
if (regex.color.test(text)) {
|
||||||
if (regex.test(text)) {
|
|
||||||
var match;
|
var match;
|
||||||
while (match = regex.exec(text)) {
|
while (match = regex.color.exec(text)) {
|
||||||
var color = "color-" + match[1];
|
var color = "color-" + match[1];
|
||||||
var bg = match[2];
|
var bg = match[2];
|
||||||
if (bg) {
|
if (bg) {
|
||||||
@ -64,16 +69,12 @@ function colors(text) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var styles = [
|
for (var i in regex.styles) {
|
||||||
[/\002([^\002]+)(\002)?/, ["<b>", "</b>"]],
|
var pattern = regex.styles[i][0];
|
||||||
[/\037([^\037]+)(\037)?/, ["<u>", "</u>"]],
|
var style = regex.styles[i][1];
|
||||||
];
|
if (pattern.test(text)) {
|
||||||
for (var i in styles) {
|
|
||||||
var regex = styles[i][0];
|
|
||||||
var style = styles[i][1];
|
|
||||||
if (regex.test(text)) {
|
|
||||||
var match;
|
var match;
|
||||||
while (match = regex.exec(text)) {
|
while (match = pattern.exec(text)) {
|
||||||
text = text.replace(match[0], style[0] + match[1] + style[1]);
|
text = text.replace(match[0], style[0] + match[1] + style[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user