simple-syntax-highlighter
Advanced tools
Comparing version 1.5.1 to 1.6.0
@@ -1,2 +0,3 @@ | ||
"use strict";var y=function(){var t=this,n=t.$createElement,a=t._self._c||n;return a("div",{staticClass:"ssh-pre",class:{"ssh-pre--dark":t.dark},attrs:{"data-type":t.language,"data-label":t.label||null}},[t.copyButton?a("button",{staticClass:"ssh-pre__copy",on:{click:t.copyCode}},[t._t("copy-button",function(){return[t._v("Copy")]})],2):t._e(),t._v(" "),a("pre",{ref:"code",staticClass:"ssh-pre__content",domProps:{innerHTML:t._s(t.content)}})])},v=[];function _(t,n,a,u,e,o,c,i){var r=typeof t=="function"?t.options:t;n&&(r.render=n,r.staticRenderFns=a,r._compiled=!0),u&&(r.functional=!0),o&&(r._scopeId="data-v-"+o);var l;if(c?(l=function(p){p=p||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!p&&typeof __VUE_SSR_CONTEXT__!="undefined"&&(p=__VUE_SSR_CONTEXT__),e&&e.call(this,p),p&&p._registeredComponents&&p._registeredComponents.add(c)},r._ssrRegister=l):e&&(l=i?function(){e.call(this,(r.functional?this.parent:this).$root.$options.shadowRoot)}:e),l)if(r.functional){r._injectStyles=l;var d=r.render;r.render=function(b,h){return l.call(h),d(b,h)}}else{var m=r.beforeCreate;r.beforeCreate=m?[].concat(m,l):[l]}return{exports:t,options:r}}const s={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*.*?\*\/)/,htmlTag:/(<([^>])*>)/,htmlentity:/(&[a-zA-Z0-9#]+;)/,punctuation:/(!==?|(?:[[\](){}.:;,+\-?=!]|<|>)+|&&|\|\|)/,number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},g={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/}},E={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},w={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}},x={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(g),content:"",slotTexts:""}),methods:{htmlize(t){return t.replace(/&(lt|gt|amp);/g,(n,a)=>({lt:"<",gt:">",amp:"&"})[a])},unhtmlize(t){return t.replace(/[<>]/g,n=>({"<":"<",">":">"})[n])},isColorDark(t){let n,a,u,e,o,c;if(n=t.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))u=parseInt(n[1])<=100,e=parseInt(n[2])<=100,o=parseInt(n[3])<=100,c=parseFloat(n[4])<.3;else if(a=t.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const i=a[1].length===3;u=parseInt(a[1][0])<=9,e=parseInt(a[1][i?1:2])<=9,o=parseInt(a[1][i?2:4])<=9}return(u&&e&&o||u&&e&&!o||!u&&e&&o)&&!c},createRegexPattern(){let t="";const n=[];for(const a in g[this.language]){const u=w[this.language][a]||1;for(let e=0;e<u;e++)n.push(a);t+=(t?"|":"")+g[this.language][a].source}return[t,n]},syntaxHighlightHtmlTag(t){const n=(u,e,o,c,i)=>`${e}<span class="attribute">${o}</span>`+(i?'<span class="punctuation">=</span>':"")+(i?`<span class="quote">${c||""}${i||""}${c||""}</span>`:"");let a=(t[2]||"").replace(E[this.language],n);if(this.language==="pug"){const u=(t[1]||"").replace(/#[a-z\d-]+/g,e=>`<span class="id">${e}</span>`).replace(/\.[a-z\d-]+/g,e=>`<span class="class">${e}</span>`);return a&&(a='<span class="punctuation">(</span>'+a+'<span class="punctuation">)</span>'),`<span class="tag-name">${t[0]||""}</span>${u}${a}`+(t[3]?'<span class="punctuation">.</span>':"")+(t[4]||"")+(t[5]?`<span class="text">${t[5]}</span>`:"")}return`<span class="punctuation">${t[0]}</span><span class="tag-name">${t[1]}</span>`+a+`<span class="punctuation">${t[3]}</span>`},syntaxHighlightContent(t){if(!this.knownLanguages.includes(this.language))return t;const[n,a]=this.createRegexPattern();return this.unhtmlize(t).replace(new RegExp(n,"gs"),(u,...e)=>{e=e.slice(0,e.length-2);let o;const c=this.language==="pug";let i=e.find((l,d)=>l&&(o=a[d])&&l);if(o==="quote")i=this.unhtmlize(i);else if(o==="comment")if(c){const[l,d,m]=e.slice(a.indexOf("comment"));i=`${l}${d}${this.unhtmlize(m)}`}else i=this.unhtmlize(i);else{if(o==="text"&&c)return`${e[0]}<span class="punctuation">|</span>${e[1]}<span class="text">${e[2]}</span>`;if(o==="text2"&&c){const[,,,l,d,m]=e,p=this.syntaxHighlightContent(d);return`${l}${p}<span class="punctuation">.</span> | ||
<span class="text">${m}</span>`}else{if(o==="tag"&&["xml","html","html-vue","pug"].includes(this.language))return this.syntaxHighlightHtmlTag(e.slice(a.indexOf("tag")));if(o==="variable"&&i[0]==="."&&this.language==="js")return`<span class="punctuation">.</span><span class="obj-attr">${i.substr(1)}</span>`}}let r="";return o==="color"&&this.language==="css"&&(r=` style="background-color: ${i};color: #${this.isColorDark(i)?"fff":"000"}"`),o&&`<span class="${o}"${r}>${i}</span>`||""})},checkSlots(){const t=(this.$slots.default||[]).map(n=>n.text||"").join("");this.slotTexts!==t&&(this.slotTexts=t,this.content=this.syntaxHighlightContent(this.slotTexts))},copyCode(t){t.target.insertAdjacentHTML("afterend",`<textarea id="clipboard-textarea">${this.$refs.code.innerText}</textarea>`);const n=document.getElementById("clipboard-textarea");n.select(),n.setSelectionRange(0,99999),document.execCommand("copy"),n.remove(),this.$emit("copied",this.$refs.code.innerText)}},mounted(){this.checkSlots()},beforeUpdate(){this.reactive&&this.checkSlots()}},f={};var T=_(x,y,v,!1,$,null,null,null);function $(t){for(let n in f)this[n]=f[n]}var k=function(){return T.exports}();module.exports=k; | ||
"use strict";const c=require("vue");const y=(t,e)=>{const n=t.__vccOpts||t;for(const[o,a]of e)n[o]=a;return n},i={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*.*?(?:\*\/|$))/,doctype:/(<\!DOCTYPE.*?>)/,htmlTag:/<(?:([a-zA-Z][\w\d-]*)((?:[\w\d\- ]+=(?:"[^"]*"|'[^']*'))*|(?:(?!&(?:lt|amp);).)*?)(\s*\/?)|(\/?)([a-zA-Z][\w\d-]*))>/,htmlentity:/(&(?:[a-zA-Z]+|#x?\d+);)/,punctuation:new RegExp("(!==?|(?:[[\\](){}.:,+\\-?=!])+|(?<!&(?:[a-zA-Z]+|#x?\\d+));|\\|\\||<|>|&)"),number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},h={shell:{quote:i.quote,comment:/(#.*?)(?:\n|$)/,keyword:/\b(p?npm|yarn|i(?:nstall)?|run|audit|outdated|update|publish|whoami|cd|sudo|chmod|chown|ls|cat|vim?|scp|rm|mv|mkdir|ln|open|cwd|which|clear|curl|ping|systemctl|echo|export|open|bash|exit)\b/,param:/( --(?:save|save-dev))(?:\s|$)/},xml:{doctype:i.doctype,quote:i.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:i.htmlentity,tag:i.htmlTag},html:{doctype:i.doctype,quote:i.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:i.htmlentity,tag:i.htmlTag},"html-vue":{doctype:i.doctype,quote:i.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:i.htmlentity,tag:i.htmlTag},pug:{text:/((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\s*(?:\n|$)))/,text2:/([ \t]*)([.#\-\w\d]+(?:\([^)]*\))*)\.\n((?:\n+(?=\4[ \t]+)|(?=\4[ \t]+).+?(?:\n|$)*?)*)(?=\s*(?:\n|$))/,quote:i.quote,comment:/(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\10[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/,tag:/([a-zA-Z][\w\d-]*|)([.#][a-zA-Z][-.\w\d]*|)\b(?:\(((?:[\w\d\- ]+=(?:"[^"]*"|'[^']*'))*|(?:(?!&(?:lt|amp);).)*?)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/,"inline-tag":/#\[([^\[\]]+)\]/},css:{comment:/(\/\*.+?(?:\*\/|$))/,quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,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:i.number,color:/(transparent|#(?:[\da-fA-F]{6}|[\da-fA-F]{3})|rgba?\([\d., ]*\))/,htmlentity:i.htmlentity,punctuation:/([:,;{}@#()!]+)/,attribute:/([a-zA-Z-]+)(?=\s*:)/,unit:/(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/,error:/([:,;{}@#()!]+|<|>|&)/},json:{quote:/("(?:\\"|[^"])*")/,number:i.number,boolean:i.boolean,punctuation:/([[\](){}:,]+)/,error:/(&(:?lt|gt|amp);|(?!\s).)/},js:{quote:i.quote,comment:i.comment,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:i.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(?:Element)?|window|console|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|Proxy|WeakMap|WeakSet|Symbol|SyncManager|File(?:Reader)?|DataTransfer|DocumentFragment|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN|atob|btoa|getComputedStyle)(?=\W)/,htmlentity:i.htmlentity,punctuation:/(!==?|[[\]!(){}:;,+\-%*/?=]+|\.+(?![a-zA-Z])|\|\||<|>|&)/,variable:/(\.?[a-zA-Z_][\w\d]*)/,"external-var":/(\$|jQuery|JSON)(?=\W|$)/},php:{quote:i.quote,comment:i.comment,special:/(<\?(?:php)?|\?>|__(?:DIR|FILE|LINE|CLASS|METHOD|FUNCTION|NAMESPACE|TRAIT)__)/,punctuation:i.punctuation,number:i.number,boolean:i.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:i.quote,comment:/((?:\-\-|#)\s.*?(?:\n|$)|\/\*.*?\*\/)/,punctuation:i.punctuation,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:i.boolean,keyword:/\b(\*|DECLARE|BEGIN|END|RETURNS|FUNCTION|CREATE|DATABASE|TABLE|VIEW|COLUMN|INDEX|GRANT|REVOKE|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|CHECK|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|THEN|NULL|EXISTS|UNIQUE|SELECT|UPDATE|DELETE|(?:INSERT|REPLACE)(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER|CROSS) |)JOIN|AS|ON|COUNT|AVG|SUM|MIN|MAX|CASE|TO|WHEN|BETWEEN|AND|OR|NOT|IN|LIKE|IS|CONCAT|SUBSTRING|CURRENT_(?:DATE|TIMESTAMP)|USING|HAVING?)(?=\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/}},b={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},E={shell:{quote:2},xml:{quote:2,tag:5},html:{quote:2,tag:5},"html-vue":{quote:2,tag:5},pug:{text:3,text2:3,quote:2,comment:3,tag:6},json:{},php:{quote:2},sql:{quote:2},css:{quote:2},js:{quote:2}},m=t=>t.map(e=>{if(!e.children||typeof e.children=="string")return e.children||"";if(Array.isArray(e.children))return m(e.children);if(e.children.default)return m(e.children.default())}).join(""),x={name:"sshpre",props:{language:{type:String,default:""},label:{type:[String,Boolean],default:!1},tab:{type:[Boolean,String],default:" "},dark:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!1},editable:{type:Boolean,default:!0}},data:()=>({knownLanguages:Object.keys(h),content:"",slotTexts:""}),methods:{htmlize(t){return t.replace(/&(lt|gt|amp);/g,(e,n)=>({lt:"<",gt:">",amp:"&"})[n])},unhtmlize(t){return t.replace(/[<>]/g,e=>({"<":"<",">":">"})[e])},isColorDark(t){let e,n,o,a,s,r;if(e=t.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))o=parseInt(e[1])<=100,a=parseInt(e[2])<=100,s=parseInt(e[3])<=100,r=parseFloat(e[4])<.3;else if(n=t.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const l=n[1].length===3;o=parseInt(n[1][0])<=9,a=parseInt(n[1][l?1:2])<=9,s=parseInt(n[1][l?2:4])<=9}return(o&&a&&s||o&&a&&!s||!o&&a&&s)&&!r},createRegexPattern(){let t="";const e=[];for(const n in h[this.language]){const o=E[this.language][n]||1;for(let a=0;a<o;a++)e.push(n);t+=(t?"|":"")+h[this.language][n].source}return[t,e]},syntaxHighlightHtmlTag(t){const e=(n,o,a,s,r)=>`${o}<span class="attribute">${a}</span>`+(s||r?'<span class="punctuation">=</span>':"")+(s||r?`<span class="quote">${s||""}${r||""}${s||""}</span>`:"");if(this.language==="pug"){let[n,o="",a="",s="",r="",l=""]=t;return o=o.replace(/#[a-z\d-]+/g,p=>`<span class="id">${p}</span>`).replace(/\.[a-z\d-]+/g,p=>`<span class="class">${p}</span>`),a&&(a=a.replace(b.pug,e),a='<span class="punctuation">(</span>'+a+'<span class="punctuation">)</span>'),l&&(l=this.highlightPugInlineTag(l)),`<span class="tag-name">${n}</span>${o}${a}`+(s?'<span class="punctuation">.</span>':"")+(r||"")+(l?`<span class="text">${l}</span>`:"")}else{const[n,o="",a="",s="",r]=t,l=o.replace(b[this.language],e);return`<span class="punctuation"><${s}</span><span class="tag-name">${n||r}</span>`+l+`<span class="punctuation">${a}></span>`}},highlightPugInlineTag(t){return t.replace(new RegExp(h.pug["inline-tag"],"gs"),(e,n)=>'<span class="inline-tag">#[</span>'+n.replace(new RegExp(h.pug.tag,"s"),(o,...a)=>(a=a.slice(0,a.length-2),this.syntaxHighlightHtmlTag(a)))+'<span class="inline-tag">]</span>')},highlightInPre(){if(this.knownLanguages.includes(this.language)){const t=this.getCaretPositionInPlainText();this.$refs.code.innerHTML=this.syntaxHighlightContent(this.$refs.code.innerText),this.reinjectCaret(this.$refs.code.childNodes,t)}},getCaretPositionInPlainText(){const t=window.getSelection();t.collapseToEnd();const e=new Range;return e.setStart(this.$refs.code,0),e.setEnd(t.extentNode,t.extentOffset),e.toString().length},reinjectCaret(t,e){var o,a;let n=0;for(const s of t){const r=((o=s.innerText)==null?void 0:o.length)||s.length;if(n+r>=e){s.childNodes.length>1?this.reinjectCaret(s.childNodes,e-n):document.getSelection().setPosition(((a=s.childNodes)==null?void 0:a[0])||s,e-n);break}n+=r}},onKeydown(t){switch(t.which){case 9:this.injectAtCaret(this.tab),t.preventDefault();break;case 13:this.injectAtCaret(` | ||
`),t.preventDefault();break}},injectAtCaret(t){const e=window.getSelection(),n=e.getRangeAt(0),o=document.createTextNode(t);n.insertNode(o),e.collapseToEnd()},syntaxHighlightContent(t){if(!this.knownLanguages.includes(this.language))return t;const[e,n]=this.createRegexPattern();return this.unhtmlize(t.replace(/&/g,"&")).replace(new RegExp(e,"gs"),(o,...a)=>{a=a.slice(0,a.length-2);let s;const r=this.language==="pug";let l=a.find((u,d)=>u&&(s=n[d])&&u);if(["punctuation","quote","htmlentity"].includes(s))l=this.unhtmlize(l);else if(s==="comment")if(r){const[u,d,g]=a.slice(n.indexOf("comment"));l=`${u}${d}${this.unhtmlize(g)}`}else l=this.unhtmlize(l);else if(s==="text"&&r){let[u,d,g]=a;return g=this.highlightPugInlineTag(g),`${u}<span class="punctuation">|</span>${d}<span class="text">${g}</span>`}else if(s==="text2"&&r){const[,,,u,d,g]=a,f=this.syntaxHighlightContent(d);return`${u}${f}<span class="punctuation">.</span> | ||
<span class="text">${g}</span>`}else{if(s==="tag"&&["xml","html","html-vue","pug"].includes(this.language))return this.syntaxHighlightHtmlTag(a.slice(n.indexOf("tag")));if(s==="variable"&&l[0]==="."&&this.language==="js")return`<span class="punctuation">.</span><span class="obj-attr">${l.substr(1)}</span>`}let p="";return s==="color"&&this.language==="css"&&(p=` style="background-color: ${l};color: #${this.isColorDark(l)?"fff":"000"}"`),s&&`<span class="${s}"${p}>${l}</span>`||""})},getSlotContent(){return this.$slots.default&&m(this.$slots.default())||""},copyCode(t){t.target.insertAdjacentHTML("afterend",`<textarea id="clipboard-textarea">${this.$refs.code.innerText}</textarea>`);const e=document.getElementById("clipboard-textarea");e.select(),e.setSelectionRange(0,99999),document.execCommand("copy"),e.remove(),this.$emit("copied",this.$refs.code.innerText)}},mounted(){const t=this.getSlotContent();this.$refs.code.innerText=t,this.$refs.code.innerHTML=this.syntaxHighlightContent(this.$refs.code.innerText)},beforeUpdate(){this.$refs.code.innerHTML=this.syntaxHighlightContent(this.getSlotContent())}},T=["data-type","data-label"],w=["contenteditable"],N={class:"ssh-pre__original"};function C(t,e,n,o,a,s){return c.openBlock(),c.createElementBlock("div",{class:c.normalizeClass(["ssh-pre",{"ssh-pre--dark":n.dark}]),"data-type":n.language,"data-label":n.label||null},[n.copyButton?(c.openBlock(),c.createElementBlock("button",{key:0,class:"ssh-pre__copy",onClick:e[0]||(e[0]=(...r)=>s.copyCode&&s.copyCode(...r))},[c.renderSlot(t.$slots,"copy-button",{},()=>[c.createTextVNode("Copy")])])):c.createCommentVNode("",!0),c.createTextVNode(),c.createElementVNode("pre",{ref:"code",class:"ssh-pre__content",contenteditable:n.editable?"true":"false",onKeydown:e[1]||(e[1]=r=>n.editable&&s.onKeydown(r)),onInput:e[2]||(e[2]=(...r)=>s.highlightInPre&&s.highlightInPre(...r))}," ",40,w),c.createTextVNode(),c.createElementVNode("div",N,[c.renderSlot(t.$slots,"default")])],10,T)}const A=y(x,[["render",C]]);module.exports=A; |
@@ -1,98 +0,43 @@ | ||
var render = function() { | ||
var _vm = this; | ||
var _h = _vm.$createElement; | ||
var _c = _vm._self._c || _h; | ||
return _c("div", { staticClass: "ssh-pre", class: { "ssh-pre--dark": _vm.dark }, attrs: { "data-type": _vm.language, "data-label": _vm.label || null } }, [_vm.copyButton ? _c("button", { staticClass: "ssh-pre__copy", on: { "click": _vm.copyCode } }, [_vm._t("copy-button", function() { | ||
return [_vm._v("Copy")]; | ||
})], 2) : _vm._e(), _vm._v(" "), _c("pre", { ref: "code", staticClass: "ssh-pre__content", domProps: { "innerHTML": _vm._s(_vm.content) } })]); | ||
}; | ||
var staticRenderFns = []; | ||
var simpleSyntaxHighlighter_vue_vue_type_style_index_0_lang = ""; | ||
function normalizeComponent(scriptExports, render2, staticRenderFns2, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) { | ||
var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports; | ||
if (render2) { | ||
options.render = render2; | ||
options.staticRenderFns = staticRenderFns2; | ||
options._compiled = true; | ||
} | ||
if (functionalTemplate) { | ||
options.functional = true; | ||
} | ||
if (scopeId) { | ||
options._scopeId = "data-v-" + scopeId; | ||
} | ||
var hook; | ||
if (moduleIdentifier) { | ||
hook = function(context) { | ||
context = context || this.$vnode && this.$vnode.ssrContext || this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext; | ||
if (!context && typeof __VUE_SSR_CONTEXT__ !== "undefined") { | ||
context = __VUE_SSR_CONTEXT__; | ||
} | ||
if (injectStyles) { | ||
injectStyles.call(this, context); | ||
} | ||
if (context && context._registeredComponents) { | ||
context._registeredComponents.add(moduleIdentifier); | ||
} | ||
}; | ||
options._ssrRegister = hook; | ||
} else if (injectStyles) { | ||
hook = shadowMode ? function() { | ||
injectStyles.call(this, (options.functional ? this.parent : this).$root.$options.shadowRoot); | ||
} : injectStyles; | ||
} | ||
if (hook) { | ||
if (options.functional) { | ||
options._injectStyles = hook; | ||
var originalRender = options.render; | ||
options.render = function renderWithStyleInjection(h, context) { | ||
hook.call(context); | ||
return originalRender(h, context); | ||
}; | ||
} else { | ||
var existing = options.beforeCreate; | ||
options.beforeCreate = existing ? [].concat(existing, hook) : [hook]; | ||
} | ||
} | ||
return { | ||
exports: scriptExports, | ||
options | ||
}; | ||
} | ||
const regexBasics = { | ||
import { openBlock as f, createElementBlock as b, normalizeClass as w, renderSlot as y, createTextVNode as h, createCommentVNode as C, createElementVNode as E } from "vue"; | ||
const N = (t, e) => { | ||
const n = t.__vccOpts || t; | ||
for (const [o, a] of e) | ||
n[o] = a; | ||
return n; | ||
}, i = { | ||
quote: /("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/, | ||
comment: /(\/\/.*?(?:\n|$)|\/\*.*?\*\/)/, | ||
htmlTag: /(<([^>])*>)/, | ||
htmlentity: /(&[a-zA-Z0-9#]+;)/, | ||
punctuation: /(!==?|(?:[[\](){}.:;,+\-?=!]|<|>)+|&&|\|\|)/, | ||
comment: /(\/\/.*?(?:\n|$)|\/\*.*?(?:\*\/|$))/, | ||
doctype: /(<\!DOCTYPE.*?>)/, | ||
htmlTag: /<(?:([a-zA-Z][\w\d-]*)((?:[\w\d\- ]+=(?:"[^"]*"|'[^']*'))*|(?:(?!&(?:lt|amp);).)*?)(\s*\/?)|(\/?)([a-zA-Z][\w\d-]*))>/, | ||
htmlentity: /(&(?:[a-zA-Z]+|#x?\d+);)/, | ||
punctuation: new RegExp("(!==?|(?:[[\\](){}.:,+\\-?=!])+|(?<!&(?:[a-zA-Z]+|#x?\\d+));|\\|\\||<|>|&)"), | ||
number: /(-?(?:\.\d+|\d+(?:\.\d+)?))/, | ||
boolean: /\b(true|false)\b/ | ||
}; | ||
const dictionary = { | ||
}, p = { | ||
shell: { | ||
quote: regexBasics.quote, | ||
quote: i.quote, | ||
comment: /(#.*?)(?:\n|$)/, | ||
keyword: /(?:^|\b)(npm|yarn|install|run)(?:\b|$)/, | ||
keyword: /\b(p?npm|yarn|i(?:nstall)?|run|audit|outdated|update|publish|whoami|cd|sudo|chmod|chown|ls|cat|vim?|scp|rm|mv|mkdir|ln|open|cwd|which|clear|curl|ping|systemctl|echo|export|open|bash|exit)\b/, | ||
param: /( --(?:save|save-dev))(?:\s|$)/ | ||
}, | ||
xml: { | ||
doctype: /(<\!DOCTYPE.*?>)/, | ||
quote: regexBasics.quote, | ||
comment: /(<!--.*?-->)/, | ||
htmlentity: regexBasics.htmlentity, | ||
tag: /(<\/?)([a-zA-Z\-:]+)(.*?)(\/?>)/ | ||
doctype: i.doctype, | ||
quote: i.quote, | ||
comment: /(<!--.*?(?:-->|$))/, | ||
htmlentity: i.htmlentity, | ||
tag: i.htmlTag | ||
}, | ||
html: { | ||
doctype: /(DOCTYPE)/, | ||
quote: regexBasics.quote, | ||
comment: /(<!--.*?-->)/, | ||
htmlentity: regexBasics.htmlentity, | ||
tag: /(<\/?)([a-z]\w*)(.*?)(\/?>)/ | ||
doctype: i.doctype, | ||
quote: i.quote, | ||
comment: /(<!--.*?(?:-->|$))/, | ||
htmlentity: i.htmlentity, | ||
tag: i.htmlTag | ||
}, | ||
"html-vue": { | ||
doctype: /(DOCTYPE)/, | ||
quote: regexBasics.quote, | ||
comment: /(<!--.*?-->)/, | ||
htmlentity: regexBasics.htmlentity, | ||
tag: /(<\/?)([a-zA-Z][\w\d-]*)((?:.|\s)*?)(\/?>)/ | ||
doctype: i.doctype, | ||
quote: i.quote, | ||
comment: /(<!--.*?(?:-->|$))/, | ||
htmlentity: i.htmlentity, | ||
tag: i.htmlTag | ||
}, | ||
@@ -102,13 +47,13 @@ pug: { | ||
text2: /([ \t]*)([.#\-\w\d]+(?:\([^)]*\))*)\.\n((?:\n+(?=\4[ \t]+)|(?=\4[ \t]+).+?(?:\n|$)*?)*)(?=\s*(?:\n|$))/, | ||
quote: regexBasics.quote, | ||
quote: i.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: /(!==?|(?:[#[\]().,+\-?=!|]|<|>)+)/ | ||
tag: /([a-zA-Z][\w\d-]*|)([.#][a-zA-Z][-.\w\d]*|)\b(?:\(((?:[\w\d\- ]+=(?:"[^"]*"|'[^']*'))*|(?:(?!&(?:lt|amp);).)*?)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/, | ||
"inline-tag": /#\[([^\[\]]+)\]/ | ||
}, | ||
css: { | ||
quote: regexBasics.quote, | ||
comment: /(\/\*.*?\*\/)/, | ||
comment: /(\/\*.+?(?:\*\/|$))/, | ||
quote: /("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/, | ||
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)/, | ||
"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\-]+)/, | ||
@@ -121,35 +66,36 @@ selector: /((?:[.#-\w*+ >:,[\]="~\n]|>)+)(?=\s*\{)/, | ||
"value keyword important": /( ?!important)/, | ||
number: regexBasics.number, | ||
number: i.number, | ||
color: /(transparent|#(?:[\da-fA-F]{6}|[\da-fA-F]{3})|rgba?\([\d., ]*\))/, | ||
htmlentity: /(&.*?;)/, | ||
punctuation: /([:,;{}@#()!]+|<|>)/, | ||
htmlentity: i.htmlentity, | ||
punctuation: /([:,;{}@#()!]+)/, | ||
attribute: /([a-zA-Z-]+)(?=\s*:)/, | ||
unit: /(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/ | ||
unit: /(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/, | ||
error: /([:,;{}@#()!]+|<|>|&)/ | ||
}, | ||
json: { | ||
quote: regexBasics.quote, | ||
comment: regexBasics.comment, | ||
number: regexBasics.number, | ||
boolean: regexBasics.boolean, | ||
punctuation: /([[\](){}:;,-]+)/ | ||
quote: /("(?:\\"|[^"])*")/, | ||
number: i.number, | ||
boolean: i.boolean, | ||
punctuation: /([[\](){}:,]+)/, | ||
error: /(&(:?lt|gt|amp);|(?!\s).)/ | ||
}, | ||
js: { | ||
quote: regexBasics.quote, | ||
comment: regexBasics.comment, | ||
quote: i.quote, | ||
comment: i.comment, | ||
number: /\b(\d+(?:\.\d+)?|null)\b/, | ||
boolean: regexBasics.boolean, | ||
boolean: i.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])|&&|\|\|)/, | ||
keyword: /\b(new|getElementsBy(?:Tag|Class|)Name|getElementById|querySelector|querySelectorAll|arguments|if|else|do|return|case|default|(?:f|F)unction|typeof|instanceof|undefined|document(?:Element)?|window|console|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|Proxy|WeakMap|WeakSet|Symbol|SyncManager|File(?:Reader)?|DataTransfer|DocumentFragment|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN|atob|btoa|getComputedStyle)(?=\W)/, | ||
htmlentity: i.htmlentity, | ||
punctuation: /(!==?|[[\]!(){}:;,+\-%*/?=]+|\.+(?![a-zA-Z])|\|\||<|>|&)/, | ||
variable: /(\.?[a-zA-Z_][\w\d]*)/, | ||
htmlentity: /(&.*?;)/, | ||
"external-var": /(\$|jQuery|JSON)(?=\W|$)/ | ||
}, | ||
php: { | ||
quote: regexBasics.quote, | ||
comment: regexBasics.comment, | ||
special: /(<\?php|\?>|__(?:DIR|FILE|LINE)__)/, | ||
punctuation: regexBasics.punctuation, | ||
number: regexBasics.number, | ||
boolean: regexBasics.boolean, | ||
quote: i.quote, | ||
comment: i.comment, | ||
special: /(<\?(?:php)?|\?>|__(?:DIR|FILE|LINE|CLASS|METHOD|FUNCTION|NAMESPACE|TRAIT)__)/, | ||
punctuation: i.punctuation, | ||
number: i.number, | ||
boolean: i.boolean, | ||
variable: /(\$[\w\d_]+)/, | ||
@@ -159,24 +105,22 @@ 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: regexBasics.quote, | ||
quote: i.quote, | ||
comment: /((?:\-\-|#)\s.*?(?:\n|$)|\/\*.*?\*\/)/, | ||
punctuation: regexBasics.punctuation, | ||
punctuation: i.punctuation, | ||
number: /\b(\d+(?:\.\d+)?|null)\b/, | ||
boolean: regexBasics.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|$)/, | ||
boolean: i.boolean, | ||
keyword: /\b(\*|DECLARE|BEGIN|END|RETURNS|FUNCTION|CREATE|DATABASE|TABLE|VIEW|COLUMN|INDEX|GRANT|REVOKE|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|CHECK|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|THEN|NULL|EXISTS|UNIQUE|SELECT|UPDATE|DELETE|(?:INSERT|REPLACE)(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER|CROSS) |)JOIN|AS|ON|COUNT|AVG|SUM|MIN|MAX|CASE|TO|WHEN|BETWEEN|AND|OR|NOT|IN|LIKE|IS|CONCAT|SUBSTRING|CURRENT_(?:DATE|TIMESTAMP)|USING|HAVING?)(?=\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/ | ||
} | ||
}; | ||
const attributesRegex = { | ||
xml: /(\s*)([a-zA-Z\d\-:]+)=("|')(.*?)\3/g, | ||
html: /(\s*)([a-zA-Z-]+)=("|')(.*?)\3/g, | ||
}, x = { | ||
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 | ||
}; | ||
const multiCapturesMapping = { | ||
}, A = { | ||
shell: { quote: 2 }, | ||
xml: { quote: 2, tag: 4 }, | ||
html: { quote: 2, tag: 4 }, | ||
"html-vue": { quote: 2, tag: 4 }, | ||
xml: { quote: 2, tag: 5 }, | ||
html: { quote: 2, tag: 5 }, | ||
"html-vue": { quote: 2, tag: 5 }, | ||
pug: { text: 3, text2: 3, quote: 2, comment: 3, tag: 6 }, | ||
json: { quote: 2 }, | ||
json: {}, | ||
php: { quote: 2 }, | ||
@@ -186,14 +130,21 @@ sql: { quote: 2 }, | ||
js: { quote: 2 } | ||
}; | ||
const __vue2_script = { | ||
}, m = (t) => t.map((e) => { | ||
if (!e.children || typeof e.children == "string") | ||
return e.children || ""; | ||
if (Array.isArray(e.children)) | ||
return m(e.children); | ||
if (e.children.default) | ||
return m(e.children.default()); | ||
}).join(""), I = { | ||
name: "sshpre", | ||
props: { | ||
language: { type: String, default: "" }, | ||
label: { type: [String, Boolean], default: false }, | ||
reactive: { type: Boolean, default: false }, | ||
dark: { type: Boolean, default: false }, | ||
copyButton: { type: Boolean, default: false } | ||
label: { type: [String, Boolean], default: !1 }, | ||
tab: { type: [Boolean, String], default: " " }, | ||
dark: { type: Boolean, default: !1 }, | ||
copyButton: { type: Boolean, default: !1 }, | ||
editable: { type: Boolean, default: !0 } | ||
}, | ||
data: () => ({ | ||
knownLanguages: Object.keys(dictionary), | ||
knownLanguages: Object.keys(p), | ||
content: "", | ||
@@ -203,117 +154,167 @@ slotTexts: "" | ||
methods: { | ||
htmlize(string) { | ||
return string.replace(/&(lt|gt|amp);/g, (m0, m1) => ({ lt: "<", gt: ">", amp: "&" })[m1]); | ||
htmlize(t) { | ||
return t.replace(/&(lt|gt|amp);/g, (e, n) => ({ lt: "<", gt: ">", amp: "&" })[n]); | ||
}, | ||
unhtmlize(string) { | ||
return string.replace(/[<>]/g, (m) => ({ "<": "<", ">": ">" })[m]); | ||
unhtmlize(t) { | ||
return t.replace(/[<>]/g, (e) => ({ "<": "<", ">": ">" })[e]); | ||
}, | ||
isColorDark(colorString) { | ||
let rgbColor, hexColor, rDark, gDark, bDark, alphaLow; | ||
if (rgbColor = colorString.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/)) { | ||
rDark = parseInt(rgbColor[1]) <= 100; | ||
gDark = parseInt(rgbColor[2]) <= 100; | ||
bDark = parseInt(rgbColor[3]) <= 100; | ||
alphaLow = parseFloat(rgbColor[4]) < 0.3; | ||
} else if (hexColor = colorString.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)) { | ||
const has3chars = hexColor[1].length === 3; | ||
rDark = parseInt(hexColor[1][0]) <= 9; | ||
gDark = parseInt(hexColor[1][has3chars ? 1 : 2]) <= 9; | ||
bDark = parseInt(hexColor[1][has3chars ? 2 : 4]) <= 9; | ||
isColorDark(t) { | ||
let e, n, o, a, s, r; | ||
if (e = t.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/)) | ||
o = parseInt(e[1]) <= 100, a = parseInt(e[2]) <= 100, s = parseInt(e[3]) <= 100, r = parseFloat(e[4]) < 0.3; | ||
else if (n = t.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)) { | ||
const l = n[1].length === 3; | ||
o = parseInt(n[1][0]) <= 9, a = parseInt(n[1][l ? 1 : 2]) <= 9, s = parseInt(n[1][l ? 2 : 4]) <= 9; | ||
} | ||
return (rDark && gDark && bDark || rDark && gDark && !bDark || !rDark && gDark && bDark) && !alphaLow; | ||
return (o && a && s || o && a && !s || !o && a && s) && !r; | ||
}, | ||
createRegexPattern() { | ||
let pattern = ""; | ||
const classMap = []; | ||
for (const Class in dictionary[this.language]) { | ||
const capturesCount = multiCapturesMapping[this.language][Class] || 1; | ||
for (let i = 0; i < capturesCount; i++) | ||
classMap.push(Class); | ||
pattern += (pattern ? "|" : "") + dictionary[this.language][Class].source; | ||
let t = ""; | ||
const e = []; | ||
for (const n in p[this.language]) { | ||
const o = A[this.language][n] || 1; | ||
for (let a = 0; a < o; a++) | ||
e.push(n); | ||
t += (t ? "|" : "") + p[this.language][n].source; | ||
} | ||
return [pattern, classMap]; | ||
return [t, e]; | ||
}, | ||
syntaxHighlightHtmlTag(matches) { | ||
const renderAttributesList = (_, a, b, c, d) => `${a}<span class="attribute">${b}</span>` + (d ? '<span class="punctuation">=</span>' : "") + (d ? `<span class="quote">${c || ""}${d || ""}${c || ""}</span>` : ""); | ||
let attributesList = (matches[2] || "").replace(attributesRegex[this.language], renderAttributesList); | ||
syntaxHighlightHtmlTag(t) { | ||
const e = (n, o, a, s, r) => `${o}<span class="attribute">${a}</span>` + (s || r ? '<span class="punctuation">=</span>' : "") + (s || r ? `<span class="quote">${s || ""}${r || ""}${s || ""}</span>` : ""); | ||
if (this.language === "pug") { | ||
const idAndClasses = (matches[1] || "").replace(/#[a-z\d-]+/g, (m) => `<span class="id">${m}</span>`).replace(/\.[a-z\d-]+/g, (m) => `<span class="class">${m}</span>`); | ||
if (attributesList) { | ||
attributesList = `<span class="punctuation">(</span>` + attributesList + `<span class="punctuation">)</span>`; | ||
let [n, o = "", a = "", s = "", r = "", l = ""] = t; | ||
return o = o.replace(/#[a-z\d-]+/g, (g) => `<span class="id">${g}</span>`).replace(/\.[a-z\d-]+/g, (g) => `<span class="class">${g}</span>`), a && (a = a.replace(x.pug, e), a = '<span class="punctuation">(</span>' + a + '<span class="punctuation">)</span>'), l && (l = this.highlightPugInlineTag(l)), `<span class="tag-name">${n}</span>${o}${a}` + (s ? '<span class="punctuation">.</span>' : "") + (r || "") + (l ? `<span class="text">${l}</span>` : ""); | ||
} else { | ||
const [n, o = "", a = "", s = "", r] = t, l = o.replace(x[this.language], e); | ||
return `<span class="punctuation"><${s}</span><span class="tag-name">${n || r}</span>` + l + `<span class="punctuation">${a}></span>`; | ||
} | ||
}, | ||
highlightPugInlineTag(t) { | ||
return t.replace(new RegExp(p.pug["inline-tag"], "gs"), (e, n) => '<span class="inline-tag">#[</span>' + n.replace(new RegExp(p.pug.tag, "s"), (o, ...a) => (a = a.slice(0, a.length - 2), this.syntaxHighlightHtmlTag(a))) + '<span class="inline-tag">]</span>'); | ||
}, | ||
highlightInPre() { | ||
if (this.knownLanguages.includes(this.language)) { | ||
const t = this.getCaretPositionInPlainText(); | ||
this.$refs.code.innerHTML = this.syntaxHighlightContent(this.$refs.code.innerText), this.reinjectCaret(this.$refs.code.childNodes, t); | ||
} | ||
}, | ||
getCaretPositionInPlainText() { | ||
const t = window.getSelection(); | ||
t.collapseToEnd(); | ||
const e = new Range(); | ||
return e.setStart(this.$refs.code, 0), e.setEnd(t.extentNode, t.extentOffset), e.toString().length; | ||
}, | ||
reinjectCaret(t, e) { | ||
var o, a; | ||
let n = 0; | ||
for (const s of t) { | ||
const r = ((o = s.innerText) == null ? void 0 : o.length) || s.length; | ||
if (n + r >= e) { | ||
s.childNodes.length > 1 ? this.reinjectCaret(s.childNodes, e - n) : document.getSelection().setPosition(((a = s.childNodes) == null ? void 0 : a[0]) || s, e - n); | ||
break; | ||
} | ||
return `<span class="tag-name">${matches[0] || ""}</span>${idAndClasses}${attributesList}` + (matches[3] ? '<span class="punctuation">.</span>' : "") + (matches[4] || "") + (matches[5] ? `<span class="text">${matches[5]}</span>` : ""); | ||
n += r; | ||
} | ||
return `<span class="punctuation">${matches[0]}</span><span class="tag-name">${matches[1]}</span>` + attributesList + `<span class="punctuation">${matches[3]}</span>`; | ||
}, | ||
syntaxHighlightContent(string) { | ||
onKeydown(t) { | ||
switch (t.which) { | ||
case 9: | ||
this.injectAtCaret(this.tab), t.preventDefault(); | ||
break; | ||
case 13: | ||
this.injectAtCaret(` | ||
`), t.preventDefault(); | ||
break; | ||
} | ||
}, | ||
injectAtCaret(t) { | ||
const e = window.getSelection(), n = e.getRangeAt(0), o = document.createTextNode(t); | ||
n.insertNode(o), e.collapseToEnd(); | ||
}, | ||
syntaxHighlightContent(t) { | ||
if (!this.knownLanguages.includes(this.language)) | ||
return string; | ||
const [regexPattern, classMap] = this.createRegexPattern(); | ||
return this.unhtmlize(string).replace(new RegExp(regexPattern, "gs"), (m, ...matches) => { | ||
matches = matches.slice(0, matches.length - 2); | ||
let Class; | ||
const isPug = this.language === "pug"; | ||
let match = matches.find((m2, i) => m2 && (Class = classMap[i]) && m2); | ||
if (Class === "quote") | ||
match = this.unhtmlize(match); | ||
else if (Class === "comment") { | ||
if (isPug) { | ||
const [carretReturn, whitespaces, comment] = matches.slice(classMap.indexOf("comment")); | ||
match = `${carretReturn}${whitespaces}${this.unhtmlize(comment)}`; | ||
return t; | ||
const [e, n] = this.createRegexPattern(); | ||
return this.unhtmlize(t.replace(/&/g, "&")).replace(new RegExp(e, "gs"), (o, ...a) => { | ||
a = a.slice(0, a.length - 2); | ||
let s; | ||
const r = this.language === "pug"; | ||
let l = a.find((c, u) => c && (s = n[u]) && c); | ||
if (["punctuation", "quote", "htmlentity"].includes(s)) | ||
l = this.unhtmlize(l); | ||
else if (s === "comment") | ||
if (r) { | ||
const [c, u, d] = a.slice(n.indexOf("comment")); | ||
l = `${c}${u}${this.unhtmlize(d)}`; | ||
} else | ||
match = this.unhtmlize(match); | ||
} else if (Class === "text" && isPug) { | ||
return `${matches[0]}<span class="punctuation">|</span>${matches[1]}<span class="text">${matches[2]}</span>`; | ||
} else if (Class === "text2" && isPug) { | ||
const [, , , tabs, tagString, text] = matches; | ||
const tag = this.syntaxHighlightContent(tagString); | ||
return `${tabs}${tag}<span class="punctuation">.</span> | ||
<span class="text">${text}</span>`; | ||
} else if (Class === "tag" && ["xml", "html", "html-vue", "pug"].includes(this.language)) { | ||
return this.syntaxHighlightHtmlTag(matches.slice(classMap.indexOf("tag"))); | ||
} else if (Class === "variable" && match[0] === "." && this.language === "js") { | ||
return `<span class="punctuation">.</span><span class="obj-attr">${match.substr(1)}</span>`; | ||
l = this.unhtmlize(l); | ||
else if (s === "text" && r) { | ||
let [c, u, d] = a; | ||
return d = this.highlightPugInlineTag(d), `${c}<span class="punctuation">|</span>${u}<span class="text">${d}</span>`; | ||
} else if (s === "text2" && r) { | ||
const [, , , c, u, d] = a, T = this.syntaxHighlightContent(u); | ||
return `${c}${T}<span class="punctuation">.</span> | ||
<span class="text">${d}</span>`; | ||
} else { | ||
if (s === "tag" && ["xml", "html", "html-vue", "pug"].includes(this.language)) | ||
return this.syntaxHighlightHtmlTag(a.slice(n.indexOf("tag"))); | ||
if (s === "variable" && l[0] === "." && this.language === "js") | ||
return `<span class="punctuation">.</span><span class="obj-attr">${l.substr(1)}</span>`; | ||
} | ||
let styles = ""; | ||
if (Class === "color" && this.language === "css") { | ||
styles = ` style="background-color: ${match};color: #${this.isColorDark(match) ? "fff" : "000"}"`; | ||
} | ||
return Class && `<span class="${Class}"${styles}>${match}</span>` || ""; | ||
let g = ""; | ||
return s === "color" && this.language === "css" && (g = ` style="background-color: ${l};color: #${this.isColorDark(l) ? "fff" : "000"}"`), s && `<span class="${s}"${g}>${l}</span>` || ""; | ||
}); | ||
}, | ||
checkSlots() { | ||
const slotTexts = (this.$slots.default || []).map((slot) => slot.text || "").join(""); | ||
if (this.slotTexts !== slotTexts) { | ||
this.slotTexts = slotTexts; | ||
this.content = this.syntaxHighlightContent(this.slotTexts); | ||
} | ||
getSlotContent() { | ||
return this.$slots.default && m(this.$slots.default()) || ""; | ||
}, | ||
copyCode(e) { | ||
e.target.insertAdjacentHTML("afterend", `<textarea id="clipboard-textarea">${this.$refs.code.innerText}</textarea>`); | ||
const textarea = document.getElementById("clipboard-textarea"); | ||
textarea.select(); | ||
textarea.setSelectionRange(0, 99999); | ||
document.execCommand("copy"); | ||
textarea.remove(); | ||
this.$emit("copied", this.$refs.code.innerText); | ||
copyCode(t) { | ||
t.target.insertAdjacentHTML( | ||
"afterend", | ||
`<textarea id="clipboard-textarea">${this.$refs.code.innerText}</textarea>` | ||
); | ||
const e = document.getElementById("clipboard-textarea"); | ||
e.select(), e.setSelectionRange(0, 99999), document.execCommand("copy"), e.remove(), this.$emit("copied", this.$refs.code.innerText); | ||
} | ||
}, | ||
mounted() { | ||
this.checkSlots(); | ||
const t = this.getSlotContent(); | ||
this.$refs.code.innerText = t, this.$refs.code.innerHTML = this.syntaxHighlightContent(this.$refs.code.innerText); | ||
}, | ||
beforeUpdate() { | ||
if (this.reactive) | ||
this.checkSlots(); | ||
this.$refs.code.innerHTML = this.syntaxHighlightContent(this.getSlotContent()); | ||
} | ||
}, v = ["data-type", "data-label"], $ = ["contenteditable"], k = { class: "ssh-pre__original" }; | ||
function S(t, e, n, o, a, s) { | ||
return f(), b("div", { | ||
class: w(["ssh-pre", { "ssh-pre--dark": n.dark }]), | ||
"data-type": n.language, | ||
"data-label": n.label || null | ||
}, [ | ||
n.copyButton ? (f(), b("button", { | ||
key: 0, | ||
class: "ssh-pre__copy", | ||
onClick: e[0] || (e[0] = (...r) => s.copyCode && s.copyCode(...r)) | ||
}, [ | ||
y(t.$slots, "copy-button", {}, () => [ | ||
h("Copy") | ||
]) | ||
])) : C("", !0), | ||
h(), | ||
E("pre", { | ||
ref: "code", | ||
class: "ssh-pre__content", | ||
contenteditable: n.editable ? "true" : "false", | ||
onKeydown: e[1] || (e[1] = (r) => n.editable && s.onKeydown(r)), | ||
onInput: e[2] || (e[2] = (...r) => s.highlightInPre && s.highlightInPre(...r)) | ||
}, " ", 40, $), | ||
h(), | ||
E("div", k, [ | ||
y(t.$slots, "default") | ||
]) | ||
], 10, v); | ||
} | ||
const _ = /* @__PURE__ */ N(I, [["render", S]]); | ||
export { | ||
_ as default | ||
}; | ||
const __cssModules = {}; | ||
var __component__ = /* @__PURE__ */ normalizeComponent(__vue2_script, render, staticRenderFns, false, __vue2_injectStyles, null, null, null); | ||
function __vue2_injectStyles(context) { | ||
for (let o in __cssModules) { | ||
this[o] = __cssModules[o]; | ||
} | ||
} | ||
var simpleSyntaxHighlighter = /* @__PURE__ */ function() { | ||
return __component__.exports; | ||
}(); | ||
export { simpleSyntaxHighlighter as default }; |
@@ -1,2 +0,3 @@ | ||
(function(g,h){typeof exports=="object"&&typeof module!="undefined"?module.exports=h():typeof define=="function"&&define.amd?define(h):(g=typeof globalThis!="undefined"?globalThis:g||self,g.sshpre=h())})(this,function(){"use strict";var g=function(){var t=this,n=t.$createElement,a=t._self._c||n;return a("div",{staticClass:"ssh-pre",class:{"ssh-pre--dark":t.dark},attrs:{"data-type":t.language,"data-label":t.label||null}},[t.copyButton?a("button",{staticClass:"ssh-pre__copy",on:{click:t.copyCode}},[t._t("copy-button",function(){return[t._v("Copy")]})],2):t._e(),t._v(" "),a("pre",{ref:"code",staticClass:"ssh-pre__content",domProps:{innerHTML:t._s(t.content)}})])},h=[],C="";function v(t,n,a,u,e,o,c,i){var r=typeof t=="function"?t.options:t;n&&(r.render=n,r.staticRenderFns=a,r._compiled=!0),u&&(r.functional=!0),o&&(r._scopeId="data-v-"+o);var l;if(c?(l=function(p){p=p||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!p&&typeof __VUE_SSR_CONTEXT__!="undefined"&&(p=__VUE_SSR_CONTEXT__),e&&e.call(this,p),p&&p._registeredComponents&&p._registeredComponents.add(c)},r._ssrRegister=l):e&&(l=i?function(){e.call(this,(r.functional?this.parent:this).$root.$options.shadowRoot)}:e),l)if(r.functional){r._injectStyles=l;var d=r.render;r.render=function(k,y){return l.call(y),d(k,y)}}else{var m=r.beforeCreate;r.beforeCreate=m?[].concat(m,l):[l]}return{exports:t,options:r}}const s={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*.*?\*\/)/,htmlTag:/(<([^>])*>)/,htmlentity:/(&[a-zA-Z0-9#]+;)/,punctuation:/(!==?|(?:[[\](){}.:;,+\-?=!]|<|>)+|&&|\|\|)/,number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},f={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/}},_={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},E={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}},x={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(f),content:"",slotTexts:""}),methods:{htmlize(t){return t.replace(/&(lt|gt|amp);/g,(n,a)=>({lt:"<",gt:">",amp:"&"})[a])},unhtmlize(t){return t.replace(/[<>]/g,n=>({"<":"<",">":">"})[n])},isColorDark(t){let n,a,u,e,o,c;if(n=t.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))u=parseInt(n[1])<=100,e=parseInt(n[2])<=100,o=parseInt(n[3])<=100,c=parseFloat(n[4])<.3;else if(a=t.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const i=a[1].length===3;u=parseInt(a[1][0])<=9,e=parseInt(a[1][i?1:2])<=9,o=parseInt(a[1][i?2:4])<=9}return(u&&e&&o||u&&e&&!o||!u&&e&&o)&&!c},createRegexPattern(){let t="";const n=[];for(const a in f[this.language]){const u=E[this.language][a]||1;for(let e=0;e<u;e++)n.push(a);t+=(t?"|":"")+f[this.language][a].source}return[t,n]},syntaxHighlightHtmlTag(t){const n=(u,e,o,c,i)=>`${e}<span class="attribute">${o}</span>`+(i?'<span class="punctuation">=</span>':"")+(i?`<span class="quote">${c||""}${i||""}${c||""}</span>`:"");let a=(t[2]||"").replace(_[this.language],n);if(this.language==="pug"){const u=(t[1]||"").replace(/#[a-z\d-]+/g,e=>`<span class="id">${e}</span>`).replace(/\.[a-z\d-]+/g,e=>`<span class="class">${e}</span>`);return a&&(a='<span class="punctuation">(</span>'+a+'<span class="punctuation">)</span>'),`<span class="tag-name">${t[0]||""}</span>${u}${a}`+(t[3]?'<span class="punctuation">.</span>':"")+(t[4]||"")+(t[5]?`<span class="text">${t[5]}</span>`:"")}return`<span class="punctuation">${t[0]}</span><span class="tag-name">${t[1]}</span>`+a+`<span class="punctuation">${t[3]}</span>`},syntaxHighlightContent(t){if(!this.knownLanguages.includes(this.language))return t;const[n,a]=this.createRegexPattern();return this.unhtmlize(t).replace(new RegExp(n,"gs"),(u,...e)=>{e=e.slice(0,e.length-2);let o;const c=this.language==="pug";let i=e.find((l,d)=>l&&(o=a[d])&&l);if(o==="quote")i=this.unhtmlize(i);else if(o==="comment")if(c){const[l,d,m]=e.slice(a.indexOf("comment"));i=`${l}${d}${this.unhtmlize(m)}`}else i=this.unhtmlize(i);else{if(o==="text"&&c)return`${e[0]}<span class="punctuation">|</span>${e[1]}<span class="text">${e[2]}</span>`;if(o==="text2"&&c){const[,,,l,d,m]=e,p=this.syntaxHighlightContent(d);return`${l}${p}<span class="punctuation">.</span> | ||
<span class="text">${m}</span>`}else{if(o==="tag"&&["xml","html","html-vue","pug"].includes(this.language))return this.syntaxHighlightHtmlTag(e.slice(a.indexOf("tag")));if(o==="variable"&&i[0]==="."&&this.language==="js")return`<span class="punctuation">.</span><span class="obj-attr">${i.substr(1)}</span>`}}let r="";return o==="color"&&this.language==="css"&&(r=` style="background-color: ${i};color: #${this.isColorDark(i)?"fff":"000"}"`),o&&`<span class="${o}"${r}>${i}</span>`||""})},checkSlots(){const t=(this.$slots.default||[]).map(n=>n.text||"").join("");this.slotTexts!==t&&(this.slotTexts=t,this.content=this.syntaxHighlightContent(this.slotTexts))},copyCode(t){t.target.insertAdjacentHTML("afterend",`<textarea id="clipboard-textarea">${this.$refs.code.innerText}</textarea>`);const n=document.getElementById("clipboard-textarea");n.select(),n.setSelectionRange(0,99999),document.execCommand("copy"),n.remove(),this.$emit("copied",this.$refs.code.innerText)}},mounted(){this.checkSlots()},beforeUpdate(){this.reactive&&this.checkSlots()}},b={};var w=v(x,g,h,!1,T,null,null,null);function T(t){for(let n in b)this[n]=b[n]}var $=function(){return w.exports}();return $}); | ||
(function(c,m){typeof exports=="object"&&typeof module<"u"?module.exports=m(require("vue")):typeof define=="function"&&define.amd?define(["vue"],m):(c=typeof globalThis<"u"?globalThis:c||self,c.sshpre=m(c.Vue))})(this,function(c){"use strict";const m="",y=(t,e)=>{const n=t.__vccOpts||t;for(const[o,a]of e)n[o]=a;return n},i={quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,comment:/(\/\/.*?(?:\n|$)|\/\*.*?(?:\*\/|$))/,doctype:/(<\!DOCTYPE.*?>)/,htmlTag:/<(?:([a-zA-Z][\w\d-]*)((?:[\w\d\- ]+=(?:"[^"]*"|'[^']*'))*|(?:(?!&(?:lt|amp);).)*?)(\s*\/?)|(\/?)([a-zA-Z][\w\d-]*))>/,htmlentity:/(&(?:[a-zA-Z]+|#x?\d+);)/,punctuation:new RegExp("(!==?|(?:[[\\](){}.:,+\\-?=!])+|(?<!&(?:[a-zA-Z]+|#x?\\d+));|\\|\\||<|>|&)"),number:/(-?(?:\.\d+|\d+(?:\.\d+)?))/,boolean:/\b(true|false)\b/},h={shell:{quote:i.quote,comment:/(#.*?)(?:\n|$)/,keyword:/\b(p?npm|yarn|i(?:nstall)?|run|audit|outdated|update|publish|whoami|cd|sudo|chmod|chown|ls|cat|vim?|scp|rm|mv|mkdir|ln|open|cwd|which|clear|curl|ping|systemctl|echo|export|open|bash|exit)\b/,param:/( --(?:save|save-dev))(?:\s|$)/},xml:{doctype:i.doctype,quote:i.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:i.htmlentity,tag:i.htmlTag},html:{doctype:i.doctype,quote:i.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:i.htmlentity,tag:i.htmlTag},"html-vue":{doctype:i.doctype,quote:i.quote,comment:/(<!--.*?(?:-->|$))/,htmlentity:i.htmlentity,tag:i.htmlTag},pug:{text:/((?:^|\n)[ \t]*|^)\|([ \t]*)([^\n]+(?=\s*(?:\n|$)))/,text2:/([ \t]*)([.#\-\w\d]+(?:\([^)]*\))*)\.\n((?:\n+(?=\4[ \t]+)|(?=\4[ \t]+).+?(?:\n|$)*?)*)(?=\s*(?:\n|$))/,quote:i.quote,comment:/(^|\n)([ \t]*|^)(\/\/-[ \t]*(?:[^\n]*?(?:\n\10[ \t]+[^\n]*)+|[^\n]+(?=\n|$)))/,tag:/([a-zA-Z][\w\d-]*|)([.#][a-zA-Z][-.\w\d]*|)\b(?:\(((?:[\w\d\- ]+=(?:"[^"]*"|'[^']*'))*|(?:(?!&(?:lt|amp);).)*?)\))?(\.?)([ \t]*)([^\n]+)?(?=\n|$)/,"inline-tag":/#\[([^\[\]]+)\]/},css:{comment:/(\/\*.+?(?:\*\/|$))/,quote:/("(?:\\"|[^"])*")|('(?:\\'|[^'])*')/,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:i.number,color:/(transparent|#(?:[\da-fA-F]{6}|[\da-fA-F]{3})|rgba?\([\d., ]*\))/,htmlentity:i.htmlentity,punctuation:/([:,;{}@#()!]+)/,attribute:/([a-zA-Z-]+)(?=\s*:)/,unit:/(px|pt|cm|%|r?em|m?s|deg|vh|vw|vmin|vmax)(?=(?:\s*[;,{}})]|\s+[-\da-z#]))/,error:/([:,;{}@#()!]+|<|>|&)/},json:{quote:/("(?:\\"|[^"])*")/,number:i.number,boolean:i.boolean,punctuation:/([[\](){}:,]+)/,error:/(&(:?lt|gt|amp);|(?!\s).)/},js:{quote:i.quote,comment:i.comment,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:i.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(?:Element)?|window|console|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|Proxy|WeakMap|WeakSet|Symbol|SyncManager|File(?:Reader)?|DataTransfer|DocumentFragment|async|await|(?:clear|set)(?:Timeout|Interval)|parse(?:Int|Float)|Math(?=\.)|isNaN|atob|btoa|getComputedStyle)(?=\W)/,htmlentity:i.htmlentity,punctuation:/(!==?|[[\]!(){}:;,+\-%*/?=]+|\.+(?![a-zA-Z])|\|\||<|>|&)/,variable:/(\.?[a-zA-Z_][\w\d]*)/,"external-var":/(\$|jQuery|JSON)(?=\W|$)/},php:{quote:i.quote,comment:i.comment,special:/(<\?(?:php)?|\?>|__(?:DIR|FILE|LINE|CLASS|METHOD|FUNCTION|NAMESPACE|TRAIT)__)/,punctuation:i.punctuation,number:i.number,boolean:i.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:i.quote,comment:/((?:\-\-|#)\s.*?(?:\n|$)|\/\*.*?\*\/)/,punctuation:i.punctuation,number:/\b(\d+(?:\.\d+)?|null)\b/,boolean:i.boolean,keyword:/\b(\*|DECLARE|BEGIN|END|RETURNS|FUNCTION|CREATE|DATABASE|TABLE|VIEW|COLUMN|INDEX|GRANT|REVOKE|ALL|PRIVILEGES|IDENTIFIED|FLUSH|ALTER|MODIFY|DROP|TRUNCATE|CONSTRAINT|ADD|CHECK|(?:(?:PRIMARY|FOREIGN|UNIQUE) )?KEY|REFERENCES|AUTO_INCREMENT|COMMENT|DEFAULT|UNSIGNED|CHARSET|COLLATE|CHARACTER|ENGINE|SQL_MODE|USE|IF|THEN|NULL|EXISTS|UNIQUE|SELECT|UPDATE|DELETE|(?:INSERT|REPLACE)(?: INTO)?|VALUES|SET|FROM|WHERE|(?:ORDER|GROUP) BY|LIMIT|(?:(?:LEFT|RIGHT|INNER|OUTER|CROSS) |)JOIN|AS|ON|COUNT|AVG|SUM|MIN|MAX|CASE|TO|WHEN|BETWEEN|AND|OR|NOT|IN|LIKE|IS|CONCAT|SUBSTRING|CURRENT_(?:DATE|TIMESTAMP)|USING|HAVING?)(?=\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/}},b={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},E={shell:{quote:2},xml:{quote:2,tag:5},html:{quote:2,tag:5},"html-vue":{quote:2,tag:5},pug:{text:3,text2:3,quote:2,comment:3,tag:6},json:{},php:{quote:2},sql:{quote:2},css:{quote:2},js:{quote:2}},f=t=>t.map(e=>{if(!e.children||typeof e.children=="string")return e.children||"";if(Array.isArray(e.children))return f(e.children);if(e.children.default)return f(e.children.default())}).join(""),x={name:"sshpre",props:{language:{type:String,default:""},label:{type:[String,Boolean],default:!1},tab:{type:[Boolean,String],default:" "},dark:{type:Boolean,default:!1},copyButton:{type:Boolean,default:!1},editable:{type:Boolean,default:!0}},data:()=>({knownLanguages:Object.keys(h),content:"",slotTexts:""}),methods:{htmlize(t){return t.replace(/&(lt|gt|amp);/g,(e,n)=>({lt:"<",gt:">",amp:"&"})[n])},unhtmlize(t){return t.replace(/[<>]/g,e=>({"<":"<",">":">"})[e])},isColorDark(t){let e,n,o,a,s,r;if(e=t.match(/rgba?\((.*),\s*(.*),\s*(.*?)(?:,\s*([^)]*))\)/))o=parseInt(e[1])<=100,a=parseInt(e[2])<=100,s=parseInt(e[3])<=100,r=parseFloat(e[4])<.3;else if(n=t.match(/#([\da-f]{3}(?:[\da-f]{3})?)/)){const l=n[1].length===3;o=parseInt(n[1][0])<=9,a=parseInt(n[1][l?1:2])<=9,s=parseInt(n[1][l?2:4])<=9}return(o&&a&&s||o&&a&&!s||!o&&a&&s)&&!r},createRegexPattern(){let t="";const e=[];for(const n in h[this.language]){const o=E[this.language][n]||1;for(let a=0;a<o;a++)e.push(n);t+=(t?"|":"")+h[this.language][n].source}return[t,e]},syntaxHighlightHtmlTag(t){const e=(n,o,a,s,r)=>`${o}<span class="attribute">${a}</span>`+(s||r?'<span class="punctuation">=</span>':"")+(s||r?`<span class="quote">${s||""}${r||""}${s||""}</span>`:"");if(this.language==="pug"){let[n,o="",a="",s="",r="",l=""]=t;return o=o.replace(/#[a-z\d-]+/g,g=>`<span class="id">${g}</span>`).replace(/\.[a-z\d-]+/g,g=>`<span class="class">${g}</span>`),a&&(a=a.replace(b.pug,e),a='<span class="punctuation">(</span>'+a+'<span class="punctuation">)</span>'),l&&(l=this.highlightPugInlineTag(l)),`<span class="tag-name">${n}</span>${o}${a}`+(s?'<span class="punctuation">.</span>':"")+(r||"")+(l?`<span class="text">${l}</span>`:"")}else{const[n,o="",a="",s="",r]=t,l=o.replace(b[this.language],e);return`<span class="punctuation"><${s}</span><span class="tag-name">${n||r}</span>`+l+`<span class="punctuation">${a}></span>`}},highlightPugInlineTag(t){return t.replace(new RegExp(h.pug["inline-tag"],"gs"),(e,n)=>'<span class="inline-tag">#[</span>'+n.replace(new RegExp(h.pug.tag,"s"),(o,...a)=>(a=a.slice(0,a.length-2),this.syntaxHighlightHtmlTag(a)))+'<span class="inline-tag">]</span>')},highlightInPre(){if(this.knownLanguages.includes(this.language)){const t=this.getCaretPositionInPlainText();this.$refs.code.innerHTML=this.syntaxHighlightContent(this.$refs.code.innerText),this.reinjectCaret(this.$refs.code.childNodes,t)}},getCaretPositionInPlainText(){const t=window.getSelection();t.collapseToEnd();const e=new Range;return e.setStart(this.$refs.code,0),e.setEnd(t.extentNode,t.extentOffset),e.toString().length},reinjectCaret(t,e){var o,a;let n=0;for(const s of t){const r=((o=s.innerText)==null?void 0:o.length)||s.length;if(n+r>=e){s.childNodes.length>1?this.reinjectCaret(s.childNodes,e-n):document.getSelection().setPosition(((a=s.childNodes)==null?void 0:a[0])||s,e-n);break}n+=r}},onKeydown(t){switch(t.which){case 9:this.injectAtCaret(this.tab),t.preventDefault();break;case 13:this.injectAtCaret(` | ||
`),t.preventDefault();break}},injectAtCaret(t){const e=window.getSelection(),n=e.getRangeAt(0),o=document.createTextNode(t);n.insertNode(o),e.collapseToEnd()},syntaxHighlightContent(t){if(!this.knownLanguages.includes(this.language))return t;const[e,n]=this.createRegexPattern();return this.unhtmlize(t.replace(/&/g,"&")).replace(new RegExp(e,"gs"),(o,...a)=>{a=a.slice(0,a.length-2);let s;const r=this.language==="pug";let l=a.find((d,u)=>d&&(s=n[u])&&d);if(["punctuation","quote","htmlentity"].includes(s))l=this.unhtmlize(l);else if(s==="comment")if(r){const[d,u,p]=a.slice(n.indexOf("comment"));l=`${d}${u}${this.unhtmlize(p)}`}else l=this.unhtmlize(l);else if(s==="text"&&r){let[d,u,p]=a;return p=this.highlightPugInlineTag(p),`${d}<span class="punctuation">|</span>${u}<span class="text">${p}</span>`}else if(s==="text2"&&r){const[,,,d,u,p]=a,A=this.syntaxHighlightContent(u);return`${d}${A}<span class="punctuation">.</span> | ||
<span class="text">${p}</span>`}else{if(s==="tag"&&["xml","html","html-vue","pug"].includes(this.language))return this.syntaxHighlightHtmlTag(a.slice(n.indexOf("tag")));if(s==="variable"&&l[0]==="."&&this.language==="js")return`<span class="punctuation">.</span><span class="obj-attr">${l.substr(1)}</span>`}let g="";return s==="color"&&this.language==="css"&&(g=` style="background-color: ${l};color: #${this.isColorDark(l)?"fff":"000"}"`),s&&`<span class="${s}"${g}>${l}</span>`||""})},getSlotContent(){return this.$slots.default&&f(this.$slots.default())||""},copyCode(t){t.target.insertAdjacentHTML("afterend",`<textarea id="clipboard-textarea">${this.$refs.code.innerText}</textarea>`);const e=document.getElementById("clipboard-textarea");e.select(),e.setSelectionRange(0,99999),document.execCommand("copy"),e.remove(),this.$emit("copied",this.$refs.code.innerText)}},mounted(){const t=this.getSlotContent();this.$refs.code.innerText=t,this.$refs.code.innerHTML=this.syntaxHighlightContent(this.$refs.code.innerText)},beforeUpdate(){this.$refs.code.innerHTML=this.syntaxHighlightContent(this.getSlotContent())}},T=["data-type","data-label"],w=["contenteditable"],N={class:"ssh-pre__original"};function C(t,e,n,o,a,s){return c.openBlock(),c.createElementBlock("div",{class:c.normalizeClass(["ssh-pre",{"ssh-pre--dark":n.dark}]),"data-type":n.language,"data-label":n.label||null},[n.copyButton?(c.openBlock(),c.createElementBlock("button",{key:0,class:"ssh-pre__copy",onClick:e[0]||(e[0]=(...r)=>s.copyCode&&s.copyCode(...r))},[c.renderSlot(t.$slots,"copy-button",{},()=>[c.createTextVNode("Copy")])])):c.createCommentVNode("",!0),c.createTextVNode(),c.createElementVNode("pre",{ref:"code",class:"ssh-pre__content",contenteditable:n.editable?"true":"false",onKeydown:e[1]||(e[1]=r=>n.editable&&s.onKeydown(r)),onInput:e[2]||(e[2]=(...r)=>s.highlightInPre&&s.highlightInPre(...r))}," ",40,w),c.createTextVNode(),c.createElementVNode("div",N,[c.renderSlot(t.$slots,"default")])],10,T)}return y(x,[["render",C]])}); |
{ | ||
"name": "simple-syntax-highlighter", | ||
"version": "1.5.1", | ||
"description": "A Vue.js syntax highlighter that reads the source code you give it and highlights it, for Humans.", | ||
"version": "1.6.0", | ||
"description": "No chi-chi syntax highlighter for Vue.js.", | ||
"author": "Antoni Andre <antoniandre.web@gmail.com>", | ||
"homepage": "https://antoniandre.github.io/simple-syntax-highlighter", | ||
"repository": "https://github.com/antoniandre/simple-syntax-highlighter", | ||
"main": "dist/sshpre.common.js", | ||
"unpkg": "dist/sshpre.umd.min.js", | ||
"license": "MIT", | ||
"funding": "https://github.com/sponsors/antoniandre", | ||
"main": "dist/sshpre.cjs.js", | ||
"unpkg": "dist/sshpre.umd.js", | ||
"jsdelivr": "dist/sshpre.umd.js", | ||
"module": "./dist/sshpre.es.js", | ||
@@ -14,8 +18,8 @@ "files": [ | ||
"exports": { | ||
"./dist/sshpre.css": "./dist/sshpre.css", | ||
"./dist/sshpre.cjs.js": "./dist/sshpre.cjs.js", | ||
".": { | ||
"import": "./dist/sshpre.es.js", | ||
"require": "./dist/sshpre.umd.js" | ||
} | ||
}, | ||
"./package.json": "./package.json", | ||
"./dist/*": "./dist/*" | ||
}, | ||
@@ -31,3 +35,2 @@ "keywords": [ | ||
], | ||
"license": "MIT", | ||
"scripts": { | ||
@@ -40,26 +43,23 @@ "dev": "vite", | ||
"devDependencies": { | ||
"@babel/eslint-parser": "^7.17.0", | ||
"@vitejs/plugin-vue": "^1.10.2", | ||
"@babel/eslint-parser": "^7.19.1", | ||
"@vitejs/plugin-vue": "^3.2.0", | ||
"@vue/compiler-sfc": "^3.2.47", | ||
"@vue/eslint-config-standard": "^6.1.0", | ||
"autoprefixer": "^10.4.2", | ||
"core-js": "^3.21.1", | ||
"autoprefixer": "^10.4.13", | ||
"eslint": "^7.32.0", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.2.0", | ||
"eslint-plugin-vue": "^7.20.0", | ||
"postcss": "^8.4.21", | ||
"pug": "^3.0.2", | ||
"rollup-plugin-delete": "^2.0.0", | ||
"sass": "^1.49.8", | ||
"vite": "^2.8.4", | ||
"vite-plugin-pug": "^0.3.0", | ||
"vite-plugin-vue2": "^1.9.3", | ||
"vue": "^2.6.14", | ||
"vue-template-compiler": "^2.6.14", | ||
"wave-ui": "^1.49.3" | ||
"sass": "^1.58.0", | ||
"vite": "^3.2.5", | ||
"vue": "^3.2.47", | ||
"wave-ui": "^3.0.0" | ||
}, | ||
"pnpm": { | ||
"overrides": { | ||
"postcss@<8.2.13": ">=8.2.13" | ||
} | ||
"peerDependencies": { | ||
"vue": "^2.6.14 || ^3.2.0" | ||
} | ||
} |
@@ -7,4 +7,3 @@ # Simple Syntax Highlighter | ||
<!-- [![npm](https://img.shields.io/npm/dw/simple-syntax-highlighter.svg)](https://www.npmjs.com/package/simple-syntax-highlighter) --> | ||
> A very lightweight and easy to use syntax highlighter (not an editor) for Vue.js and Vue 3. Multiple coding languages supported. | ||
> What I use in all my libs documentations. ;) | ||
> No chi-chi syntax highlighter for Vue.js. | ||
@@ -19,6 +18,6 @@ ___ | ||
**Vue 3** | ||
**Vue 2 (legacy)** | ||
``` | ||
npm i simple-syntax-highlighter@next | ||
npm i simple-syntax-highlighter@legacy | ||
``` | ||
@@ -46,2 +45,5 @@ ___ | ||
If you are using this library for profit business, please consider [backing me](https://github.com/sponsors/antoniandre)! | ||
It ensures that the project your products rely on keep being actively maintained. :) | ||
___ | ||
@@ -57,2 +59,5 @@ | ||
- __Version 3.0.0__ Support code editing. Improved syntax highlighting. Always reactive. | ||
- __Version 2.0.0__ Vue 3 build | ||
- __Version 1.6.0__ Support code editing. Improved syntax highlighting. Always reactive. | ||
- __Version 1.5.0__ Removed support for IE - it's finally over. :tada: | ||
@@ -59,0 +64,0 @@ - __Version 1.4.0__ Added Pug language support |
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
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
54764
17
458
65
1
2