"+(r=n.defaultattr?""+e(n.defaultattr)+""+r:r)+""}},code:{tags:{code:null},isInline:!1,allowedChildren:["#","#newline"],format:"[code]{0}[/code]",html:"{0}"},left:{styles:{"text-align":["left","-webkit-left","-moz-left","-khtml-left"]},isInline:!1,allowsEmpty:!0,format:"[left]{0}[/left]",html:'{0}
'},center:{styles:{"text-align":["center","-webkit-center","-moz-center","-khtml-center"]},isInline:!1,allowsEmpty:!0,format:"[center]{0}[/center]",html:'{0}
'},right:{styles:{"text-align":["right","-webkit-right","-moz-right","-khtml-right"]},isInline:!1,allowsEmpty:!0,format:"[right]{0}[/right]",html:'{0}
'},justify:{styles:{"text-align":["justify","-webkit-justify","-moz-justify","-khtml-justify"]},isInline:!1,allowsEmpty:!0,format:"[justify]{0}[/justify]",html:'{0}
'},youtube:{allowsEmpty:!0,tags:{iframe:{"data-youtube-id":null}},format:function(t,e){return(t=o(t,"data-youtube-id"))?"[youtube]"+t+"[/youtube]":e},html:''},rtl:{styles:{direction:["rtl"]},isInline:!1,format:"[rtl]{0}[/rtl]",html:'{0}
'},ltr:{styles:{direction:["ltr"]},isInline:!1,format:"[ltr]{0}[/ltr]",html:'{0}
'},ignore:{}};function p(t,n){return t.replace(/\{([^}]+)\}/g,function(t,r){var l=!0;return"!"===r.charAt(0)&&(l=!1,r=r.substring(1)),"0"===r&&(l=!1),void 0===n[r]?t:l?e(n[r],!0):n[r]})}function g(t){return"function"==typeof t}function b(t){return t&&t.replace(/\\(.)/g,"$1").replace(/^(["'])(.*?)\1$/,"$2")}var y="open",v="content",x="newline",k="close";function w(t,e,n,r,l,i){var o=this;o.type=t,o.name=e,o.val=n,o.attrs=r||{},o.children=l||[],o.closing=i||null}function E(t){var n=this;function r(t,e){var n,r,l;return t===y&&(n=e.match(/\[([^\]\s=]+)(?:([^\]]+))?\]/))&&(l=c(n[1]),n[2])&&(n[2]=n[2].trim())&&(r=(t=>{var e,n=/([^\s=]+)=(?:(?:(["'])((?:\\\2|[^\2])*?)\2)|((?:.(?!\s\S+=))*.))/g,r={};if("="===t.charAt(0)&&t.indexOf("=",1)<0)r.defaultattr=b(t.substr(1));else for("="===t.charAt(0)&&(t="defaultattr"+t);e=n.exec(t);)r[c(e[1])]=b(e[3])||e[4];return r})(n[2])),t===k&&(n=e.match(/\[\/([^\[\]]+)\]/))&&(l=c(n[1])),(l=t===x?"#newline":l)&&(t!==y&&t!==k||m[l])||(t=v,l="#"),new w(t,l,e,r)}function l(t,e,n){for(var r=n.length;r--;)if(n[r].type===e&&n[r].name===t)return 1}function i(t,e){return t=(t?m[t.name]:{}).allowedChildren,!n.opts.fixInvalidChildren||!t||-1"),g(i.html)?i.html.call(n,l,l.attrs,a):(l.attrs[0]=a,p(i.html,l.attrs))):l.val+a+(l.closing?l.closing.val:"");else{if(l.type===x){if(!r){f+="
";continue}u||(f+=""),f+="
",t.length||(f+="
"),f+="
\n",u=!1;continue}s=r,c=e(l.val,!0)}s&&!u?(f+="",u=!0):!s&&u&&(f+="
\n",u=!1),f+=c}return u&&(f+="\n"),f}function a(t,e,n){var r=/\s|=/.test(t);return g(e)?e(t,n):e===d.never||e===d.auto&&!r?t:'"'+t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'}function u(t){return t.length?t[t.length-1]:null}function c(t){return t.toLowerCase()}n.opts=s({},E.defaults,t),n.tokenize=function(t){var e,n,l,i=[],o=[{type:v,regex:/^([^\[\r\n]+|\[)/},{type:x,regex:/^(\r\n|\r|\n)/},{type:y,regex:/^\[[^\[\]]+\]/},{type:k,regex:/^\[\/[^\[\]]+\]/}];t:for(;t.length;){for(l=o.length;l--;)if(n=o[l].type,(e=t.match(o[l].regex))&&e[0]){i.push(r(n,e[0])),t=t.substr(e[0].length);continue t}t.length&&i.push(r(v,t)),t=""}return i},n.parse=function(t,e){t=(t=>{function e(){return u(g)}function r(t){(e()?e().children:p).push(t)}function o(t){return e()&&(s=m[e().name])&&s.closedBy&&-1{var n=t.nodeName.toLowerCase(),l=r.isInline;if(!l(t,!0)||"br"===n){for(var i,o,s=t.previousSibling;s&&1===s.nodeType&&!a(s,"br")&&l(s,!0)&&!s.firstChild;)s=s.previousSibling;for(;i=((o=t.parentNode)&&o.lastChild)===t,(t=o)&&i&&l(o,!0););i&&"li"!==n||(e+="\n"),"br"!==n&&s&&!a(s,"br")&&l(s,!0)&&(e="\n"+e)}return e})(e,f)):u+=f):3===d&&(u+=e.nodeValue)},!1,!0),u}(t,e)}function d(e,n,r){var l=new E(t.opts.parserOptions);return(e||r?l.toHTMLFragment:l.toHTML)(t.opts.bbcodeTrim?n.trim():n)}function p(e,n,l,o){l=l||document;var a,s=!!r.closest(o,"code"),u=l.createElement("div"),c=l.createElement("div"),d=new E(t.opts.parserOptions);for(c.innerHTML=n,i(u,"visibility","hidden"),u.appendChild(c),l.body.appendChild(u),e&&(u.insertBefore(l.createTextNode("#"),u.firstChild),u.appendChild(l.createTextNode("#"))),o&&i(c,"whiteSpace",i(o,"whiteSpace")),a=c.getElementsByClassName("sceditor-ignore");a.length;)a[0].parentNode.removeChild(a[0]);return r.removeWhiteSpace(u),n=f(c,s),l.body.removeChild(u),n=d.toBBCode(n,!0),t.opts.bbcodeTrim?n.trim():n}t.init=function(){t.opts=this.opts,t.elementToBbcode=f,u(m,function(t,n){var r=!1===n.isInline,l=(n=m[t].tags,m[t].styles);l&&(e["*"]=e["*"]||{},e["*"][r]=e["*"][r]||{},e["*"][r][t]=[["style",Object.entries(l)]]),n&&u(n,function(n,l){l&&l.style&&(l.style=Object.entries(l.style)),e[n]=e[n]||{},e[n][r]=e[n][r]||{},e[n][r][t]=l&&Object.entries(l)})}),this.commands=s(!0,{},h,this.commands),this.toBBCode=t.toSource,this.fromBBCode=t.toHtml},t.toHtml=d.bind(null,!1),t.fragmentToHtml=d.bind(null,!0),t.toSource=p.bind(null,!1),t.fragmentToSource=p.bind(null,!0)}w.prototype={clone:function(){var t=this;return new w(t.type,t.name,t.val,s({},t.attrs),[],t.closing?t.closing.clone():null)},splitAt:function(t){var e,n=this.clone();return-1<(t=this.children.indexOf(t))&&(e=this.children.length-t,n.children=this.children.splice(t,e)),n}},E.QuoteType=d,E.defaults={breakBeforeBlock:!1,breakStartBlock:!1,breakEndBlock:!1,breakAfterBlock:!0,removeEmptyTags:!0,fixInvalidNesting:!0,fixInvalidChildren:!0,quoteType:d.auto,strictMatch:!1},C.get=function(t){return m[t]||null},C.set=function(t,e){return t&&e&&((e=s(m[t]||{},e)).remove=function(){delete m[t]},m[t]=e),this},C.rename=function(t,e){return t in m&&(m[e]=m[t],delete m[t]),this},C.remove=function(t){return t in m&&delete m[t],this},C.formatBBCodeString=p,t.formats.bbcode=C,t.BBCodeParser=E})(sceditor);