simple-syntax-highlighter
Advanced tools
Comparing version 2.0.7 to 2.2.0
@@ -1,2 +0,2 @@ | ||
"use strict";var c=require("vue");var f=(e,t)=>{for(const[a,i]of t)e[a]=i;return e};const s={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*[\s\S]*?\*\/)/,htmlTag:/(<([^>])*>)/,punctuation:/(!==?|(?:[[\](){}.:;,+\-?=!]|<|>)+|&&|\|\|)/,number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},m={shell:{quote:s.quote,comment:/(#.*?)(?:\n|$)/,keyword:/(?:^|\b)(npm|yarn|install|run)(?:\b|$)/,param:/( --(?:save|save-dev))(?:\s|$)/},xml:{doctype:/(<\!DOCTYPE.*?>)/,quote:s.quote,comment:/(<!--[\s\S]*?-->)/,tag:/(<\/?)([a-zA-Z\-:]+)([\s\S]*?)(\/?>)/},html:{doctype:/(DOCTYPE)/,quote:s.quote,comment:/(<!--[\s\S]*?-->)/,tag:/(<\/?)([a-z]\w*)([\s\S]*?)(\/?>)/},"html-vue":{doctype:/(DOCTYPE)/,quote:s.quote,comment:/(<!--[\s\S]*?-->)/,tag:/(<\/?)([a-zA-Z][\w\d-]*)((?:.|\s)*?)(\/?>)/},pug:{text:/((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\n|$))/,text2:/([ \t]*)([.#\-\w\d]+(?:\([^)]*\))*)\.\n((?:\n+(?=\1[ \t]+)|(?=\1[ \t]+)[\s\S]+?(?:\n|$)*?)*)(?=\n|$)/,quote:s.quote,comment:/(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\1[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/,tag:/([a-zA-Z][\w\d-]*|)([.#][a-zA-Z][-.\w\d]*|)\b(?:\(([\s\S]*?)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/,punctuation:/(!==?|(?:[#[\]().,+\-?=!|]|<|>)+)/},css:{quote:s.quote,comment:/(\/\*[\s\S]*?\*\/)/,pseudo:/(:(?:hover|active|focus|visited|not|before|after|(?:first|last|nth)-child))/,"selector keyword vendor":/(@-(?:moz|o|webkit|ms)-(?=keyframes\s))/,"selector keyword":/((?:@(?:import|media|font-face|keyframes)|screen|print|and)(?=[\s({])|keyframes|\s(?:ul|ol|li|table|div|pre|p|a|img|br|hr|h[1-6]|em|strong|span|html|body|iframe|video|audio|input|button|form|label|fieldset|small|abbr|i|dd|dt)\b)/,variable:/(--[a-zA-Z0-9\-]+)/,selector:/((?:[.#-\w*+ >:,[\]="~\n]|>)+)(?=\s*\{)/,"attribute keyword vendor":/(-(?:moz|o|webkit|ms)-(?=transform|transition|user-select|tap-highlight-color|animation|background-size|box-shadow))/,"attribute keyword":/\b(content|float|display|position|top|left|right|bottom|(?:(?:max|min)-)?width|(?:(?:max|min|line)-)?height|font(?:-(?:family|style|size|weight|variant|stretch))?|vertical-align|color|opacity|visibility|z-index|pointer-events|user-select|transform(?:-(?:origin|style|delay|duration|property|timing-function))?|transition(?:-(?:delay|duration))?|animation(?:-(?:name|delay|duration|direction|fill-mode))?|backface-visibility|backdrop-filter|background(?:-(?:color|position|image|repeat|size|attachment|origin|clip|blend-mode))?|(?:padding|margin|border)(?:-(?:top|left|right|bottom))?|border(?:-(?:radius|color|width|style|spacing))|white-space|text-(?:align|transform|decoration|shadow|indent)|overflow(?:-(?:x|y))?|(?:letter|word)-spacing|word-break|box-(?:sizing|shadow)|stroke(?:-(?:width|opacity|dasharray|dashoffset|linecap|linejoin))?|fill|speak|outline|user-select|cursor|flex(?:-(?:direction|flow|grow|shrink|basis|wrap))?|(?:justify|align)-(?:content|self|items))(?=\s*:)/,"value keyword vendor":/(-(?:moz|o|webkit|ms)-(?=linear-gradient))/,"value keyword":/\b(inherit|initial|normal|none|unset|auto|inline(?:-(?:block|flex))?|block|flex|absolute|relative|static|fixed|sticky|hidden|visible|top|left|right|bottom|center|middle|baseline|solid|dotted|dashed|line-through|(?:over|under)line|wavy|double|(?:pre-|no)?wrap|pre|break-word|(?:upper|lower)case|capitalize|italic|bold|attr\(.*?\)|linear|ease(?:-in)?(?:-out)?|all|infinite|cubic-bezier|(?:translate|rotate)(?:[X-Z]|3d)?|skew[XY]?|scale|(?:no-)?repeat|repeat(?:-x|-y)|contain|cover|url|(?:repeating-)?(?:linear|radial)-gradient|inset|pointer|(?:flex-)?(?:start|end)|space-(?:between|evenly|around)|stretch|revert|row(?:-reverse)?|column(?:-reverse)?)(?=\s*[,;}(]|\s+[\da-z!])/,"value keyword important":/( ?!important)/,number:s.number,color:/(transparent|#(?:[\da-fA-F]{6}|[\da-fA-F]{3})|rgba?\([\d., ]*\))/,htmlentity:/(&.*?;)/,punctuation:/([:,;{}@#()!]+|<|>)/,attribute:/([a-zA-Z-]+)(?=\s*:)/,unit:/(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/},json:{quote:s.quote,comment:s.comment,number:s.number,boolean:s.boolean,punctuation:/([[\](){}:;,-]+)/},js:{quote:s.quote,comment:s.comment,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:s.boolean,this:/\b(this)(?=\W)/,keyword:/\b(new|getElementsBy(?:Tag|Class|)Name|getElementById|querySelector|querySelectorAll|arguments|if|else|do|return|case|default|(?:f|F)unction|typeof|instanceof|undefined|document|window|while|for|forEach|switch|in|break|continue|delete|length|var|let|const|export|import|as|require|from|Class|constructor|Number|Boolean|String|Array|Object|RegExp|Integer|Date|Promise|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN)(?=\W)/,punctuation:/(!==?|(?:[[\]!(){}:;,+\-%*/?=]|<|>)+|\.+(?![a-zA-Z])|&&|\|\|)/,variable:/(\.?[a-zA-Z_][\w\d]*)/,htmlentity:/(&.*?;)/,"external-var":/(\$|jQuery|JSON)(?=\W|$)/},php:{quote:s.quote,comment:s.comment,special:/(<\?php|\?>|__(?:DIR|FILE|LINE)__)/,punctuation:s.punctuation,number:s.number,boolean:s.boolean,variable:/(\$[\w\d_]+)/,keyword:/\b(define|echo|die|exit|print_r|var_dump|if|else|elseif|do|return|case|default|function|\$this|while|foreach|for|switch|in|break|continue|empty|isset|unset|parse_ini_file|session_(?:start|destroy|id)|header|json_(?:encode|decode)|error_log|(require|include)(:?_once)?|try|throw|new|Exception|catch|finally|preg_(?:match|replace)|list|strlen|substr|str_replace|array_(?:keys|values))(?=\W|$)/},sql:{quote:s.quote,comment:/((?:\-\-|#)\s.*?(?:\n|$)|\/\*[\s\S]*?\*\/)/,punctuation:s.punctuation,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:s.boolean,keyword:/\b(\*|CREATE|DATABASE|TABLE|GRANT|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|NOT|NULL|EXISTS|SELECT|UPDATE|DELETE|INSERT(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER) |)JOIN|AS|ON|COUNT|CASE|TO|WHEN|BETWEEN|AND|OR|IN|LIKE|CONCAT|CURRENT_TIMESTAMP)(?=\W|$)/,"var-type":/\b((?:var)?char|(?:tiny|small|medium|big)?int|decimal|float|double|real|bit|boolean|date(?:time)?|time(?:stamp)?|year|(?:tiny|medium|long)?(?:text|blob)|enum)\b/}},y={xml:/(\s*)([a-zA-Z\d\-:]+)=("|')([\s\S]*?)\3/g,html:/(\s*)([a-zA-Z-]+)=("|')([\s\S]*?)\3/g,"html-vue":/(\s*)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')([\s\S]*?)\3)|)/g,pug:/(\s*|,)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')([\s\S]*?)\3)|)/g},x={shell:{quote:2},xml:{quote:2,tag:4},html:{quote:2,tag:4},"html-vue":{quote:2,tag:4},pug:{text:3,text2:3,quote:2,comment:3,tag:6},json:{quote:2},php:{quote:2},sql:{quote:2},css:{quote:2},js:{quote:2}},g=e=>e.map(t=>{if(!t.children||typeof t.children=="string")return t.children||"";if(Array.isArray(t.children))return g(t.children);if(t.children.default)return g(t.children.default())}).join(""),E={name:"sshpre",props:{language:{type:String,default:""},label:{type:[String,Boolean],default:!1},reactive:{type:Boolean,default:!1},dark:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!1}},data:()=>({knownLanguages:Object.keys(m),content:"",slotTexts:""}),methods:{htmlize(e){return e.replace(/&(lt|gt|amp);/g,(t,a)=>({lt:"<",gt:">",amp:"&"})[a])},unhtmlize(e){return e.replace(/[<>]/g,t=>({"<":"<",">":">"})[t])},isColorDark(e){let t,a,i,n,o,l;if(t=e.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))i=parseInt(t[1])<=100,n=parseInt(t[2])<=100,o=parseInt(t[3])<=100,l=parseFloat(t[4])<.3;else if(a=e.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const r=a[1].length===3;i=parseInt(a[1][0])<=9,n=parseInt(a[1][r?1:2])<=9,o=parseInt(a[1][r?2:4])<=9}return(i&&n&&o||i&&n&&!o||!i&&n&&o)&&!l},createRegexPattern(){let e="";const t=[];for(const a in m[this.language]){const i=x[this.language][a]||1;for(let n=0;n<i;n++)t.push(a);e+=(e?"|":"")+m[this.language][a].source}return[e,t]},syntaxHighlightHtmlTag(e){const t=(i,n,o,l,r)=>`${n}<span class="attribute">${o}</span>`+(r?'<span class="punctuation">=</span>':"")+(r?`<span class="quote">${l||""}${r||""}${l||""}</span>`:"");let a=(e[2]||"").replace(y[this.language],t);if(this.language==="pug"){const i=(e[1]||"").replace(/#[a-z\d-]+/g,n=>`<span class="id">${n}</span>`).replace(/\.[a-z\d-]+/g,n=>`<span class="class">${n}</span>`);return a&&(a='<span class="punctuation">(</span>'+a+'<span class="punctuation">)</span>'),`<span class="tag-name">${e[0]||""}</span>${i}${a}`+(e[3]?'<span class="punctuation">.</span>':"")+(e[4]||"")+(e[5]?`<span class="text">${e[5]}</span>`:"")}return`<span class="punctuation">${e[0]}</span><span class="tag-name">${e[1]}</span>`+a+`<span class="punctuation">${e[3]}</span>`},syntaxHighlightContent(e){if(!this.knownLanguages.includes(this.language))return e;const[t,a]=this.createRegexPattern();return this.unhtmlize(e).replace(new RegExp(t,"g"),(i,...n)=>{n=n.slice(0,n.length-2);let o;const l=this.language==="pug";let r=n.find((u,d)=>u&&(o=a[d])&&u);if(o==="quote")r=this.unhtmlize(r);else if(o==="comment")if(l){const[u,d,p]=n.slice(a.indexOf("comment"));r=`${u}${d}${this.unhtmlize(p)}`}else r=this.unhtmlize(r);else{if(o==="text"&&l)return`${n[0]}<span class="punctuation">|</span>${n[1]}<span class="text">${n[2]}</span>`;if(o==="text2"&&l){const[,,,u,d,p]=n,b=this.syntaxHighlightContent(d);return`${u}${b}<span class="punctuation">.</span> | ||
"use strict";var c=require("vue");var f=(e,t)=>{for(const[a,i]of t)e[a]=i;return e};const s={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*.*?\*\/)/,htmlTag:/(<([^>])*>)/,htmlentity:/(&[a-zA-Z0-9#]+;)/,punctuation:/(!==?|(?:[[\](){}.:;,+\-?=!]|<|>)+|&&|\|\|)/,number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},m={shell:{quote:s.quote,comment:/(#.*?)(?:\n|$)/,keyword:/(?:^|\b)(npm|yarn|install|run)(?:\b|$)/,param:/( --(?:save|save-dev))(?:\s|$)/},xml:{doctype:/(<\!DOCTYPE.*?>)/,quote:s.quote,comment:/(<!--.*?-->)/,htmlentity:s.htmlentity,tag:/(<\/?)([a-zA-Z\-:]+)(.*?)(\/?>)/},html:{doctype:/(DOCTYPE)/,quote:s.quote,comment:/(<!--.*?-->)/,htmlentity:s.htmlentity,tag:/(<\/?)([a-z]\w*)(.*?)(\/?>)/},"html-vue":{doctype:/(DOCTYPE)/,quote:s.quote,comment:/(<!--.*?-->)/,htmlentity:s.htmlentity,tag:/(<\/?)([a-zA-Z][\w\d-]*)((?:.|\s)*?)(\/?>)/},pug:{text:/((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\s*(?:\n|$)))/,text2:/([ \t]*)([.#\-\w\d]+(?:\([^)]*\))*)\.\n((?:\n+(?=\4[ \t]+)|(?=\4[ \t]+).+?(?:\n|$)*?)*)(?=\s*(?:\n|$))/,quote:s.quote,comment:/(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\10[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/,tag:/([a-zA-Z][\w\d-]*|)([.#][a-zA-Z][-.\w\d]*|)\b(?:\((.*?)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/,punctuation:/(!==?|(?:[#[\]().,+\-?=!|]|<|>)+)/},css:{quote:s.quote,comment:/(\/\*.*?\*\/)/,pseudo:/(:(?:hover|active|focus|visited|not|before|after|(?:first|last|nth)-child))/,"selector keyword vendor":/(@-(?:moz|o|webkit|ms)-(?=keyframes\s))/,"selector keyword":/((?:@(?:import|media|font-face|keyframes)|screen|print|and)(?=[\s({])|keyframes|\s(?:ul|ol|li|table|div|pre|p|a|img|br|hr|h[1-6]|em|strong|span|html|body|iframe|video|audio|input|button|form|label|fieldset|small|abbr|i|dd|dt)\b)/,variable:/(--[a-zA-Z0-9\-]+)/,selector:/((?:[.#-\w*+ >:,[\]="~\n]|>)+)(?=\s*\{)/,"attribute keyword vendor":/(-(?:moz|o|webkit|ms)-(?=transform|transition|user-select|tap-highlight-color|animation|background-size|box-shadow))/,"attribute keyword":/\b(content|float|display|position|top|left|right|bottom|(?:(?:max|min)-)?width|(?:(?:max|min|line)-)?height|font(?:-(?:family|style|size|weight|variant|stretch))?|vertical-align|color|opacity|visibility|z-index|pointer-events|user-select|transform(?:-(?:origin|style|delay|duration|property|timing-function))?|transition(?:-(?:delay|duration))?|animation(?:-(?:name|delay|duration|direction|fill-mode))?|backface-visibility|backdrop-filter|background(?:-(?:color|position|image|repeat|size|attachment|origin|clip|blend-mode))?|(?:padding|margin|border)(?:-(?:top|left|right|bottom))?|border(?:-(?:radius|color|width|style|spacing))|white-space|text-(?:align|transform|decoration|shadow|indent)|overflow(?:-(?:x|y))?|(?:letter|word)-spacing|word-break|box-(?:sizing|shadow)|stroke(?:-(?:width|opacity|dasharray|dashoffset|linecap|linejoin))?|fill|speak|outline|user-select|cursor|flex(?:-(?:direction|flow|grow|shrink|basis|wrap))?|(?:justify|align)-(?:content|self|items))(?=\s*:)/,"value keyword vendor":/(-(?:moz|o|webkit|ms)-(?=linear-gradient))/,"value keyword":/\b(inherit|initial|normal|none|unset|auto|inline(?:-(?:block|flex))?|block|flex|absolute|relative|static|fixed|sticky|hidden|visible|top|left|right|bottom|center|middle|baseline|solid|dotted|dashed|line-through|(?:over|under)line|wavy|double|(?:pre-|no)?wrap|pre|break-word|(?:upper|lower)case|capitalize|italic|bold|attr\(.*?\)|linear|ease(?:-in)?(?:-out)?|all|infinite|cubic-bezier|(?:translate|rotate)(?:[X-Z]|3d)?|skew[XY]?|scale|(?:no-)?repeat|repeat(?:-x|-y)|contain|cover|url|(?:repeating-)?(?:linear|radial)-gradient|inset|pointer|(?:flex-)?(?:start|end)|space-(?:between|evenly|around)|stretch|revert|row(?:-reverse)?|column(?:-reverse)?)(?=\s*[,;}(]|\s+[\da-z!])/,"value keyword important":/( ?!important)/,number:s.number,color:/(transparent|#(?:[\da-fA-F]{6}|[\da-fA-F]{3})|rgba?\([\d., ]*\))/,htmlentity:/(&.*?;)/,punctuation:/([:,;{}@#()!]+|<|>)/,attribute:/([a-zA-Z-]+)(?=\s*:)/,unit:/(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/},json:{quote:s.quote,comment:s.comment,number:s.number,boolean:s.boolean,punctuation:/([[\](){}:;,-]+)/},js:{quote:s.quote,comment:s.comment,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:s.boolean,this:/\b(this)(?=\W)/,keyword:/\b(new|getElementsBy(?:Tag|Class|)Name|getElementById|querySelector|querySelectorAll|arguments|if|else|do|return|case|default|(?:f|F)unction|typeof|instanceof|undefined|document|window|while|for|forEach|switch|in|break|continue|delete|length|var|let|const|export|import|as|require|from|Class|constructor|Number|Boolean|String|Array|Object|RegExp|Integer|Date|Promise|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN)(?=\W)/,punctuation:/(!==?|(?:[[\]!(){}:;,+\-%*/?=]|<|>)+|\.+(?![a-zA-Z])|&&|\|\|)/,variable:/(\.?[a-zA-Z_][\w\d]*)/,htmlentity:/(&.*?;)/,"external-var":/(\$|jQuery|JSON)(?=\W|$)/},php:{quote:s.quote,comment:s.comment,special:/(<\?php|\?>|__(?:DIR|FILE|LINE)__)/,punctuation:s.punctuation,number:s.number,boolean:s.boolean,variable:/(\$[\w\d_]+)/,keyword:/\b(define|echo|die|exit|print_r|var_dump|if|else|elseif|do|return|case|default|function|\$this|while|foreach|for|switch|in|break|continue|empty|isset|unset|parse_ini_file|session_(?:start|destroy|id)|header|json_(?:encode|decode)|error_log|(require|include)(:?_once)?|try|throw|new|Exception|catch|finally|preg_(?:match|replace)|list|strlen|substr|str_replace|array_(?:keys|values))(?=\W|$)/},sql:{quote:s.quote,comment:/((?:\-\-|#)\s.*?(?:\n|$)|\/\*.*?\*\/)/,punctuation:s.punctuation,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:s.boolean,keyword:/\b(\*|CREATE|DATABASE|TABLE|GRANT|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|NOT|NULL|EXISTS|SELECT|UPDATE|DELETE|INSERT(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER) |)JOIN|AS|ON|COUNT|CASE|TO|WHEN|BETWEEN|AND|OR|IN|LIKE|CONCAT|CURRENT_TIMESTAMP)(?=\W|$)/,"var-type":/\b((?:var)?char|(?:tiny|small|medium|big)?int|decimal|float|double|real|bit|boolean|date(?:time)?|time(?:stamp)?|year|(?:tiny|medium|long)?(?:text|blob)|enum)\b/}},y={xml:/(\s*)([a-zA-Z\d\-:]+)=("|')(.*?)\3/g,html:/(\s*)([a-zA-Z-]+)=("|')(.*?)\3/g,"html-vue":/(\s*)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')(.*?)\3)|)/g,pug:/(\s*|,)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')(.*?)\3)|)/g},x={shell:{quote:2},xml:{quote:2,tag:4},html:{quote:2,tag:4},"html-vue":{quote:2,tag:4},pug:{text:3,text2:3,quote:2,comment:3,tag:6},json:{quote:2},php:{quote:2},sql:{quote:2},css:{quote:2},js:{quote:2}},g=e=>e.map(t=>{if(!t.children||typeof t.children=="string")return t.children||"";if(Array.isArray(t.children))return g(t.children);if(t.children.default)return g(t.children.default())}).join(""),E={name:"sshpre",props:{language:{type:String,default:""},label:{type:[String,Boolean],default:!1},reactive:{type:Boolean,default:!1},dark:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!1}},data:()=>({knownLanguages:Object.keys(m),content:"",slotTexts:""}),methods:{htmlize(e){return e.replace(/&(lt|gt|amp);/g,(t,a)=>({lt:"<",gt:">",amp:"&"})[a])},unhtmlize(e){return e.replace(/[<>]/g,t=>({"<":"<",">":">"})[t])},isColorDark(e){let t,a,i,n,o,l;if(t=e.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))i=parseInt(t[1])<=100,n=parseInt(t[2])<=100,o=parseInt(t[3])<=100,l=parseFloat(t[4])<.3;else if(a=e.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const r=a[1].length===3;i=parseInt(a[1][0])<=9,n=parseInt(a[1][r?1:2])<=9,o=parseInt(a[1][r?2:4])<=9}return(i&&n&&o||i&&n&&!o||!i&&n&&o)&&!l},createRegexPattern(){let e="";const t=[];for(const a in m[this.language]){const i=x[this.language][a]||1;for(let n=0;n<i;n++)t.push(a);e+=(e?"|":"")+m[this.language][a].source}return[e,t]},syntaxHighlightHtmlTag(e){const t=(i,n,o,l,r)=>`${n}<span class="attribute">${o}</span>`+(r?'<span class="punctuation">=</span>':"")+(r?`<span class="quote">${l||""}${r||""}${l||""}</span>`:"");let a=(e[2]||"").replace(y[this.language],t);if(this.language==="pug"){const i=(e[1]||"").replace(/#[a-z\d-]+/g,n=>`<span class="id">${n}</span>`).replace(/\.[a-z\d-]+/g,n=>`<span class="class">${n}</span>`);return a&&(a='<span class="punctuation">(</span>'+a+'<span class="punctuation">)</span>'),`<span class="tag-name">${e[0]||""}</span>${i}${a}`+(e[3]?'<span class="punctuation">.</span>':"")+(e[4]||"")+(e[5]?`<span class="text">${e[5]}</span>`:"")}return`<span class="punctuation">${e[0]}</span><span class="tag-name">${e[1]}</span>`+a+`<span class="punctuation">${e[3]}</span>`},syntaxHighlightContent(e){if(!this.knownLanguages.includes(this.language))return e;const[t,a]=this.createRegexPattern();return this.unhtmlize(e).replace(new RegExp(t,"gs"),(i,...n)=>{n=n.slice(0,n.length-2);let o;const l=this.language==="pug";let r=n.find((u,d)=>u&&(o=a[d])&&u);if(o==="quote")r=this.unhtmlize(r);else if(o==="comment")if(l){const[u,d,p]=n.slice(a.indexOf("comment"));r=`${u}${d}${this.unhtmlize(p)}`}else r=this.unhtmlize(r);else{if(o==="text"&&l)return`${n[0]}<span class="punctuation">|</span>${n[1]}<span class="text">${n[2]}</span>`;if(o==="text2"&&l){const[,,,u,d,p]=n,b=this.syntaxHighlightContent(d);return`${u}${b}<span class="punctuation">.</span> | ||
<span class="text">${p}</span>`}else{if(o==="tag"&&["xml","html","html-vue","pug"].includes(this.language))return this.syntaxHighlightHtmlTag(n.slice(a.indexOf("tag")));if(o==="variable"&&r[0]==="."&&this.language==="js")return`<span class="punctuation">.</span><span class="obj-attr">${r.substr(1)}</span>`}}let h="";return o==="color"&&this.language==="css"&&(h=` style="background-color: ${r};color: #${this.isColorDark(r)?"fff":"000"}"`),o&&`<span class="${o}"${h}>${r}</span>`||""})},checkSlots(){const e=this.$slots.default&&g(this.$slots.default())||"";this.slotTexts!==e&&(this.slotTexts=e,this.content=this.syntaxHighlightContent(this.slotTexts))},copyCode(e){e.target.insertAdjacentHTML("afterend",`<textarea id="clipboard-textarea">${this.$refs.code.innerText}</textarea>`);const t=document.getElementById("clipboard-textarea");t.select(),t.setSelectionRange(0,99999),document.execCommand("copy"),t.remove(),this.$emit("copied",this.$refs.code.innerText)}},mounted(){this.checkSlots()},beforeUpdate(){this.reactive&&this.checkSlots()}},v=["data-type","data-label"],w=c.createTextVNode("Copy"),T=c.createTextVNode(),k=["innerHTML"];function $(e,t,a,i,n,o){return c.openBlock(),c.createElementBlock("div",{class:c.normalizeClass(["ssh-pre",{"ssh-pre--dark":a.dark}]),"data-type":a.language,"data-label":a.label||null},[a.copyButton?(c.openBlock(),c.createElementBlock("button",{key:0,class:"ssh-pre__copy",onClick:t[0]||(t[0]=(...l)=>o.copyCode&&o.copyCode(...l))},[c.renderSlot(e.$slots,"copy-button",{},()=>[w])])):c.createCommentVNode("",!0),T,c.createElementVNode("pre",{ref:"code",class:"ssh-pre__content",innerHTML:e.content},null,8,k)],10,v)}var A=f(E,[["render",$]]);module.exports=A; |
@@ -11,4 +11,5 @@ import { openBlock, createElementBlock, normalizeClass, renderSlot, createCommentVNode, createElementVNode, createTextVNode } from "vue"; | ||
quote: /("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/, | ||
comment: /(\/\/.*?(?:\n|$)|\/\*[\s\S]*?\*\/)/, | ||
comment: /(\/\/.*?(?:\n|$)|\/\*.*?\*\/)/, | ||
htmlTag: /(<([^>])*>)/, | ||
htmlentity: /(&[a-zA-Z0-9#]+;)/, | ||
punctuation: /(!==?|(?:[[\](){}.:;,+\-?=!]|<|>)+|&&|\|\|)/, | ||
@@ -28,4 +29,5 @@ number: /(-?(?:\.\d+|\d+(?:\.\d+)?))/, | ||
quote: regexBasics.quote, | ||
comment: /(<!--[\s\S]*?-->)/, | ||
tag: /(<\/?)([a-zA-Z\-:]+)([\s\S]*?)(\/?>)/ | ||
comment: /(<!--.*?-->)/, | ||
htmlentity: regexBasics.htmlentity, | ||
tag: /(<\/?)([a-zA-Z\-:]+)(.*?)(\/?>)/ | ||
}, | ||
@@ -35,4 +37,5 @@ html: { | ||
quote: regexBasics.quote, | ||
comment: /(<!--[\s\S]*?-->)/, | ||
tag: /(<\/?)([a-z]\w*)([\s\S]*?)(\/?>)/ | ||
comment: /(<!--.*?-->)/, | ||
htmlentity: regexBasics.htmlentity, | ||
tag: /(<\/?)([a-z]\w*)(.*?)(\/?>)/ | ||
}, | ||
@@ -42,11 +45,12 @@ "html-vue": { | ||
quote: regexBasics.quote, | ||
comment: /(<!--[\s\S]*?-->)/, | ||
comment: /(<!--.*?-->)/, | ||
htmlentity: regexBasics.htmlentity, | ||
tag: /(<\/?)([a-zA-Z][\w\d-]*)((?:.|\s)*?)(\/?>)/ | ||
}, | ||
pug: { | ||
text: /((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\n|$))/, | ||
text2: /([ \t]*)([.#\-\w\d]+(?:\([^)]*\))*)\.\n((?:\n+(?=\1[ \t]+)|(?=\1[ \t]+)[\s\S]+?(?:\n|$)*?)*)(?=\n|$)/, | ||
text: /((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\s*(?:\n|$)))/, | ||
text2: /([ \t]*)([.#\-\w\d]+(?:\([^)]*\))*)\.\n((?:\n+(?=\4[ \t]+)|(?=\4[ \t]+).+?(?:\n|$)*?)*)(?=\s*(?:\n|$))/, | ||
quote: regexBasics.quote, | ||
comment: /(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\1[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/, | ||
tag: /([a-zA-Z][\w\d-]*|)([.#][a-zA-Z][-.\w\d]*|)\b(?:\(([\s\S]*?)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/, | ||
comment: /(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\10[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/, | ||
tag: /([a-zA-Z][\w\d-]*|)([.#][a-zA-Z][-.\w\d]*|)\b(?:\((.*?)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/, | ||
punctuation: /(!==?|(?:[#[\]().,+\-?=!|]|<|>)+)/ | ||
@@ -56,3 +60,3 @@ }, | ||
quote: regexBasics.quote, | ||
comment: /(\/\*[\s\S]*?\*\/)/, | ||
comment: /(\/\*.*?\*\/)/, | ||
pseudo: /(:(?:hover|active|focus|visited|not|before|after|(?:first|last|nth)-child))/, | ||
@@ -106,3 +110,3 @@ "selector keyword vendor": /(@-(?:moz|o|webkit|ms)-(?=keyframes\s))/, | ||
quote: regexBasics.quote, | ||
comment: /((?:\-\-|#)\s.*?(?:\n|$)|\/\*[\s\S]*?\*\/)/, | ||
comment: /((?:\-\-|#)\s.*?(?:\n|$)|\/\*.*?\*\/)/, | ||
punctuation: regexBasics.punctuation, | ||
@@ -116,6 +120,6 @@ number: /\b(\d+(?:\.\d+)?|null)\b/, | ||
const attributesRegex = { | ||
xml: /(\s*)([a-zA-Z\d\-:]+)=("|')([\s\S]*?)\3/g, | ||
html: /(\s*)([a-zA-Z-]+)=("|')([\s\S]*?)\3/g, | ||
"html-vue": /(\s*)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')([\s\S]*?)\3)|)/g, | ||
pug: /(\s*|,)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')([\s\S]*?)\3)|)/g | ||
xml: /(\s*)([a-zA-Z\d\-:]+)=("|')(.*?)\3/g, | ||
html: /(\s*)([a-zA-Z-]+)=("|')(.*?)\3/g, | ||
"html-vue": /(\s*)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')(.*?)\3)|)/g, | ||
pug: /(\s*|,)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')(.*?)\3)|)/g | ||
}; | ||
@@ -205,3 +209,3 @@ const multiCapturesMapping = { | ||
const [regexPattern, classMap] = this.createRegexPattern(); | ||
return this.unhtmlize(string).replace(new RegExp(regexPattern, "g"), (m, ...matches) => { | ||
return this.unhtmlize(string).replace(new RegExp(regexPattern, "gs"), (m, ...matches) => { | ||
matches = matches.slice(0, matches.length - 2); | ||
@@ -208,0 +212,0 @@ let Class; |
@@ -1,2 +0,2 @@ | ||
(function(i,p){typeof exports=="object"&&typeof module!="undefined"?module.exports=p(require("vue")):typeof define=="function"&&define.amd?define(["vue"],p):(i=typeof globalThis!="undefined"?globalThis:i||self,i.sshpre=p(i.Vue))})(this,function(i){"use strict";var p="",b=(e,t)=>{for(const[n,l]of t)e[n]=l;return e};const s={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*[\s\S]*?\*\/)/,htmlTag:/(<([^>])*>)/,punctuation:/(!==?|(?:[[\](){}.:;,+\-?=!]|<|>)+|&&|\|\|)/,number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},m={shell:{quote:s.quote,comment:/(#.*?)(?:\n|$)/,keyword:/(?:^|\b)(npm|yarn|install|run)(?:\b|$)/,param:/( --(?:save|save-dev))(?:\s|$)/},xml:{doctype:/(<\!DOCTYPE.*?>)/,quote:s.quote,comment:/(<!--[\s\S]*?-->)/,tag:/(<\/?)([a-zA-Z\-:]+)([\s\S]*?)(\/?>)/},html:{doctype:/(DOCTYPE)/,quote:s.quote,comment:/(<!--[\s\S]*?-->)/,tag:/(<\/?)([a-z]\w*)([\s\S]*?)(\/?>)/},"html-vue":{doctype:/(DOCTYPE)/,quote:s.quote,comment:/(<!--[\s\S]*?-->)/,tag:/(<\/?)([a-zA-Z][\w\d-]*)((?:.|\s)*?)(\/?>)/},pug:{text:/((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\n|$))/,text2:/([ \t]*)([.#\-\w\d]+(?:\([^)]*\))*)\.\n((?:\n+(?=\1[ \t]+)|(?=\1[ \t]+)[\s\S]+?(?:\n|$)*?)*)(?=\n|$)/,quote:s.quote,comment:/(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\1[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/,tag:/([a-zA-Z][\w\d-]*|)([.#][a-zA-Z][-.\w\d]*|)\b(?:\(([\s\S]*?)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/,punctuation:/(!==?|(?:[#[\]().,+\-?=!|]|<|>)+)/},css:{quote:s.quote,comment:/(\/\*[\s\S]*?\*\/)/,pseudo:/(:(?:hover|active|focus|visited|not|before|after|(?:first|last|nth)-child))/,"selector keyword vendor":/(@-(?:moz|o|webkit|ms)-(?=keyframes\s))/,"selector keyword":/((?:@(?:import|media|font-face|keyframes)|screen|print|and)(?=[\s({])|keyframes|\s(?:ul|ol|li|table|div|pre|p|a|img|br|hr|h[1-6]|em|strong|span|html|body|iframe|video|audio|input|button|form|label|fieldset|small|abbr|i|dd|dt)\b)/,variable:/(--[a-zA-Z0-9\-]+)/,selector:/((?:[.#-\w*+ >:,[\]="~\n]|>)+)(?=\s*\{)/,"attribute keyword vendor":/(-(?:moz|o|webkit|ms)-(?=transform|transition|user-select|tap-highlight-color|animation|background-size|box-shadow))/,"attribute keyword":/\b(content|float|display|position|top|left|right|bottom|(?:(?:max|min)-)?width|(?:(?:max|min|line)-)?height|font(?:-(?:family|style|size|weight|variant|stretch))?|vertical-align|color|opacity|visibility|z-index|pointer-events|user-select|transform(?:-(?:origin|style|delay|duration|property|timing-function))?|transition(?:-(?:delay|duration))?|animation(?:-(?:name|delay|duration|direction|fill-mode))?|backface-visibility|backdrop-filter|background(?:-(?:color|position|image|repeat|size|attachment|origin|clip|blend-mode))?|(?:padding|margin|border)(?:-(?:top|left|right|bottom))?|border(?:-(?:radius|color|width|style|spacing))|white-space|text-(?:align|transform|decoration|shadow|indent)|overflow(?:-(?:x|y))?|(?:letter|word)-spacing|word-break|box-(?:sizing|shadow)|stroke(?:-(?:width|opacity|dasharray|dashoffset|linecap|linejoin))?|fill|speak|outline|user-select|cursor|flex(?:-(?:direction|flow|grow|shrink|basis|wrap))?|(?:justify|align)-(?:content|self|items))(?=\s*:)/,"value keyword vendor":/(-(?:moz|o|webkit|ms)-(?=linear-gradient))/,"value keyword":/\b(inherit|initial|normal|none|unset|auto|inline(?:-(?:block|flex))?|block|flex|absolute|relative|static|fixed|sticky|hidden|visible|top|left|right|bottom|center|middle|baseline|solid|dotted|dashed|line-through|(?:over|under)line|wavy|double|(?:pre-|no)?wrap|pre|break-word|(?:upper|lower)case|capitalize|italic|bold|attr\(.*?\)|linear|ease(?:-in)?(?:-out)?|all|infinite|cubic-bezier|(?:translate|rotate)(?:[X-Z]|3d)?|skew[XY]?|scale|(?:no-)?repeat|repeat(?:-x|-y)|contain|cover|url|(?:repeating-)?(?:linear|radial)-gradient|inset|pointer|(?:flex-)?(?:start|end)|space-(?:between|evenly|around)|stretch|revert|row(?:-reverse)?|column(?:-reverse)?)(?=\s*[,;}(]|\s+[\da-z!])/,"value keyword important":/( ?!important)/,number:s.number,color:/(transparent|#(?:[\da-fA-F]{6}|[\da-fA-F]{3})|rgba?\([\d., ]*\))/,htmlentity:/(&.*?;)/,punctuation:/([:,;{}@#()!]+|<|>)/,attribute:/([a-zA-Z-]+)(?=\s*:)/,unit:/(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/},json:{quote:s.quote,comment:s.comment,number:s.number,boolean:s.boolean,punctuation:/([[\](){}:;,-]+)/},js:{quote:s.quote,comment:s.comment,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:s.boolean,this:/\b(this)(?=\W)/,keyword:/\b(new|getElementsBy(?:Tag|Class|)Name|getElementById|querySelector|querySelectorAll|arguments|if|else|do|return|case|default|(?:f|F)unction|typeof|instanceof|undefined|document|window|while|for|forEach|switch|in|break|continue|delete|length|var|let|const|export|import|as|require|from|Class|constructor|Number|Boolean|String|Array|Object|RegExp|Integer|Date|Promise|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN)(?=\W)/,punctuation:/(!==?|(?:[[\]!(){}:;,+\-%*/?=]|<|>)+|\.+(?![a-zA-Z])|&&|\|\|)/,variable:/(\.?[a-zA-Z_][\w\d]*)/,htmlentity:/(&.*?;)/,"external-var":/(\$|jQuery|JSON)(?=\W|$)/},php:{quote:s.quote,comment:s.comment,special:/(<\?php|\?>|__(?:DIR|FILE|LINE)__)/,punctuation:s.punctuation,number:s.number,boolean:s.boolean,variable:/(\$[\w\d_]+)/,keyword:/\b(define|echo|die|exit|print_r|var_dump|if|else|elseif|do|return|case|default|function|\$this|while|foreach|for|switch|in|break|continue|empty|isset|unset|parse_ini_file|session_(?:start|destroy|id)|header|json_(?:encode|decode)|error_log|(require|include)(:?_once)?|try|throw|new|Exception|catch|finally|preg_(?:match|replace)|list|strlen|substr|str_replace|array_(?:keys|values))(?=\W|$)/},sql:{quote:s.quote,comment:/((?:\-\-|#)\s.*?(?:\n|$)|\/\*[\s\S]*?\*\/)/,punctuation:s.punctuation,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:s.boolean,keyword:/\b(\*|CREATE|DATABASE|TABLE|GRANT|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|NOT|NULL|EXISTS|SELECT|UPDATE|DELETE|INSERT(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER) |)JOIN|AS|ON|COUNT|CASE|TO|WHEN|BETWEEN|AND|OR|IN|LIKE|CONCAT|CURRENT_TIMESTAMP)(?=\W|$)/,"var-type":/\b((?:var)?char|(?:tiny|small|medium|big)?int|decimal|float|double|real|bit|boolean|date(?:time)?|time(?:stamp)?|year|(?:tiny|medium|long)?(?:text|blob)|enum)\b/}},y={xml:/(\s*)([a-zA-Z\d\-:]+)=("|')([\s\S]*?)\3/g,html:/(\s*)([a-zA-Z-]+)=("|')([\s\S]*?)\3/g,"html-vue":/(\s*)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')([\s\S]*?)\3)|)/g,pug:/(\s*|,)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')([\s\S]*?)\3)|)/g},x={shell:{quote:2},xml:{quote:2,tag:4},html:{quote:2,tag:4},"html-vue":{quote:2,tag:4},pug:{text:3,text2:3,quote:2,comment:3,tag:6},json:{quote:2},php:{quote:2},sql:{quote:2},css:{quote:2},js:{quote:2}},g=e=>e.map(t=>{if(!t.children||typeof t.children=="string")return t.children||"";if(Array.isArray(t.children))return g(t.children);if(t.children.default)return g(t.children.default())}).join(""),E={name:"sshpre",props:{language:{type:String,default:""},label:{type:[String,Boolean],default:!1},reactive:{type:Boolean,default:!1},dark:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!1}},data:()=>({knownLanguages:Object.keys(m),content:"",slotTexts:""}),methods:{htmlize(e){return e.replace(/&(lt|gt|amp);/g,(t,n)=>({lt:"<",gt:">",amp:"&"})[n])},unhtmlize(e){return e.replace(/[<>]/g,t=>({"<":"<",">":">"})[t])},isColorDark(e){let t,n,l,a,o,c;if(t=e.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))l=parseInt(t[1])<=100,a=parseInt(t[2])<=100,o=parseInt(t[3])<=100,c=parseFloat(t[4])<.3;else if(n=e.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const r=n[1].length===3;l=parseInt(n[1][0])<=9,a=parseInt(n[1][r?1:2])<=9,o=parseInt(n[1][r?2:4])<=9}return(l&&a&&o||l&&a&&!o||!l&&a&&o)&&!c},createRegexPattern(){let e="";const t=[];for(const n in m[this.language]){const l=x[this.language][n]||1;for(let a=0;a<l;a++)t.push(n);e+=(e?"|":"")+m[this.language][n].source}return[e,t]},syntaxHighlightHtmlTag(e){const t=(l,a,o,c,r)=>`${a}<span class="attribute">${o}</span>`+(r?'<span class="punctuation">=</span>':"")+(r?`<span class="quote">${c||""}${r||""}${c||""}</span>`:"");let n=(e[2]||"").replace(y[this.language],t);if(this.language==="pug"){const l=(e[1]||"").replace(/#[a-z\d-]+/g,a=>`<span class="id">${a}</span>`).replace(/\.[a-z\d-]+/g,a=>`<span class="class">${a}</span>`);return n&&(n='<span class="punctuation">(</span>'+n+'<span class="punctuation">)</span>'),`<span class="tag-name">${e[0]||""}</span>${l}${n}`+(e[3]?'<span class="punctuation">.</span>':"")+(e[4]||"")+(e[5]?`<span class="text">${e[5]}</span>`:"")}return`<span class="punctuation">${e[0]}</span><span class="tag-name">${e[1]}</span>`+n+`<span class="punctuation">${e[3]}</span>`},syntaxHighlightContent(e){if(!this.knownLanguages.includes(this.language))return e;const[t,n]=this.createRegexPattern();return this.unhtmlize(e).replace(new RegExp(t,"g"),(l,...a)=>{a=a.slice(0,a.length-2);let o;const c=this.language==="pug";let r=a.find((u,d)=>u&&(o=n[d])&&u);if(o==="quote")r=this.unhtmlize(r);else if(o==="comment")if(c){const[u,d,h]=a.slice(n.indexOf("comment"));r=`${u}${d}${this.unhtmlize(h)}`}else r=this.unhtmlize(r);else{if(o==="text"&&c)return`${a[0]}<span class="punctuation">|</span>${a[1]}<span class="text">${a[2]}</span>`;if(o==="text2"&&c){const[,,,u,d,h]=a,S=this.syntaxHighlightContent(d);return`${u}${S}<span class="punctuation">.</span> | ||
<span class="text">${h}</span>`}else{if(o==="tag"&&["xml","html","html-vue","pug"].includes(this.language))return this.syntaxHighlightHtmlTag(a.slice(n.indexOf("tag")));if(o==="variable"&&r[0]==="."&&this.language==="js")return`<span class="punctuation">.</span><span class="obj-attr">${r.substr(1)}</span>`}}let f="";return o==="color"&&this.language==="css"&&(f=` style="background-color: ${r};color: #${this.isColorDark(r)?"fff":"000"}"`),o&&`<span class="${o}"${f}>${r}</span>`||""})},checkSlots(){const e=this.$slots.default&&g(this.$slots.default())||"";this.slotTexts!==e&&(this.slotTexts=e,this.content=this.syntaxHighlightContent(this.slotTexts))},copyCode(e){e.target.insertAdjacentHTML("afterend",`<textarea id="clipboard-textarea">${this.$refs.code.innerText}</textarea>`);const t=document.getElementById("clipboard-textarea");t.select(),t.setSelectionRange(0,99999),document.execCommand("copy"),t.remove(),this.$emit("copied",this.$refs.code.innerText)}},mounted(){this.checkSlots()},beforeUpdate(){this.reactive&&this.checkSlots()}},w=["data-type","data-label"],T=i.createTextVNode("Copy"),k=i.createTextVNode(),v=["innerHTML"];function $(e,t,n,l,a,o){return i.openBlock(),i.createElementBlock("div",{class:i.normalizeClass(["ssh-pre",{"ssh-pre--dark":n.dark}]),"data-type":n.language,"data-label":n.label||null},[n.copyButton?(i.openBlock(),i.createElementBlock("button",{key:0,class:"ssh-pre__copy",onClick:t[0]||(t[0]=(...c)=>o.copyCode&&o.copyCode(...c))},[i.renderSlot(e.$slots,"copy-button",{},()=>[T])])):i.createCommentVNode("",!0),k,i.createElementVNode("pre",{ref:"code",class:"ssh-pre__content",innerHTML:e.content},null,8,v)],10,w)}var A=b(E,[["render",$]]);return A}); | ||
(function(r,p){typeof exports=="object"&&typeof module!="undefined"?module.exports=p(require("vue")):typeof define=="function"&&define.amd?define(["vue"],p):(r=typeof globalThis!="undefined"?globalThis:r||self,r.sshpre=p(r.Vue))})(this,function(r){"use strict";var p="",b=(e,t)=>{for(const[n,l]of t)e[n]=l;return e};const s={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*.*?\*\/)/,htmlTag:/(<([^>])*>)/,htmlentity:/(&[a-zA-Z0-9#]+;)/,punctuation:/(!==?|(?:[[\](){}.:;,+\-?=!]|<|>)+|&&|\|\|)/,number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},m={shell:{quote:s.quote,comment:/(#.*?)(?:\n|$)/,keyword:/(?:^|\b)(npm|yarn|install|run)(?:\b|$)/,param:/( --(?:save|save-dev))(?:\s|$)/},xml:{doctype:/(<\!DOCTYPE.*?>)/,quote:s.quote,comment:/(<!--.*?-->)/,htmlentity:s.htmlentity,tag:/(<\/?)([a-zA-Z\-:]+)(.*?)(\/?>)/},html:{doctype:/(DOCTYPE)/,quote:s.quote,comment:/(<!--.*?-->)/,htmlentity:s.htmlentity,tag:/(<\/?)([a-z]\w*)(.*?)(\/?>)/},"html-vue":{doctype:/(DOCTYPE)/,quote:s.quote,comment:/(<!--.*?-->)/,htmlentity:s.htmlentity,tag:/(<\/?)([a-zA-Z][\w\d-]*)((?:.|\s)*?)(\/?>)/},pug:{text:/((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\s*(?:\n|$)))/,text2:/([ \t]*)([.#\-\w\d]+(?:\([^)]*\))*)\.\n((?:\n+(?=\4[ \t]+)|(?=\4[ \t]+).+?(?:\n|$)*?)*)(?=\s*(?:\n|$))/,quote:s.quote,comment:/(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\10[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/,tag:/([a-zA-Z][\w\d-]*|)([.#][a-zA-Z][-.\w\d]*|)\b(?:\((.*?)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/,punctuation:/(!==?|(?:[#[\]().,+\-?=!|]|<|>)+)/},css:{quote:s.quote,comment:/(\/\*.*?\*\/)/,pseudo:/(:(?:hover|active|focus|visited|not|before|after|(?:first|last|nth)-child))/,"selector keyword vendor":/(@-(?:moz|o|webkit|ms)-(?=keyframes\s))/,"selector keyword":/((?:@(?:import|media|font-face|keyframes)|screen|print|and)(?=[\s({])|keyframes|\s(?:ul|ol|li|table|div|pre|p|a|img|br|hr|h[1-6]|em|strong|span|html|body|iframe|video|audio|input|button|form|label|fieldset|small|abbr|i|dd|dt)\b)/,variable:/(--[a-zA-Z0-9\-]+)/,selector:/((?:[.#-\w*+ >:,[\]="~\n]|>)+)(?=\s*\{)/,"attribute keyword vendor":/(-(?:moz|o|webkit|ms)-(?=transform|transition|user-select|tap-highlight-color|animation|background-size|box-shadow))/,"attribute keyword":/\b(content|float|display|position|top|left|right|bottom|(?:(?:max|min)-)?width|(?:(?:max|min|line)-)?height|font(?:-(?:family|style|size|weight|variant|stretch))?|vertical-align|color|opacity|visibility|z-index|pointer-events|user-select|transform(?:-(?:origin|style|delay|duration|property|timing-function))?|transition(?:-(?:delay|duration))?|animation(?:-(?:name|delay|duration|direction|fill-mode))?|backface-visibility|backdrop-filter|background(?:-(?:color|position|image|repeat|size|attachment|origin|clip|blend-mode))?|(?:padding|margin|border)(?:-(?:top|left|right|bottom))?|border(?:-(?:radius|color|width|style|spacing))|white-space|text-(?:align|transform|decoration|shadow|indent)|overflow(?:-(?:x|y))?|(?:letter|word)-spacing|word-break|box-(?:sizing|shadow)|stroke(?:-(?:width|opacity|dasharray|dashoffset|linecap|linejoin))?|fill|speak|outline|user-select|cursor|flex(?:-(?:direction|flow|grow|shrink|basis|wrap))?|(?:justify|align)-(?:content|self|items))(?=\s*:)/,"value keyword vendor":/(-(?:moz|o|webkit|ms)-(?=linear-gradient))/,"value keyword":/\b(inherit|initial|normal|none|unset|auto|inline(?:-(?:block|flex))?|block|flex|absolute|relative|static|fixed|sticky|hidden|visible|top|left|right|bottom|center|middle|baseline|solid|dotted|dashed|line-through|(?:over|under)line|wavy|double|(?:pre-|no)?wrap|pre|break-word|(?:upper|lower)case|capitalize|italic|bold|attr\(.*?\)|linear|ease(?:-in)?(?:-out)?|all|infinite|cubic-bezier|(?:translate|rotate)(?:[X-Z]|3d)?|skew[XY]?|scale|(?:no-)?repeat|repeat(?:-x|-y)|contain|cover|url|(?:repeating-)?(?:linear|radial)-gradient|inset|pointer|(?:flex-)?(?:start|end)|space-(?:between|evenly|around)|stretch|revert|row(?:-reverse)?|column(?:-reverse)?)(?=\s*[,;}(]|\s+[\da-z!])/,"value keyword important":/( ?!important)/,number:s.number,color:/(transparent|#(?:[\da-fA-F]{6}|[\da-fA-F]{3})|rgba?\([\d., ]*\))/,htmlentity:/(&.*?;)/,punctuation:/([:,;{}@#()!]+|<|>)/,attribute:/([a-zA-Z-]+)(?=\s*:)/,unit:/(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/},json:{quote:s.quote,comment:s.comment,number:s.number,boolean:s.boolean,punctuation:/([[\](){}:;,-]+)/},js:{quote:s.quote,comment:s.comment,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:s.boolean,this:/\b(this)(?=\W)/,keyword:/\b(new|getElementsBy(?:Tag|Class|)Name|getElementById|querySelector|querySelectorAll|arguments|if|else|do|return|case|default|(?:f|F)unction|typeof|instanceof|undefined|document|window|while|for|forEach|switch|in|break|continue|delete|length|var|let|const|export|import|as|require|from|Class|constructor|Number|Boolean|String|Array|Object|RegExp|Integer|Date|Promise|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN)(?=\W)/,punctuation:/(!==?|(?:[[\]!(){}:;,+\-%*/?=]|<|>)+|\.+(?![a-zA-Z])|&&|\|\|)/,variable:/(\.?[a-zA-Z_][\w\d]*)/,htmlentity:/(&.*?;)/,"external-var":/(\$|jQuery|JSON)(?=\W|$)/},php:{quote:s.quote,comment:s.comment,special:/(<\?php|\?>|__(?:DIR|FILE|LINE)__)/,punctuation:s.punctuation,number:s.number,boolean:s.boolean,variable:/(\$[\w\d_]+)/,keyword:/\b(define|echo|die|exit|print_r|var_dump|if|else|elseif|do|return|case|default|function|\$this|while|foreach|for|switch|in|break|continue|empty|isset|unset|parse_ini_file|session_(?:start|destroy|id)|header|json_(?:encode|decode)|error_log|(require|include)(:?_once)?|try|throw|new|Exception|catch|finally|preg_(?:match|replace)|list|strlen|substr|str_replace|array_(?:keys|values))(?=\W|$)/},sql:{quote:s.quote,comment:/((?:\-\-|#)\s.*?(?:\n|$)|\/\*.*?\*\/)/,punctuation:s.punctuation,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:s.boolean,keyword:/\b(\*|CREATE|DATABASE|TABLE|GRANT|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|NOT|NULL|EXISTS|SELECT|UPDATE|DELETE|INSERT(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER) |)JOIN|AS|ON|COUNT|CASE|TO|WHEN|BETWEEN|AND|OR|IN|LIKE|CONCAT|CURRENT_TIMESTAMP)(?=\W|$)/,"var-type":/\b((?:var)?char|(?:tiny|small|medium|big)?int|decimal|float|double|real|bit|boolean|date(?:time)?|time(?:stamp)?|year|(?:tiny|medium|long)?(?:text|blob)|enum)\b/}},y={xml:/(\s*)([a-zA-Z\d\-:]+)=("|')(.*?)\3/g,html:/(\s*)([a-zA-Z-]+)=("|')(.*?)\3/g,"html-vue":/(\s*)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')(.*?)\3)|)/g,pug:/(\s*|,)([@:#]?[a-zA-Z\d-]+)(?:(?:=("|')(.*?)\3)|)/g},x={shell:{quote:2},xml:{quote:2,tag:4},html:{quote:2,tag:4},"html-vue":{quote:2,tag:4},pug:{text:3,text2:3,quote:2,comment:3,tag:6},json:{quote:2},php:{quote:2},sql:{quote:2},css:{quote:2},js:{quote:2}},g=e=>e.map(t=>{if(!t.children||typeof t.children=="string")return t.children||"";if(Array.isArray(t.children))return g(t.children);if(t.children.default)return g(t.children.default())}).join(""),E={name:"sshpre",props:{language:{type:String,default:""},label:{type:[String,Boolean],default:!1},reactive:{type:Boolean,default:!1},dark:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!1}},data:()=>({knownLanguages:Object.keys(m),content:"",slotTexts:""}),methods:{htmlize(e){return e.replace(/&(lt|gt|amp);/g,(t,n)=>({lt:"<",gt:">",amp:"&"})[n])},unhtmlize(e){return e.replace(/[<>]/g,t=>({"<":"<",">":">"})[t])},isColorDark(e){let t,n,l,a,o,c;if(t=e.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))l=parseInt(t[1])<=100,a=parseInt(t[2])<=100,o=parseInt(t[3])<=100,c=parseFloat(t[4])<.3;else if(n=e.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const i=n[1].length===3;l=parseInt(n[1][0])<=9,a=parseInt(n[1][i?1:2])<=9,o=parseInt(n[1][i?2:4])<=9}return(l&&a&&o||l&&a&&!o||!l&&a&&o)&&!c},createRegexPattern(){let e="";const t=[];for(const n in m[this.language]){const l=x[this.language][n]||1;for(let a=0;a<l;a++)t.push(n);e+=(e?"|":"")+m[this.language][n].source}return[e,t]},syntaxHighlightHtmlTag(e){const t=(l,a,o,c,i)=>`${a}<span class="attribute">${o}</span>`+(i?'<span class="punctuation">=</span>':"")+(i?`<span class="quote">${c||""}${i||""}${c||""}</span>`:"");let n=(e[2]||"").replace(y[this.language],t);if(this.language==="pug"){const l=(e[1]||"").replace(/#[a-z\d-]+/g,a=>`<span class="id">${a}</span>`).replace(/\.[a-z\d-]+/g,a=>`<span class="class">${a}</span>`);return n&&(n='<span class="punctuation">(</span>'+n+'<span class="punctuation">)</span>'),`<span class="tag-name">${e[0]||""}</span>${l}${n}`+(e[3]?'<span class="punctuation">.</span>':"")+(e[4]||"")+(e[5]?`<span class="text">${e[5]}</span>`:"")}return`<span class="punctuation">${e[0]}</span><span class="tag-name">${e[1]}</span>`+n+`<span class="punctuation">${e[3]}</span>`},syntaxHighlightContent(e){if(!this.knownLanguages.includes(this.language))return e;const[t,n]=this.createRegexPattern();return this.unhtmlize(e).replace(new RegExp(t,"gs"),(l,...a)=>{a=a.slice(0,a.length-2);let o;const c=this.language==="pug";let i=a.find((u,d)=>u&&(o=n[d])&&u);if(o==="quote")i=this.unhtmlize(i);else if(o==="comment")if(c){const[u,d,h]=a.slice(n.indexOf("comment"));i=`${u}${d}${this.unhtmlize(h)}`}else i=this.unhtmlize(i);else{if(o==="text"&&c)return`${a[0]}<span class="punctuation">|</span>${a[1]}<span class="text">${a[2]}</span>`;if(o==="text2"&&c){const[,,,u,d,h]=a,_=this.syntaxHighlightContent(d);return`${u}${_}<span class="punctuation">.</span> | ||
<span class="text">${h}</span>`}else{if(o==="tag"&&["xml","html","html-vue","pug"].includes(this.language))return this.syntaxHighlightHtmlTag(a.slice(n.indexOf("tag")));if(o==="variable"&&i[0]==="."&&this.language==="js")return`<span class="punctuation">.</span><span class="obj-attr">${i.substr(1)}</span>`}}let f="";return o==="color"&&this.language==="css"&&(f=` style="background-color: ${i};color: #${this.isColorDark(i)?"fff":"000"}"`),o&&`<span class="${o}"${f}>${i}</span>`||""})},checkSlots(){const e=this.$slots.default&&g(this.$slots.default())||"";this.slotTexts!==e&&(this.slotTexts=e,this.content=this.syntaxHighlightContent(this.slotTexts))},copyCode(e){e.target.insertAdjacentHTML("afterend",`<textarea id="clipboard-textarea">${this.$refs.code.innerText}</textarea>`);const t=document.getElementById("clipboard-textarea");t.select(),t.setSelectionRange(0,99999),document.execCommand("copy"),t.remove(),this.$emit("copied",this.$refs.code.innerText)}},mounted(){this.checkSlots()},beforeUpdate(){this.reactive&&this.checkSlots()}},w=["data-type","data-label"],T=r.createTextVNode("Copy"),k=r.createTextVNode(),v=["innerHTML"];function $(e,t,n,l,a,o){return r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["ssh-pre",{"ssh-pre--dark":n.dark}]),"data-type":n.language,"data-label":n.label||null},[n.copyButton?(r.openBlock(),r.createElementBlock("button",{key:0,class:"ssh-pre__copy",onClick:t[0]||(t[0]=(...c)=>o.copyCode&&o.copyCode(...c))},[r.renderSlot(e.$slots,"copy-button",{},()=>[T])])):r.createCommentVNode("",!0),k,r.createElementVNode("pre",{ref:"code",class:"ssh-pre__content",innerHTML:e.content},null,8,v)],10,w)}var A=b(E,[["render",$]]);return A}); |
{ | ||
"name": "simple-syntax-highlighter", | ||
"version": "2.0.7", | ||
"version": "2.2.0", | ||
"description": "A Vue.js syntax highlighter that reads the source code you give it and highlights it, for Humans.", | ||
@@ -39,3 +39,3 @@ "author": "Antoni Andre <antoniandre.web@gmail.com>", | ||
"@babel/eslint-parser": "^7.15.8", | ||
"@vitejs/plugin-vue": "^1.9.3", | ||
"@vitejs/plugin-vue": "^1.9.4", | ||
"@vue/compiler-sfc": "^3.2.20", | ||
@@ -45,9 +45,9 @@ "@vue/eslint-config-standard": "^6.1.0", | ||
"eslint": "^7.32.0", | ||
"eslint-plugin-import": "^2.24.2", | ||
"eslint-plugin-import": "^2.25.2", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"eslint-plugin-vue": "^7.19.1", | ||
"eslint-plugin-promise": "^5.1.1", | ||
"eslint-plugin-vue": "^7.20.0", | ||
"rollup-plugin-delete": "^2.0.0", | ||
"sass": "^1.42.1", | ||
"vite": "^2.6.7", | ||
"sass": "^1.43.4", | ||
"vite": "^2.6.13", | ||
"vite-plugin-pug": "^0.3.0", | ||
@@ -54,0 +54,0 @@ "vue": "^3.2.20", |
@@ -31,5 +31,5 @@ # Simple Syntax Highlighter | ||
## Browser Support | ||
![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) | | ||
--- | --- | --- | --- | --- | --- | | ||
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11+ ✔ | | ||
![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | | ||
--- | --- | --- | --- | --- | | ||
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | | ||
@@ -55,2 +55,3 @@ ___ | ||
- __Version 1.5.0__ Removed support for IE - it's finally over. :tada: | ||
- __Version 1.4.0__ Added Pug language support | ||
@@ -57,0 +58,0 @@ - __Version 1.3.0__ Added the `copy-button` option |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
47778
404
60
0