patch_file/ckeditor/plugins/codemirror/js/codemirror.mode.bbcode.min.js

4 lines
1.7 KiB
JavaScript

CodeMirror.defineMode("bbcode",function(h){var i,j,k;i="b i u s img quote code list table tr td size color url";j="* :-) hr cut";h.hasOwnProperty("bbCodeTags")&&(i=h.bbCodeTags);h.hasOwnProperty("bbCodeUnaryTags")&&(j=h.bbCodeUnaryTags);var c={cont:function(a,b){k=b;return a},escapeRegEx:function(a){return a.replace(/([\:\-\)\(\*\+\?\[\]])/g,"\\$1")}},l=/[a-zA-Z0-9_]/,m=/['"]/,n=RegExp("(?:"+c.escapeRegEx(i).split(" ").join("|")+")"),o=RegExp("(?:"+c.escapeRegEx(j).split(" ").join("|")+")"),f={tokenizer:function(a,
b){if(a.eatSpace())return null;if(a.match("[",true)){b.tokenize=f.bbcode;return c.cont("tag","startTag")}a.next();return null},inAttribute:function(a){return function(b,c){for(var d=null,g=null;!b.eol();){g=b.peek();if(b.next()==a&&d!=="\\"){c.tokenize=f.bbcode;break}d=g}return"string"}},bbcode:function(a,b){if(a.match("]",true)){b.tokenize=f.tokenizer;return c.cont("tag",null)}if(a.match("[",true))return c.cont("tag","startTag");var e=a.next();if(m.test(e)){b.tokenize=f.inAttribute(e);return c.cont("string",
"string")}if(/\d/.test(e)){a.eatWhile(/\d/);return c.cont("number","number")}if(b.last=="whitespace"){a.eatWhile(l);return c.cont("attribute","modifier")}if(b.last=="property"){a.eatWhile(l);return c.cont("property",null)}if(/\s/.test(e)){k="whitespace";return null}var d="";e!="/"&&(d=d+e);for(var g=null;g=a.eat(l);)d=d+g;return o.test(d)?c.cont("atom","atom"):n.test(d)?c.cont("keyword","keyword"):/\s/.test(e)?null:c.cont("tag","tag")}};return{startState:function(){return{tokenize:f.tokenizer,mode:"bbcode",
last:null}},token:function(a,b){var c=b.tokenize(a,b);b.last=k;return c},electricChars:""}});CodeMirror.defineMIME("text/x-bbcode","bbcode");