Source
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
var BBCode = {
opentags: null, // open tag stack
crlf2br: null, // convert CRLF to <br>?
noparse: null, // ignore BBCode tags?
urlstart: null, // beginning of the URL if zero or greater (ignored if -1)
RE: {
'bbcode': /^\/?(?:b|i|u|pre|code|color|size|noparse|url)$/, // BBcode tags
'color': /^(:?#(?:[0-9a-f]{3})?[0-9a-f]{3})$/i, // color names or hex color
'uri': /^[-;\/\?:@&=\+\$,_\.!~\*'\(\)%0-9a-z]{1,512}$/i, // reserved, unreserved, escaped and alphanumeric [RFC2396]
'format': /([\r\n])|(?:\[([a-z]{1,16})(?:=([^\x00-\x1F''\(\)<>\[\]]{1,256}))?\])|(?:\[\/([a-z]{1,16})\])/ig // main regular expression: CRLF, [tag=option], [tag] or [/tag]
},
// post must be HTML-encoded
Parse: function(post) {
this.crlf2br = false;
this.noparse = false;
this.urlstart = -1;
this.opentags = [];
var result = post.replace(this.RE.format, this.toHtml.bind(this));
if (this.opentags.length) {
var endtags = '';
if (this.opentags[this.opentags.length-1].bbtag == 'url') {
this.opentags.pop();
endtags += '\'>' + post.substr(this.urlstart, post.length-this.urlstart) + '</a>';
}
while (this.opentags.length) {
endtags += this.opentags.pop().etag;
}
}
return endtags ? result + endtags : result;
},
// check if it's a valid BBCode tag
isValidTag: function(str) {
if (empty(str)) {
return false;
}