Skip to content
Snippets Groups Projects
Commit 34027759 authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

BB-code cleanup.

parent 94bd153b
No related branches found
No related tags found
No related merge requests found
/* Element containing the BB-code */
let el = document.getElementsByClassName("nfo")[0].children[0]
let str = el.innerText
var r = /\[(\/)?(\w{0,5})(=([^\]]*))?\]/g
let result;
let stk = [];
let result_str = "";
let last_idx = 0;
let other;
/* Index of first unhandled character in input string
* Should guarantee that nothing gets parsed twice */
let last_idx = 0;
let result;
while ((result = r.exec(str)) !== null) {
index = result.index
var [matched, end, tag, _, param] = result
if (! end) { /* if start tag */
o = Object()
o.tag = tag
o.str = ""
o.index = index + matched.length
o.param = param
o = { tag: tag
, str: ""
, index: index + matched.length
, param: param
}
if (stk.length === 0) {
result_str += str.substring(last_idx, index);
} else {
other = stk.last();
var other = stk.last();
other.str += str.substring(other.index, index);
}
last_idx = o.index;
......@@ -40,10 +42,11 @@ while ((result = r.exec(str)) !== null) {
var s;
switch (parent.tag) {
case "url":
s = "<a href='"
if (typeof parent.param === "undefined") {
s = "<a href='" + parent.str;
s += parent.str;
} else {
s = "<a href='" + parent.param;
s += parent.param;
}
s += "'>" + parent.str + "</a>";
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment