diff --git a/.github/workflows/build.sh b/.github/workflows/build.sh index a90d28d..36f4fec 100644 --- a/.github/workflows/build.sh +++ b/.github/workflows/build.sh @@ -42,7 +42,9 @@ for pid in $(jobs -p); do wait $pid || (wait && echo -e "\n\033[91mError: could not minify some files\033[0m" && exit 1) done -cp src/*.d.ts dist -cp src/*.d.ts dist/node +npx -p typescript tsc --outDir dist +npx -p typescript tsc --outDir dist/node + +echo '{"type": "commonjs"}' > dist/node/package.json exit 0 \ No newline at end of file diff --git a/.github/workflows/jsdoc.yml b/.github/workflows/jsdoc.yml index bac685d..c1cce76 100644 --- a/.github/workflows/jsdoc.yml +++ b/.github/workflows/jsdoc.yml @@ -20,14 +20,12 @@ jobs: - name: Set up workspace uses: actions/checkout@v3 - - name: Build documention - uses: andstor/jsdoc-action@v1.2.1 + - uses: actions/setup-node@v4 with: - source_dir: ./src - output_dir: ./doc - config_file: jsdoc.json - template: '@alexispuga/jsdoc-template' - front_page: README.md + node-version: 20 + + - name: Build documention + run: npx -y typedoc src/index.js src/detect.js src/terminal.js - name: Auto commit run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c2ad1b7..5b91e6d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,6 @@ name: Release -"on": +on: push: branches: - main diff --git a/README.md b/README.md index ddacd2f..6acccf0 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ npm i @speed-highlight/core ``` ```js -const { setTheme, printHighlight } = require('@speed-highlight/core/terminal.js'); +const { setTheme, printHighlight } = require('@speed-highlight/core/terminal'); setTheme('[theme-name]') printHighlight('console.log("hello")', 'js') diff --git a/dist/detect.d.ts b/dist/detect.d.ts index d36ba18..5e0eb92 100644 --- a/dist/detect.d.ts +++ b/dist/detect.d.ts @@ -1,8 +1,3 @@ -/** - * Try to find the language the given code belong to - * @param code The code - * @returns The language of the code - */ -export declare function detectLanguage( - code: string -): Promise \ No newline at end of file +export function detectLanguage(code: string): ShjLanguage; +export type ShjLanguage = import('./index.js').ShjLanguage; +//# sourceMappingURL=detect.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index 1adba8b..27cb5ad 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,114 +1,61 @@ -/////////// typedef.js /////////// - /** - * Supported languages. - */ -export type ShjLanguage = 'asm'|'bash'|'bf'|'c'|'css'|'csv'|'diff'|'docker'|'git'|'go'|'html'|'http'|'ini'|'java'|'js'|'jsdoc'|'json'|'leanpub-md'|'log'|'lua'|'make'|'md'|'pl'|'plain'|'py'|'regex'|'rs'|'sql'|'todo'|'toml'|'ts'|'uri'|'xml'|'yaml'; - -/** - * Themes supported in the browser. - */ -export type ShjBrowserTheme = 'atom-dark'|'github-dark'|'github-dim'|'dark'|'default'|'github-light'|'visual-studio-dark'; - -/** - * Languages supported in the terminal. - */ -export type ShjTerminalTheme = 'default'|'atom-dark'; - -/** - * * `inline` inside `code` element - * * `oneline` inside `div` element and containing only one line - * * `multiline` inside `div` element - */ -export type ShjDisplayMode = 'inline'|'oneline'|'multiline'; - -export type ShjToken = 'deleted'|'err'|'var'|'section'|'kwd'|'class'|'cmnt'|'insert'|'type'|'func'|'bool'|'num'|'oper'|'str'|'esc'; - -export interface ShjOptions { - /** - * Indicates whether to hide line numbers. - * @default false - */ - hideLineNumbers: boolean; -} - -/////////// Custom Types /////////// - -export type ShjLanguageComponent = - | { type: string; match: RegExp } - | { expand: string } - | { - match: RegExp; - sub: - | string - | ((code: string) => { - type: string; - sub: Array<{ match: RegExp; sub: string | Promise }> - }); - }; - -export type ShjLanguageDefinition = Array; - -/////////// index.js /////////// - -/** - * Find the tokens in the given code and call the callback - * @param src The code - * @param lang The language of the code - * @param callback The callback function + * Find the tokens in the given code and call the given callback + * + * @function tokenize + * @param {String} src The code + * @param {ShjLanguage|Array} lang The language of the code + * @param {function(String, ShjToken=):void} token The callback function * this function will be given * * the text of the token * * the type of the token */ -export declare function tokenize( - src: string, - lang: T, - callback: (value: string, token: ShjToken) => void -): Promise; - +export function tokenize(src: string, lang: ShjLanguage | any[], token: (arg0: string, arg1: ShjToken | undefined) => void): Promise; /** * Highlight a string passed as argument and return it * @example * elm.innerHTML = await highlightText(code, 'js'); - * @param src The code - * @param lang The language of the code - * @param multiline If it is multiline, it will add a wrapper for the line numbering and header - * @param Customization options - * @returns The highlighted string + * + * @async + * @function highlightText + * @param {String} src The code + * @param {ShjLanguage} lang The language of the code + * @param {Boolean} [multiline=true] If it is multiline, it will add a wrapper for the line numbering and header + * @param {ShjOptions} [opt={}] Customization options + * @returns {Promise} The highlighted string */ -export declare function highlightText( - src: string, - lang: T, - multiline?: boolean, - opt?: ShjOptions -): Promise; - +export function highlightText(src: string, lang: ShjLanguage, multiline?: boolean, opt?: ShjOptions): Promise; /** * Highlight a DOM element by getting the new innerHTML with highlightText - * @param elm The DOM element - * @param lang The language of the code (seaching by default on `elm` for a 'shj-lang-' class) - * @param mode The display mode (guessed by default) - * @param opt Customization options + * + * @async + * @function highlightElement + * @param {Element} elm The DOM element + * @param {ShjLanguage} [lang] The language of the code (seaching by default on `elm` for a 'shj-lang-' class) + * @param {ShjDisplayMode} [mode] The display mode (guessed by default) + * @param {ShjOptions} [opt={}] Customization options + */ +export function highlightElement(elm: Element, lang?: ShjLanguage, mode?: ShjDisplayMode, opt?: ShjOptions): Promise; +export function highlightAll(opt?: ShjOptions): Promise; +export function loadLanguage(languageName: string, language: ShjLanguage): void; +export type ShjToken = ('deleted' | 'err' | 'var' | 'section' | 'kwd' | 'class' | 'cmnt' | 'insert' | 'type' | 'func' | 'bool' | 'num' | 'oper' | 'str' | 'esc'); +export type ShjOptions = { + /** + * Indicates whether to hide line numbers + */ + hideLineNumbers?: boolean; +}; +/** + * * `inline` inside `code` element + * * `oneline` inside `div` element and containing only one line + * * `multiline` inside `div` element */ -export declare function highlightElement( - elm: Element, - lang?: T, - mode?: ShjDisplayMode, - opt?: ShjOptions -): Promise; - +export type ShjDisplayMode = ('inline' | 'oneline' | 'multiline'); /** - * Call highlightElement on element with a css class starting with `shj-lang-` - * @param opt Customization options + * Themes supported in the browser */ -export declare function highlightAll(opt?: ShjOptions): Promise; - +export type ShjBrowserTheme = ('atom-dark' | 'github-dark' | 'github-dim' | 'dark' | 'default' | 'github-light' | 'visual-studio-dark'); /** - * Load a language and add it to the langs object - * @param name The name of the language - * @param module Module that has the language as the default export + * Languages supported */ -export declare function loadLanguage( - name: string, - module: { default: ShjLanguageDefinition } -): void; +export type ShjLanguage = ('asm' | 'bash' | 'bf' | 'c' | 'css' | 'csv' | 'diff' | 'docker' | 'git' | 'go' | 'html' | 'http' | 'ini' | 'java' | 'js' | 'jsdoc' | 'json' | 'leanpub-md' | 'log' | 'lua' | 'make' | 'md' | 'pl' | 'plain' | 'py' | 'regex' | 'rs' | 'sql' | 'todo' | 'toml' | 'ts' | 'uri' | 'xml' | 'yaml'); +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/languages/md.js b/dist/languages/md.js index c746661..88dfb7a 100644 --- a/dist/languages/md.js +++ b/dist/languages/md.js @@ -1,2 +1,2 @@ -var c=[["bash",[/#!(\/usr)?\/bin\/bash/g,500],[/\b(if|elif|then|fi|echo)\b|\$/g,10]],["html",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^\s+<-]/gm,10],[/^@@ ?[-+,0-9 ]+ ?@@/gm,25]],["md",[/^(>|\t\*|\t\d+.)/gm,10],[/\[.*\](.*)/g,10]],["docker",[/^(FROM|ENTRYPOINT|RUN)/gm,500]],["xml",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^<\?xml/g,500]],["c",[/#include\b|\bprintf\s+\(/g,100]],["rs",[/^\s+(use|fn|mut|match)\b/gm,100]],["go",[/\b(func|fmt|package)\b/g,100]],["java",[/^import\s+java/gm,500]],["asm",[/^(section|global main|extern|\t(call|mov|ret))/gm,100]],["css",[/^(@import|@page|@media|(\.|#)[a-z]+)/gm,20]],["json",[/\b(true|false|null|\{})\b|\"[^"]+\":/g,10]],["yaml",[/^(\s+)?[a-z][a-z0-9]*:/gmi,10]]],s=a=>{var m;return((m=c.map(([e,...t])=>[e,t.reduce((g,[n,i])=>g+[...a.matchAll(n)].length*i,0)]).filter(([e,t])=>t>20).sort((e,t)=>t[1]-e[1])[0])==null?void 0:m[0])||"plain"};var p=[{type:"cmnt",match:/^>.*|(=|-)\1+/gm},{type:"class",match:/\*\*((?!\*\*).)*\*\*/g},{match:/```((?!```)[^])*\n```/g,sub:a=>({type:"kwd",sub:[{match:/\n[^]*(?=```)/g,sub:a.split(` -`)[0].slice(3)||s(a)}]})},{type:"str",match:/`[^`]*`/g},{type:"var",match:/~~((?!~~).)*~~/g},{type:"kwd",match:/_[^_]*_|\*[^*]*\*/g},{type:"kwd",match:/^\s*(\*|\d+\.)\s/gm},{type:"oper",match:/\[[^\]]*]/g},{type:"func",match:/\([^)]*\)/g}];export{p as default}; +var c=[["bash",[/#!(\/usr)?\/bin\/bash/g,500],[/\b(if|elif|then|fi|echo)\b|\$/g,10]],["html",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^\s+<-]/gm,10],[/^@@ ?[-+,0-9 ]+ ?@@/gm,25]],["md",[/^(>|\t\*|\t\d+.)/gm,10],[/\[.*\](.*)/g,10]],["docker",[/^(FROM|ENTRYPOINT|RUN)/gm,500]],["xml",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^<\?xml/g,500]],["c",[/#include\b|\bprintf\s+\(/g,100]],["rs",[/^\s+(use|fn|mut|match)\b/gm,100]],["go",[/\b(func|fmt|package)\b/g,100]],["java",[/^import\s+java/gm,500]],["asm",[/^(section|global main|extern|\t(call|mov|ret))/gm,100]],["css",[/^(@import|@page|@media|(\.|#)[a-z]+)/gm,20]],["json",[/\b(true|false|null|\{})\b|\"[^"]+\":/g,10]],["yaml",[/^(\s+)?[a-z][a-z0-9]*:/gmi,10]]],m=a=>{var s;return((s=c.map(([e,...t])=>[e,t.reduce((g,[n,i])=>g+[...a.matchAll(n)].length*i,0)]).filter(([e,t])=>t>20).sort((e,t)=>t[1]-e[1])[0])==null?void 0:s[0])||"plain"};var p=[{type:"cmnt",match:/^>.*|(=|-)\1+/gm},{type:"class",match:/\*\*((?!\*\*).)*\*\*/g},{match:/```((?!```)[^])*\n```/g,sub:a=>({type:"kwd",sub:[{match:/\n[^]*(?=```)/g,sub:a.split(` +`)[0].slice(3)||m(a)}]})},{type:"str",match:/`[^`]*`/g},{type:"var",match:/~~((?!~~).)*~~/g},{type:"kwd",match:/_[^_]*_|\*[^*]*\*/g},{type:"kwd",match:/^\s*(\*|\d+\.)\s/gm},{type:"oper",match:/\[[^\]]*]/g},{type:"func",match:/\([^)]*\)/g}];export{p as default}; diff --git a/dist/node/detect.d.ts b/dist/node/detect.d.ts index d36ba18..5e0eb92 100644 --- a/dist/node/detect.d.ts +++ b/dist/node/detect.d.ts @@ -1,8 +1,3 @@ -/** - * Try to find the language the given code belong to - * @param code The code - * @returns The language of the code - */ -export declare function detectLanguage( - code: string -): Promise \ No newline at end of file +export function detectLanguage(code: string): ShjLanguage; +export type ShjLanguage = import('./index.js').ShjLanguage; +//# sourceMappingURL=detect.d.ts.map \ No newline at end of file diff --git a/dist/node/index.d.ts b/dist/node/index.d.ts index 1adba8b..27cb5ad 100644 --- a/dist/node/index.d.ts +++ b/dist/node/index.d.ts @@ -1,114 +1,61 @@ -/////////// typedef.js /////////// - /** - * Supported languages. - */ -export type ShjLanguage = 'asm'|'bash'|'bf'|'c'|'css'|'csv'|'diff'|'docker'|'git'|'go'|'html'|'http'|'ini'|'java'|'js'|'jsdoc'|'json'|'leanpub-md'|'log'|'lua'|'make'|'md'|'pl'|'plain'|'py'|'regex'|'rs'|'sql'|'todo'|'toml'|'ts'|'uri'|'xml'|'yaml'; - -/** - * Themes supported in the browser. - */ -export type ShjBrowserTheme = 'atom-dark'|'github-dark'|'github-dim'|'dark'|'default'|'github-light'|'visual-studio-dark'; - -/** - * Languages supported in the terminal. - */ -export type ShjTerminalTheme = 'default'|'atom-dark'; - -/** - * * `inline` inside `code` element - * * `oneline` inside `div` element and containing only one line - * * `multiline` inside `div` element - */ -export type ShjDisplayMode = 'inline'|'oneline'|'multiline'; - -export type ShjToken = 'deleted'|'err'|'var'|'section'|'kwd'|'class'|'cmnt'|'insert'|'type'|'func'|'bool'|'num'|'oper'|'str'|'esc'; - -export interface ShjOptions { - /** - * Indicates whether to hide line numbers. - * @default false - */ - hideLineNumbers: boolean; -} - -/////////// Custom Types /////////// - -export type ShjLanguageComponent = - | { type: string; match: RegExp } - | { expand: string } - | { - match: RegExp; - sub: - | string - | ((code: string) => { - type: string; - sub: Array<{ match: RegExp; sub: string | Promise }> - }); - }; - -export type ShjLanguageDefinition = Array; - -/////////// index.js /////////// - -/** - * Find the tokens in the given code and call the callback - * @param src The code - * @param lang The language of the code - * @param callback The callback function + * Find the tokens in the given code and call the given callback + * + * @function tokenize + * @param {String} src The code + * @param {ShjLanguage|Array} lang The language of the code + * @param {function(String, ShjToken=):void} token The callback function * this function will be given * * the text of the token * * the type of the token */ -export declare function tokenize( - src: string, - lang: T, - callback: (value: string, token: ShjToken) => void -): Promise; - +export function tokenize(src: string, lang: ShjLanguage | any[], token: (arg0: string, arg1: ShjToken | undefined) => void): Promise; /** * Highlight a string passed as argument and return it * @example * elm.innerHTML = await highlightText(code, 'js'); - * @param src The code - * @param lang The language of the code - * @param multiline If it is multiline, it will add a wrapper for the line numbering and header - * @param Customization options - * @returns The highlighted string + * + * @async + * @function highlightText + * @param {String} src The code + * @param {ShjLanguage} lang The language of the code + * @param {Boolean} [multiline=true] If it is multiline, it will add a wrapper for the line numbering and header + * @param {ShjOptions} [opt={}] Customization options + * @returns {Promise} The highlighted string */ -export declare function highlightText( - src: string, - lang: T, - multiline?: boolean, - opt?: ShjOptions -): Promise; - +export function highlightText(src: string, lang: ShjLanguage, multiline?: boolean, opt?: ShjOptions): Promise; /** * Highlight a DOM element by getting the new innerHTML with highlightText - * @param elm The DOM element - * @param lang The language of the code (seaching by default on `elm` for a 'shj-lang-' class) - * @param mode The display mode (guessed by default) - * @param opt Customization options + * + * @async + * @function highlightElement + * @param {Element} elm The DOM element + * @param {ShjLanguage} [lang] The language of the code (seaching by default on `elm` for a 'shj-lang-' class) + * @param {ShjDisplayMode} [mode] The display mode (guessed by default) + * @param {ShjOptions} [opt={}] Customization options + */ +export function highlightElement(elm: Element, lang?: ShjLanguage, mode?: ShjDisplayMode, opt?: ShjOptions): Promise; +export function highlightAll(opt?: ShjOptions): Promise; +export function loadLanguage(languageName: string, language: ShjLanguage): void; +export type ShjToken = ('deleted' | 'err' | 'var' | 'section' | 'kwd' | 'class' | 'cmnt' | 'insert' | 'type' | 'func' | 'bool' | 'num' | 'oper' | 'str' | 'esc'); +export type ShjOptions = { + /** + * Indicates whether to hide line numbers + */ + hideLineNumbers?: boolean; +}; +/** + * * `inline` inside `code` element + * * `oneline` inside `div` element and containing only one line + * * `multiline` inside `div` element */ -export declare function highlightElement( - elm: Element, - lang?: T, - mode?: ShjDisplayMode, - opt?: ShjOptions -): Promise; - +export type ShjDisplayMode = ('inline' | 'oneline' | 'multiline'); /** - * Call highlightElement on element with a css class starting with `shj-lang-` - * @param opt Customization options + * Themes supported in the browser */ -export declare function highlightAll(opt?: ShjOptions): Promise; - +export type ShjBrowserTheme = ('atom-dark' | 'github-dark' | 'github-dim' | 'dark' | 'default' | 'github-light' | 'visual-studio-dark'); /** - * Load a language and add it to the langs object - * @param name The name of the language - * @param module Module that has the language as the default export + * Languages supported */ -export declare function loadLanguage( - name: string, - module: { default: ShjLanguageDefinition } -): void; +export type ShjLanguage = ('asm' | 'bash' | 'bf' | 'c' | 'css' | 'csv' | 'diff' | 'docker' | 'git' | 'go' | 'html' | 'http' | 'ini' | 'java' | 'js' | 'jsdoc' | 'json' | 'leanpub-md' | 'log' | 'lua' | 'make' | 'md' | 'pl' | 'plain' | 'py' | 'regex' | 'rs' | 'sql' | 'todo' | 'toml' | 'ts' | 'uri' | 'xml' | 'yaml'); +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/node/languages/md.js b/dist/node/languages/md.js index 34926c2..0b39436 100644 --- a/dist/node/languages/md.js +++ b/dist/node/languages/md.js @@ -1,2 +1,2 @@ -var g=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var r=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var o=(t,a)=>{for(var e in a)g(t,e,{get:a[e],enumerable:!0})},b=(t,a,e,m)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of r(a))!p.call(t,s)&&s!==e&&g(t,s,{get:()=>a[s],enumerable:!(m=l(a,s))||m.enumerable});return t};var u=t=>b(g({},"__esModule",{value:!0}),t);var d={};o(d,{default:()=>h});module.exports=u(d);var f=[["bash",[/#!(\/usr)?\/bin\/bash/g,500],[/\b(if|elif|then|fi|echo)\b|\$/g,10]],["html",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^\s+<-]/gm,10],[/^@@ ?[-+,0-9 ]+ ?@@/gm,25]],["md",[/^(>|\t\*|\t\d+.)/gm,10],[/\[.*\](.*)/g,10]],["docker",[/^(FROM|ENTRYPOINT|RUN)/gm,500]],["xml",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^<\?xml/g,500]],["c",[/#include\b|\bprintf\s+\(/g,100]],["rs",[/^\s+(use|fn|mut|match)\b/gm,100]],["go",[/\b(func|fmt|package)\b/g,100]],["java",[/^import\s+java/gm,500]],["asm",[/^(section|global main|extern|\t(call|mov|ret))/gm,100]],["css",[/^(@import|@page|@media|(\.|#)[a-z]+)/gm,20]],["json",[/\b(true|false|null|\{})\b|\"[^"]+\":/g,10]],["yaml",[/^(\s+)?[a-z][a-z0-9]*:/gmi,10]]],n=t=>{var a;return((a=f.map(([e,...m])=>[e,m.reduce((s,[i,c])=>s+[...t.matchAll(i)].length*c,0)]).filter(([e,m])=>m>20).sort((e,m)=>m[1]-e[1])[0])==null?void 0:a[0])||"plain"};var h=[{type:"cmnt",match:/^>.*|(=|-)\1+/gm},{type:"class",match:/\*\*((?!\*\*).)*\*\*/g},{match:/```((?!```)[^])*\n```/g,sub:t=>({type:"kwd",sub:[{match:/\n[^]*(?=```)/g,sub:t.split(` +var g=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var r=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var o=(t,a)=>{for(var e in a)g(t,e,{get:a[e],enumerable:!0})},b=(t,a,e,s)=>{if(a&&typeof a=="object"||typeof a=="function")for(let m of r(a))!p.call(t,m)&&m!==e&&g(t,m,{get:()=>a[m],enumerable:!(s=l(a,m))||s.enumerable});return t};var u=t=>b(g({},"__esModule",{value:!0}),t);var d={};o(d,{default:()=>h});module.exports=u(d);var f=[["bash",[/#!(\/usr)?\/bin\/bash/g,500],[/\b(if|elif|then|fi|echo)\b|\$/g,10]],["html",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^\s+<-]/gm,10],[/^@@ ?[-+,0-9 ]+ ?@@/gm,25]],["md",[/^(>|\t\*|\t\d+.)/gm,10],[/\[.*\](.*)/g,10]],["docker",[/^(FROM|ENTRYPOINT|RUN)/gm,500]],["xml",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^<\?xml/g,500]],["c",[/#include\b|\bprintf\s+\(/g,100]],["rs",[/^\s+(use|fn|mut|match)\b/gm,100]],["go",[/\b(func|fmt|package)\b/g,100]],["java",[/^import\s+java/gm,500]],["asm",[/^(section|global main|extern|\t(call|mov|ret))/gm,100]],["css",[/^(@import|@page|@media|(\.|#)[a-z]+)/gm,20]],["json",[/\b(true|false|null|\{})\b|\"[^"]+\":/g,10]],["yaml",[/^(\s+)?[a-z][a-z0-9]*:/gmi,10]]],n=t=>{var a;return((a=f.map(([e,...s])=>[e,s.reduce((m,[i,c])=>m+[...t.matchAll(i)].length*c,0)]).filter(([e,s])=>s>20).sort((e,s)=>s[1]-e[1])[0])==null?void 0:a[0])||"plain"};var h=[{type:"cmnt",match:/^>.*|(=|-)\1+/gm},{type:"class",match:/\*\*((?!\*\*).)*\*\*/g},{match:/```((?!```)[^])*\n```/g,sub:t=>({type:"kwd",sub:[{match:/\n[^]*(?=```)/g,sub:t.split(` `)[0].slice(3)||n(t)}]})},{type:"str",match:/`[^`]*`/g},{type:"var",match:/~~((?!~~).)*~~/g},{type:"kwd",match:/_[^_]*_|\*[^*]*\*/g},{type:"kwd",match:/^\s*(\*|\d+\.)\s/gm},{type:"oper",match:/\[[^\]]*]/g},{type:"func",match:/\([^)]*\)/g}];0&&(module.exports={}); diff --git a/dist/node/terminal.d.ts b/dist/node/terminal.d.ts index fd85f1b..3b601ba 100644 --- a/dist/node/terminal.d.ts +++ b/dist/node/terminal.d.ts @@ -1,26 +1,6 @@ -/** - * Highlight a string passed as argument and return a string that can directly be printed - * @param src The code - * @param ang The language of the code - * @returns The highlighted string - */ -export declare function highlightText( - src: string, - lang: T -): Promise; - -/** - * Highlight and print a given string - * @param src The code - * @param lang The language of the code - */ -export declare function printHighlight( - src: string, - lang: T -): Promise; - -/** - * Change the current used theme for highlighting - * @param name The name of the theme - */ -export declare function setTheme(name: import('.').ShjBrowserTheme): Promise; \ No newline at end of file +export function highlightText(src: string, lang: ShjLanguage): Promise; +export function printHighlight(src: string, lang: ShjLanguage): Promise; +export function setTheme(name: any): Promise; +export type ShjLanguage = import('./index.js').ShjLanguage; +export type ShjTerminalTheme = import('./index.js').ShjTerminalTheme; +//# sourceMappingURL=terminal.d.ts.map \ No newline at end of file diff --git a/dist/node/terminal.js b/dist/node/terminal.js index 1b65bbc..3a946f6 100644 --- a/dist/node/terminal.js +++ b/dist/node/terminal.js @@ -1 +1 @@ -var L=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(t&&(e=t(t=0)),e);var y=(t,e)=>{for(var n in e)m(t,n,{get:e[n],enumerable:!0})},b=(t,e,n,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of z(e))!E.call(t,a)&&a!==n&&m(t,a,{get:()=>e[a],enumerable:!(p=T(e,a))||p.enumerable});return t};var o=(t,e,n)=>(n=t!=null?L(D(t)):{},b(e||!t||!t.__esModule?m(n,"default",{value:t,enumerable:!0}):n,t)),N=t=>b(m({},"__esModule",{value:!0}),t);var r,$=g(()=>{r={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",gray:"\x1B[90m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m"}});var j={};y(j,{default:()=>C});var C,v=g(()=>{$();C={deleted:r.red,var:r.red,err:r.red,kwd:r.red,num:r.yellow,class:r.yellow,cmnt:r.gray,insert:r.green,str:r.green,bool:r.cyan,type:r.blue,oper:r.blue,section:r.magenta,func:r.magenta}});var S={};y(S,{highlightText:()=>I,printHighlight:()=>H,setTheme:()=>M});module.exports=N(S);var w={num:{type:"num",match:/(\.e?|\b)\d(e-|[\d.oxa-fA-F_])*(\.|\b)/g},str:{type:"str",match:/(["'])(\\[^]|(?!\1)[^\r\n\\])*\1?/g},strDouble:{type:"str",match:/"((?!")[^\r\n\\]|\\[^])*"?/g}};var u={};async function f(t,e,n){var p;try{let a,s,i={},d,l=[],c=0,x=typeof e=="string"?await((p=u[e])!=null?p:u[e]=Promise.resolve().then(()=>o(require(`./languages/${e}.js`)))):e,h=[...typeof e=="string"?x.default:e.sub];for(;c0;){if(s=h[a].expand?w[h[a].expand]:h[a],l[a]===void 0||l[a].match.index(v(),j)),I=async(t,e)=>{let n="",p=(await A).default;return await f(t,e,(a,s)=>{var i;return n+=s?`${(i=p[s])!=null?i:""}${a}\x1B[0m`:a}),n},H=async(t,e)=>console.log(await I(t,e)),M=async t=>A=Promise.resolve().then(()=>o(require(`./themes/${t}.js`)));0&&(module.exports={highlightText,printHighlight,setTheme}); +var L=Object.create;var d=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(t&&(e=t(t=0)),e);var y=(t,e)=>{for(var i in e)d(t,i,{get:e[i],enumerable:!0})},b=(t,e,i,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of z(e))!E.call(t,a)&&a!==i&&d(t,a,{get:()=>e[a],enumerable:!(c=T(e,a))||c.enumerable});return t};var m=(t,e,i)=>(i=t!=null?L(D(t)):{},b(e||!t||!t.__esModule?d(i,"default",{value:t,enumerable:!0}):i,t)),N=t=>b(d({},"__esModule",{value:!0}),t);var l,$=g(()=>{l={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",gray:"\x1B[90m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m"}});var j={};y(j,{default:()=>C});var C,v=g(()=>{$();C={deleted:l.red,var:l.red,err:l.red,kwd:l.red,num:l.yellow,class:l.yellow,cmnt:l.gray,insert:l.green,str:l.green,bool:l.cyan,type:l.blue,oper:l.blue,section:l.magenta,func:l.magenta}});var S={};y(S,{highlightText:()=>I,printHighlight:()=>H,setTheme:()=>M});module.exports=N(S);var w={num:{type:"num",match:/(\.e?|\b)\d(e-|[\d.oxa-fA-F_])*(\.|\b)/g},str:{type:"str",match:/(["'])(\\[^]|(?!\1)[^\r\n\\])*\1?/g},strDouble:{type:"str",match:/"((?!")[^\r\n\\]|\\[^])*"?/g}};var u={};async function f(t,e,i){var c;try{let a,s,n={},o,r=[],h=0,x=typeof e=="string"?await((c=u[e])!=null?c:u[e]=Promise.resolve().then(()=>m(require(`./languages/${e}.js`)))):e,p=[...typeof e=="string"?x.default:e.sub];for(;h0;){if(s=p[a].expand?w[p[a].expand]:p[a],r[a]===void 0||r[a].match.index(v(),j)),I=async(t,e)=>{let i="",c=(await A).default;return await f(t,e,(a,s)=>{var n;return i+=s?`${(n=c[s])!=null?n:""}${a}\x1B[0m`:a}),i},H=async(t,e)=>console.log(await I(t,e)),M=async t=>A=Promise.resolve().then(()=>m(require(`./themes/${t}.js`)));0&&(module.exports={highlightText,printHighlight,setTheme}); diff --git a/dist/terminal.d.ts b/dist/terminal.d.ts index fd85f1b..3b601ba 100644 --- a/dist/terminal.d.ts +++ b/dist/terminal.d.ts @@ -1,26 +1,6 @@ -/** - * Highlight a string passed as argument and return a string that can directly be printed - * @param src The code - * @param ang The language of the code - * @returns The highlighted string - */ -export declare function highlightText( - src: string, - lang: T -): Promise; - -/** - * Highlight and print a given string - * @param src The code - * @param lang The language of the code - */ -export declare function printHighlight( - src: string, - lang: T -): Promise; - -/** - * Change the current used theme for highlighting - * @param name The name of the theme - */ -export declare function setTheme(name: import('.').ShjBrowserTheme): Promise; \ No newline at end of file +export function highlightText(src: string, lang: ShjLanguage): Promise; +export function printHighlight(src: string, lang: ShjLanguage): Promise; +export function setTheme(name: any): Promise; +export type ShjLanguage = import('./index.js').ShjLanguage; +export type ShjTerminalTheme = import('./index.js').ShjTerminalTheme; +//# sourceMappingURL=terminal.d.ts.map \ No newline at end of file diff --git a/dist/terminal.js b/dist/terminal.js index 98c63a7..ae34380 100644 --- a/dist/terminal.js +++ b/dist/terminal.js @@ -1 +1 @@ -var $=Object.defineProperty;var u=(e,a)=>()=>(e&&(a=e(e=0)),a);var j=(e,a)=>{for(var r in a)$(e,r,{get:a[r],enumerable:!0})};var n,g=u(()=>{n={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",gray:"\x1B[90m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m"}});var y={};j(y,{default:()=>v});var v,b=u(()=>{g();v={deleted:n.red,var:n.red,err:n.red,kwd:n.red,num:n.yellow,class:n.yellow,cmnt:n.gray,insert:n.green,str:n.green,bool:n.cyan,type:n.blue,oper:n.blue,section:n.magenta,func:n.magenta}});var f={num:{type:"num",match:/(\.e?|\b)\d(e-|[\d.oxa-fA-F_])*(\.|\b)/g},str:{type:"str",match:/(["'])(\\[^]|(?!\1)[^\r\n\\])*\1?/g},strDouble:{type:"str",match:/"((?!")[^\r\n\\]|\\[^])*"?/g}};var d={};async function x(e,a,r){var h;try{let i,s,t={},m,l=[],p=0,o=typeof a=="string"?await((h=d[a])!=null?h:d[a]=import(`./languages/${a}.js`)):a,c=[...typeof a=="string"?o.default:a.sub];for(;p0;){if(s=c[i].expand?f[c[i].expand]:c[i],l[i]===void 0||l[i].match.index(b(),y)),A=async(e,a)=>{let r="",h=(await w).default;return await x(e,a,(i,s)=>{var t;return r+=s?`${(t=h[s])!=null?t:""}${i}\x1B[0m`:i}),r},C=async(e,a)=>console.log(await A(e,a)),H=async e=>w=import(`./themes/${e}.js`);export{A as highlightText,C as printHighlight,H as setTheme}; +var $=Object.defineProperty;var u=(e,a)=>()=>(e&&(a=e(e=0)),a);var j=(e,a)=>{for(var l in a)$(e,l,{get:a[l],enumerable:!0})};var i,g=u(()=>{i={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",gray:"\x1B[90m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m"}});var y={};j(y,{default:()=>v});var v,b=u(()=>{g();v={deleted:i.red,var:i.red,err:i.red,kwd:i.red,num:i.yellow,class:i.yellow,cmnt:i.gray,insert:i.green,str:i.green,bool:i.cyan,type:i.blue,oper:i.blue,section:i.magenta,func:i.magenta}});var f={num:{type:"num",match:/(\.e?|\b)\d(e-|[\d.oxa-fA-F_])*(\.|\b)/g},str:{type:"str",match:/(["'])(\\[^]|(?!\1)[^\r\n\\])*\1?/g},strDouble:{type:"str",match:/"((?!")[^\r\n\\]|\\[^])*"?/g}};var o={};async function x(e,a,l){var p;try{let n,s,t={},d,r=[],c=0,m=typeof a=="string"?await((p=o[a])!=null?p:o[a]=import(`./languages/${a}.js`)):a,h=[...typeof a=="string"?m.default:a.sub];for(;c0;){if(s=h[n].expand?f[h[n].expand]:h[n],r[n]===void 0||r[n].match.index(b(),y)),A=async(e,a)=>{let l="",p=(await w).default;return await x(e,a,(n,s)=>{var t;return l+=s?`${(t=p[s])!=null?t:""}${n}\x1B[0m`:n}),l},C=async(e,a)=>console.log(await A(e,a)),H=async e=>w=import(`./themes/${e}.js`);export{A as highlightText,C as printHighlight,H as setTheme}; diff --git a/doc/common.js.html b/doc/common.js.html deleted file mode 100644 index 06b44f1..0000000 --- a/doc/common.js.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - Source: common.js - JSDoc - - - - -
- -
- -
-
-

Source: common.js

-
- - - - - -
-
/**
- * Commonly used match pattern
-*/
-
-export default {
-	num: {
-		type: 'num',
-		match: /(\.e?|\b)\d(e-|[\d.oxa-fA-F_])*(\.|\b)/g
-	},
-	str: {
-		type: 'str',
-		match: /(["'])(\\[^]|(?!\1)[^\r\n\\])*\1?/g
-	},
-	strDouble: {
-		type: 'str',
-		match: /"((?!")[^\r\n\\]|\\[^])*"?/g
-	}
-}
-
-
- - - - - -
- -
-
- - - - - - - - diff --git a/doc/css/jsdoc-template.css b/doc/css/jsdoc-template.css deleted file mode 100644 index b86592c..0000000 --- a/doc/css/jsdoc-template.css +++ /dev/null @@ -1 +0,0 @@ -*{border:0;margin:0;padding:0}:focus,a:active,a:hover{outline:0}table{border-collapse:collapse;border-spacing:0}[hidden]{display:none}ol,ul{list-style:none}html{font-size:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}button::-moz-focus-inner{border:0}[data-css-icon]{position:relative}[data-css-icon=menu]:after,[data-css-icon]:before{position:absolute;top:50%;left:50%}[data-css-icon=menu]:after,[data-css-icon=menu]:before{border-style:solid;border-width:.2em 0;width:1em;height:.7em;margin-left:-.55em}[data-css-icon=menu]:before{content:"";margin-top:-.55em}[data-css-icon=menu]:after{content:"";border-bottom:0;margin-top:-.1em}.is-active[data-css-icon=menu]:before{content:unset}html{background-color:#06060c}#content-nav li:not(.is-active),#page-header,#page-header a,#page-header h3,.signature-attributes,.type-signature,.variation,body,html{color:#5d6177}a{color:#1676aa}#content-nav,#content-nav>header{background:inherit}dl{border-left:2px solid rgba(0,0,0,.1)}dt.tag-deprecated,dt.tag-deprecated+dd{border-left:2px solid red}#page-footer,.doc>.member,.doc>h3,article,button{border:1px solid rgba(0,0,0,.03)}table table{border-left:2px solid rgba(0,0,0,.05)}#page-footer,.doc>.member,article{border-width:1px 0 0}.doc>h3{border-width:0 0 1px}#content-nav li:before,#page-header li.is-active a,#page-title,#page-title a,.doc h2>a,h4.name>a,input[type=search]{color:inherit}#page-header,button.is-active{background:#181826;color:#d8d8d8}#page-header :focus,#page-header a:hover,#page-header a b{color:#fff}#content-nav li:not(.is-active) abbr,input[type=search]{background-color:hsla(0,0%,100%,.03)}#content-nav li:not(.is-active) abbr:hover,input[type=search]:focus{background:hsla(0,0%,100%,.05)}#page-header li.is-active abbr{background:#fff;color:#000}.code-caption,table{background-color:#f6f6f6}.doc h3,.prettyprint.linenums li.selected,body,button{background-color:#fbfbfb}.class-description,.example:hover .code-caption,.summary,button,code,dt,h1,h2,h3,h4,h5,h6,kbd,small a,thead,tr:focus,tr:hover{color:#1f1e26}#readme :not(pre)>code,.example:hover>*,kbd,samp,tbody tr:focus *,tbody tr:hover *{background:#f3f3f3}body{max-width:1980px;width:100%;margin:auto;overflow-x:hidden}body,html{font:100% DejaVu Sans,helvetica,arial,sans-serif;line-height:1.7;text-align:left}a{text-decoration:none}a:focus,a:hover{text-decoration:underline}nav b{font-weight:inherit}#page-header li.is-active a{font-weight:bolder}input[type=search]{width:100%;font-family:inherit;padding:8px 20px}aside{font-size:1rem}button{cursor:pointer;border-radius:0}img{max-width:100%}button.has-icon{width:60px;height:60px}h2,h3,h4,h5,h6{font-weight:bolder}article:not(.doc) h2,article:not(.doc) h3,article:not(.doc) h4,dt,h1,nav>h2,th{font-weight:400}h1,h2{font-size:200%}#readme h2,#readme h3,h3,h4{font-size:150%}#readme h4,#readme h5,h5,h6{font-size:125%}h6{font-size:100%}.doc h3,.doc h5,.doc h6,nav>h3{text-transform:uppercase}nav>h2{font-size:150%;padding:20px 0}nav>h3{font-size:100%}nav>h3:not(:first-of-type){margin-top:40px}.doc h3,.doc h4,.doc h5,dt,th{font-size:100%}.table-wrapper{width:100%;overflow:auto}table{margin-top:10px;border-collapse:separate;width:100%}td,th{padding:10px 2rem;vertical-align:top;word-break:normal}var{font-weight:bolder}samp{font-style:italic}kbd,var{font-style:normal}#readme :not(pre)>code,kbd,samp{padding:0 10px}table table{margin-top:20px}.doc table h6,code{font-size:100%}.doc h2,code,h4.name,kbd,samp,var{font-family:Menlo,Bitstream Vera Sans Mono,DejaVu Sans Mono,Monaco,Consolas,monospace}#page-wrapper{display:flex;width:100%}#main-wrapper{width:calc(100% - 320px);position:relative}#content{min-height:100vh;width:100%}#content>header{padding:50px}.has-icon{text-indent:100%;white-space:nowrap;overflow:hidden}#page-header{position:sticky;top:0;padding:20px;width:320px;height:100vh;overflow-y:auto;box-sizing:border-box}#page-title{padding:20px 0;text-align:center}#content-nav{padding-bottom:20px}#content-nav>header{position:sticky;top:-20px;padding:15px 0;z-index:1}#content-nav>ul{list-style:none;white-space:nowrap;overflow:hidden;padding-left:0}#content-nav li{position:relative}#page-footer{padding:2.5% 5%;text-align:right}small{font-size:1rem}ol{list-style:decimal-leading-zero}ul{list-style:disc}dl,ol,ul{box-sizing:border-box;margin-top:2rem;margin-bottom:2rem;padding-left:2rem}.doc>h3{position:sticky;top:0;z-index:1;margin-bottom:-1px}.container-overview,.member{overflow:hidden}#readme,.doc>.member{max-width:1024px;margin-left:auto;margin-right:auto}#readme{padding:7.5% 10% 10%}.doc>.member{padding-bottom:5%;padding-top:10%}h3~.param-desc{margin-bottom:2rem}.member>:not(h5):not(h4):not(h3):not(h2):not(.param-desc):not(:last-child):not(.example-wrapper){margin-bottom:50px}#readme h2,#readme h3{margin-top:100px}#readme h4,#readme h5,#readme h6,.container-overview>.member>:first-child:not(.description),.container-overview>:first-child:not(.description):not(.member),.member h2{margin-top:50px}.doc:not([data-kind=globalobj])>h3{margin-top:5%}.container-overview>:not(h5):not(h4):not(h3):not(h2):not(:last-child){margin-bottom:50px}.member>:last-child{margin-bottom:0}dd{margin-bottom:2em}dd+dd{margin-top:-2em}table h6{padding-top:2em}#readme p{margin-bottom:2em;max-width:55em}#readme br,.member>.description br{margin-bottom:5%}.prettyprint{white-space:pre-wrap;overflow:hidden;padding:4% 5% 5%;box-sizing:border-box;font-size:80%}.source-code-wrapper>.source{min-width:720px}.code-caption{padding:1rem 2rem 0}.example-wrapper,.source-code-wrapper{overflow:auto}.example{position:relative;width:100%;display:block;margin-top:2rem;min-width:720px}#readme p:first-of-type,.class-description,.description:not(td),.summary{font-size:125%}.signature-attributes{font-size:50%}.type-signature{font-size:60%;font-weight:lighter;position:relative}h4.name{font-size:200%}.doc{padding:50px;width:100%;box-sizing:border-box;overflow-wrap:break-word}.signature{font-weight:lighter;margin-left:10px;font-size:80%}.disabled{text-decoration:line-through}.important{font-weight:bolder}dt.tag-deprecated,dt.tag-deprecated+dd{margin-left:calc(-2rem - 2px);padding-left:2rem}.is-searching nav li:not(.matches),.is-searching nav ul:not(.matches){display:none}.is-searching nav ul.matches{margin-top:0;margin-bottom:0}.is-searching nav h3{display:none}#content-nav li abbr{font-size:50%;text-decoration:none;text-align:center;font-weight:bolder;text-transform:uppercase;display:inline-block;vertical-align:middle;margin-right:1em;width:4em;white-space:nowrap;overflow:hidden;padding-top:1px}@media (max-width:767px){h4.name{font-size:150%}.signature{vertical-align:baseline}.description:not(td),.signature{font-size:100%}.doc>.member{padding:50px 0;margin:0}#content>header,#readme,.doc{padding:30px}#content>header{padding-right:60px}.prettyprint{padding:2rem}}@media (max-width:1359px){#page-header{position:fixed;top:0;right:0;bottom:0;z-index:998;order:2}body:not(.is-page-header-open) #page-header{opacity:0;visibility:hidden}#page-header>*{transition:all .35s ease;opacity:1;transform:translateX(0)}body:not(.is-page-header-open) #page-header>*{opacity:0;transform:translateX(25px)}#main-wrapper{width:100%}#page-header-opener{position:fixed;top:0;right:0;z-index:998}input[type=search]{padding-left:15px;padding-right:60px}}@media (min-width:1360px){article>.member{padding-bottom:10%}#page-header-opener{display:none}} \ No newline at end of file diff --git a/doc/css/tomorrow.min.css b/doc/css/tomorrow.min.css deleted file mode 100644 index 53813bb..0000000 --- a/doc/css/tomorrow.min.css +++ /dev/null @@ -1,2 +0,0 @@ -/*! Color themes for Google Code Prettify | MIT License | github.com/jmblog/color-themes-for-google-code-prettify */ -.prettyprint{background:#f6f6f6;font-family:Menlo,Bitstream Vera Sans Mono,DejaVu Sans Mono,Monaco,Consolas,monospace;border:0!important}.pln,{color:inherit}ol.linenums{margin-top:0;margin-bottom:0;color:#8e908c}li.L0,li.L1,li.L2,li.L3,li.L4,li.L5,li.L6,li.L7,li.L8,li.L9{padding-left:1em;background-color:inherit;list-style-type:decimal}@media screen{.str{color:#718c00}.kwd{color:#8959a8}.com{color:#8e908c}.typ{color:#4271ae}.lit{color:#f5871f}.pun,.opn,.clo{color:inherit}.tag{color:#c82829}.atn{color:#f5871f}.atv{color:#3e999f}.dec{color:#f5871f}.var{color:#c82829}.fun{color:#4271ae}} \ No newline at end of file diff --git a/doc/detect%0ALanguage%20detectormodule_.html b/doc/detect%0ALanguage%20detectormodule_.html deleted file mode 100644 index 98db76b..0000000 --- a/doc/detect%0ALanguage%20detectormodule_.html +++ /dev/null @@ -1,309 +0,0 @@ - - - - - Module: detect -Language detector - JSDoc - - - - -
- -
- -
-
-

Module: detect -Language detector

-
- - - - -
- -
- -

detect -Language detector

- - -
- -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- detect.js, line 1 -
- - - - - - - -
- - - - - - -
- - - - - - - - - - - - - - - - -

Methods

- - - -
- - - - -

detectLanguage -Try to find the language the given code belong to(code) → {String}

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- detect.js, line 30 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
code -
-
- - -String - - - - The code
-
- - - - - - - - - - - - - - - -
Returns:
- - -
- The language of the code -
- - - -
-
- Type -
-
- -String - - -
-
- - - - - - -
- - - - - - - -
- - - - -
- -
-
- - - - - - - - \ No newline at end of file diff --git a/doc/detect.js.html b/doc/detect.js.html deleted file mode 100644 index 57d4f9e..0000000 --- a/doc/detect.js.html +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - Source: detect.js - JSDoc - - - - -
- -
- -
-
-

Source: detect.js

-
- - - - - -
-
/**
- * @module detect
- * Language detector
-*/
-
-const languages = [
-	['bash', [/#!(\/usr)?\/bin\/bash/g, 500], [/\b(if|elif|then|fi|echo)\b|\$/g, 10]],
-	['html', [/<\/?[a-z-]+[^\n>]*>/g, 10], [/^\s+<!DOCTYPE\s+html/g, 500]],
-	['http', [/^(GET|HEAD|POST|PUT|DELETE|PATCH|HTTP)\b/g, 500]],
-	['js', [/\b(console|await|async|function|export|import|this|class|for|let|const|map|join|require)\b/g, 10]],
-	['ts', [/\b(console|await|async|function|export|import|this|class|for|let|const|map|join|require|implements|interface|namespace)\b/g, 10]],
-	['py', [/\b(def|print|class|and|or|lambda)\b/g, 10]],
-	['sql', [/\b(SELECT|INSERT|FROM)\b/g, 50]],
-	['pl', [/#!(\/usr)?\/bin\/perl/g, 500], [/\b(use|print)\b|\$/g, 10]],
-	['lua', [/#!(\/usr)?\/bin\/lua/g, 500]],
-	['make', [/\b(ifneq|endif|if|elif|then|fi|echo|.PHONY|^[a-z]+ ?:$)\b|\$/gm, 10]],
-	['uri', [/https?:|mailto:|tel:|ftp:/g, 30]],
-	['css', [/^(@import|@page|@media|(\.|#)[a-z]+)/gm, 20]],
-	['diff', [/^[+><-]/gm, 10], [/^@@ ?[-+,0-9 ]+ ?@@/gm, 25]],
-	['md', [/^(>|\t\*|\t\d+.)/gm, 10], [/\[.*\](.*)/g, 10]],
-	['docker', [/^(FROM|ENTRYPOINT|RUN)/gm, 500]],
-	['xml', [/<\/?[a-z-]+[^\n>]*>/g, 10], [/^<\?xml/g, 500]],
-	['c', [/#include\b|\bprintf\s+\(/g, 100]],
-	['rs', [/^\s+(use|fn|mut|match)\b/gm, 100]],
-	['go', [/\b(func|fmt|package)\b/g, 100]],
-	['java', [/^import\s+java/gm, 500]],
-	['asm', [/^(section|global main|extern|\t(call|mov|ret))/gm, 100]],
-]
-
-/**
- * @function detectLanguage
- * Try to find the language the given code belong to
- * @param {String} code The code
- * @returns {String} The language of the code
- */
-export const detectLanguage = code => {
-	return (languages
-		.map(([lang, ...features]) => [
-			features.reduce((acc, [match, score]) => acc + [...code.matchAll(match)].length * score, 0),
-			lang
-		])
-		.filter(([score, lang]) => score > 10)
-		.sort((a, b) => b[0] - a[0])[0]?.[1] || 'plain');
-}
-
-
- - - - - -
- -
-
- - - - - - - - diff --git a/doc/global.html b/doc/global.html deleted file mode 100644 index c1f4acf..0000000 --- a/doc/global.html +++ /dev/null @@ -1,1826 +0,0 @@ - - - - - Global - JSDoc - - - - -
- -
- -
-
-

Global

-
- - - - -
- -
- -

Global scope

- -
- -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - -
- - - - - - - - - - - - - - -

Members

- - - -
-

languages

- - - - -
- Language detector -
- - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- detect.js, line 5 -
- - - - - - - -
- - - - - - - - - -
- - - - -

Methods

- - - -
- - - - -

Call highlightElement on element with a css class starting with `shj-lang-`(optopt)

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 130 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
opt -
- - - - [optional] - - - - - - -
- - -HighlightOptions - - - - - - {} - - Customization options
-
- - - - - - - - - - - - - - - - - - - -
- - -
- - - - -

Change the current used theme for highlighting(name)

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- term.js, line 33 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
name -
-
- - -String - - - - The name of the theme
-
- - - - - - - - - - - - - - - - - - - -
- - -
- - - - -

Find the tokens in the given code and call the callback(src, lang, token)

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 20 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
src -
-
- - -String - - - - The code
lang -
-
- - -String - or - -Object - - - - The language of the code
token -
-
- - -function - - - - The callback function -this function will be given -* the text of the token -* the type of the token
-
- - - - - - - - - - - - - - - - - - - -
- - -
- - - - -

Highlight a DOM element by getting the new innerHTML with highlightText(elm, langopt, modeopt, optopt)

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 110 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
elm -
- - - - - - - - -
- - -HTMLElement - - - - - - The DOM element
lang -
- - - - [optional] - - - - - - -
- - -String - - - - - - The language of the code (seaching by default on `elm` for a 'shj-lang-' class)
mode -
- - - - [optional] - - - - - - -
- - -String - - - - - - The display mode (guessed by default) -* inline inside `code` element -* oneline inside `div` element and containing only one line -* multiline inside `div` element
opt -
- - - - [optional] - - - - - - -
- - -HighlightOptions - - - - - - {} - - Customization options
-
- - - - - - - - - - - - - - - - - - - -
- - -
- - - - -

Highlight a string passed as argument and return a string that can directly be printed(src, lang) → {String}

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- term.js, line 9 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
src -
-
- - -String - - - - The code
lang -
-
- - -String - - - - The language of the code
-
- - - - - - - - - - - - - - - -
Returns:
- - -
- The highlighted string -
- - - -
-
- Type -
-
- -String - - -
-
- - - - - - -
- - -
- - - - -

Highlight a string passed as argument and return it(src, lang, multilineopt, optopt) → {String}

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 89 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
src -
- - - - - - - - -
- - -String - - - - - - The code
lang -
- - - - - - - - -
- - -String - - - - - - The language of the code
multiline -
- - - - [optional] - - - - - - -
- - -Boolean - - - - - - true - - If it is multiline, it will add a wrapper for the line numbering and header
opt -
- - - - [optional] - - - - - - -
- - -HighlightOptions - - - - - - {} - - Customization options
-
- - - - - - - - - - - - - - - -
Returns:
- - -
- The highlighted string -
- - - -
-
- Type -
-
- -String - - -
-
- - - - - - -
Example
- -
-
- -
elm.innerHTML = await highlightText(code, 'js');
-
-
- - -
- - -
- - - - -

Highlight and print a given string(code)

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- term.js, line 25 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
code -
-
- - -String - - - - The code
-
- - - - - - - - - - - - - - - - - - - -
- - -
- - - - -

Try to find the language the given code belong to(code) → {String}

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- detect.js, line 29 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
code -
-
- - -String - - - - The code
-
- - - - - - - - - - - - - - - -
Returns:
- - -
- The language of the code -
- - - -
-
- Type -
-
- -String - - -
-
- - - - - - -
- - - - -

Type Definitions

- - - -
-

HighlightOptions

- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 84 -
- - - - - - - -
- - - -
Properties:
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
hideLineNumbers -
- - - - [optional] - - - - - -
- - -Boolean - - - - - - false - - Indicates whether to hide line numbers
-
- - - - - - -
Type:
-

-Object - -

- - - - - -
- - - - - -
- - - - -
- -
-
- - - - - - - - \ No newline at end of file diff --git a/doc/index%0ABase%20scriptmodule_.html b/doc/index%0ABase%20scriptmodule_.html deleted file mode 100644 index 1356350..0000000 --- a/doc/index%0ABase%20scriptmodule_.html +++ /dev/null @@ -1,1179 +0,0 @@ - - - - - Module: index -Base script - JSDoc - - - - -
- -
- -
-
-

Module: index -Base script

-
- - - - -
- -
- -

index -Base script

- - -
- -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 1 -
- - - - - - - -
- - - - - - -
- - - - - - - - - - - - - - - - -

Methods

- - - -
- - - - -

highlightAll(optopt)

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 131 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
opt -
- - - - [optional] - - - - - - -
- - -HighlightOptions - - - - - - {} - - Customization options
-
- - - - - - - - - - - - - - - - - - - -
- - -
- - - - -

highlightElement(elm, langopt, modeopt, optopt)

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 111 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
elm -
- - - - - - - - -
- - -HTMLElement - - - - - - The DOM element
lang -
- - - - [optional] - - - - - - -
- - -String - - - - - - The language of the code (seaching by default on `elm` for a 'shj-lang-' class)
mode -
- - - - [optional] - - - - - - -
- - -String - - - - - - The display mode (guessed by default) -* inline inside `code` element -* oneline inside `div` element and containing only one line -* multiline inside `div` element
opt -
- - - - [optional] - - - - - - -
- - -HighlightOptions - - - - - - {} - - Customization options
-
- - - - - - - - - - - - - - - - - - - -
- - -
- - - - -

highlightText(src, lang, multilineopt, optopt) → {String}

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 90 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
src -
- - - - - - - - -
- - -String - - - - - - The code
lang -
- - - - - - - - -
- - -String - - - - - - The language of the code
multiline -
- - - - [optional] - - - - - - -
- - -Boolean - - - - - - true - - If it is multiline, it will add a wrapper for the line numbering and header
opt -
- - - - [optional] - - - - - - -
- - -HighlightOptions - - - - - - {} - - Customization options
-
- - - - - - - - - - - - - - - -
Returns:
- - -
- The highlighted string -
- - - -
-
- Type -
-
- -String - - -
-
- - - - - - -
Example
- -
-
- -
elm.innerHTML = await highlightText(code, 'js');
-
-
- - -
- - -
- - - - -

tokenize -Find the tokens in the given code and call the callback(src, lang, token)

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 21 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
src -
-
- - -String - - - - The code
lang -
-
- - -String - or - -Object - - - - The language of the code
token -
-
- - -function - - - - The callback function -this function will be given -* the text of the token -* the type of the token
-
- - - - - - - - - - - - - - - - - - - -
- - - - -

Type Definitions

- - - -
-

HighlightOptions

- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- index.js, line 85 -
- - - - - - - -
- - - -
Properties:
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
hideLineNumbers -
- - - - [optional] - - - - - -
- - -Boolean - - - - - - false - - Indicates whether to hide line numbers
-
- - - - - - -
Type:
-

-Object - -

- - - - - -
- - - - - -
- - - - -
- -
-
- - - - - - - - \ No newline at end of file diff --git a/doc/index.html b/doc/index.html deleted file mode 100644 index 40fe2a3..0000000 --- a/doc/index.html +++ /dev/null @@ -1,402 +0,0 @@ - - - - - Home - JSDoc - - - - -
- -
- -
-
-

Home

-
- - - - - - - - - - - - - - - - - - - - - -

Speed-highlight JS

-

Light, fast, and easy to use, dependencies free javascript syntax highlighter, with automatic language detection, try it out here

-

-

Light 📦

-
    -
  • The core is about 1kB (gzipped & minified)
  • -
  • Languages definition are from a few bytes to 1kB
  • -
  • Themes are about 1kB
  • -
  • Language rules needed are automatically loaded
  • -
-

Fast ⚡

-

Blazing fast highlighting using regex

-

Simple setup 🚀

-

Web

-

Style/theme (in the header of your html file):

-
<link rel="stylesheet" href="/path/dist/themes/default.css">
-
-

In the body of your html file:

-
<div class='shj-lang-[code-language]'>[code]</div>
-or
-<code class='shj-lang-[code-language]'>[inline code]</code>
-
-

Highlight the code (in your javascript):

-
import { highlightAll } from '/path/dist/index.js'
-highlightAll();
-
-

Auto language detection

-
import { highlightElement } from '../src/index.js';
-import { detectLanguage } from '../src/detect.js';
-
-elm.textContent = code;
-highlightElement(elm, detectLanguage(code));
-
-

CDN

-
<link rel="stylesheet" href="https://unpkg.com/@speed-highlight/core/dist/themes/default.css">
-<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/speed-highlight/core/dist/themes/default.css">
-
-
import ... from 'https://unpkg.com/@speed-highlight/core/dist/index.js'
-import ... from 'https://cdn.jsdelivr.net/gh/speed-highlight/core/dist/index.js'
-
-

Deno

-

Use the deno module

-
import { setTheme, printHighlight } from 'https://x.nest.land/speed_highlight_js/dist/term.js';
-
-await setTheme('[theme-name]')
-printHighlight('console.log("hello")', 'js')
-
-

Node

-

Use the npm package

-
npm i @speed-highlight/core
-
-
const { setTheme, printHighlight } = require('@speed-highlight/core/dist/node/term.js');
-
-setTheme('[theme-name]')
-printHighlight('console.log("hello")', 'js')
-
-

Languages supported 🌐

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameClass nameSupportLanguage detection
bashshj-lang-bash
brainfuckshj-lang-bfincrement, operator, print, comment
cssshj-lang-csscomment, str, selector, units, function, ...
csvshj-lang-csvpunctuation, ...
diffshj-lang-diff
gitshj-lang-gitcomment, insert, deleted, string, ...
htmlshj-lang-html
httpshj-lang-httpkeywork, string, punctuation, variable, version
inishj-lang-ini
javasciptshj-lang-jsbasic syntax, regex, jsdoc, json, template literals
jsdocshj-lang-jsdoc
jsonshj-lang-jsonstring, number, bool, ...
leanpub-mdshj-lang-leanpub-md
logshj-lang-lognumber, string, comment, errors
luashj-lang-lua
makefileshj-lang-make
markdownshj-lang-md
perlshj-lang-pl
plainshj-lang-plain
pythonshj-lang-py
regexshj-lang-regexcount, set, ...
sqlshj-lang-sqlnumber, string, function, ...
todoshj-lang-todo
tomlshj-lang-tomlcomment, table, string, bool, variable
typescriptshj-lang-tsjs syntax, ts keyword, types
urishj-lang-uri
yamlshj-lang-yamlcomment, numbers, variable, string, bool
dockershj-lang-docker
cshj-lang-c
xmlshj-lang-xml
rustshj-lang-rs
goshj-lang-go
javashj-lang-java
asmshj-lang-asm
-

Themes 🌈

-

A modern theme by default

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTerminalWeb
default
github-dark
github-light
github-dim
atom-dark
visual-studio-dark
-

Documentation 👀

-

Further in-depth documentation for the API and other topics is in our Wiki and our Documentation

-

License 📃

-

Shj is released under the Creative Commons Zero License. See our LICENSE file for details.

- - - - - - -
- -
-
- - - - - - - - \ No newline at end of file diff --git a/doc/index.js.html b/doc/index.js.html deleted file mode 100644 index 466307f..0000000 --- a/doc/index.js.html +++ /dev/null @@ -1,209 +0,0 @@ - - - - - - Source: index.js - JSDoc - - - - -
- -
- -
-
-

Source: index.js

-
- - - - - -
-
/**
- * @module index
- * Base script
-*/
-
-import expandData from './common.js';
-
-const langs = {},
-	sanitize = (str = '') =>
-		str.replaceAll('&', '&#38;').replaceAll?.('<', '&lt;').replaceAll?.('>', '&gt;'),
-	/**
-	 * @function
-	 * @private
-	 * Create a HTML element with the right token styling
-	 * @param {String} str The content (need to be sanitized)
-	 * @param {String} [token] The type of token
-	 * @returns A HMTL string
-	 */
-	toSpan = (str, token) => token ? `<span class="shj-syn-${token}">${str}</span>` : str;
-
-/**
- * @function tokenize
- * Find the tokens in the given code and call the callback
- * @param {String} src The code
- * @param {String|Object} lang The language of the code
- * @param {Function} token The callback function
- * this function will be given
- * * the text of the token
- * * the type of the token
- */
-export async function tokenize(src, lang, token) {
-	try {
-		let m,
-			part,
-			first = {},
-			match,
-			cache = [],
-			i = 0,
-			data = typeof lang === 'string' ? (await (langs[lang] ??= import(`./languages/${lang}.js`))) : lang,
-			// make a fast shallow copy to bee able to splice lang without change the original one
-			arr = [...typeof lang === 'string' ? data.default : lang.sub];
-
-		while (i < src.length) {
-			first.index = null;
-			for (m = arr.length; m-- > 0;) {
-				part = arr[m].expand ? expandData[arr[m].expand] : arr[m];
-				// do not call again exec if the previous result is sufficient
-				if (cache[m] === undefined || cache[m].match.index < i) {
-					part.match.lastIndex = i;
-					match = part.match.exec(src);
-					if (match === null) {
-						// no more match with this regex can be disposed
-						arr.splice(m, 1);
-						cache.splice(m, 1);
-						continue;
-					}
-					// save match for later use to decrease performance cost
-					cache[m] = { match, lastIndex: part.match.lastIndex };
-				}
-				// check if it the first match in the string
-				if (cache[m].match[0] && (cache[m].match.index <= first.index || first.index === null))
-					first = {
-						part: part,
-						index: cache[m].match.index,
-						match: cache[m].match[0],
-						end: cache[m].lastIndex
-					}
-			}
-			if (first.index === null)
-				break;
-			token(src.slice(i, first.index), data.type);
-			i = first.end;
-			if (first.part.sub)
-				await tokenize(first.match, typeof first.part.sub === 'string' ? first.part.sub : (typeof first.part.sub === 'function' ? first.part.sub(first.match) : first.part), token);
-			else
-				token(first.match, first.part.type);
-		}
-		token(src.slice(i, src.length), data.type);
-	}
-	catch {
-		token(src);
-	}
-}
-
-/**
- * @typedef {Object} HighlightOptions
- * @property {Boolean} [hideLineNumbers=false] Indicates whether to hide line numbers
- */
-
-/**
- * @function highlightText
- * @async
- * Highlight a string passed as argument and return it
- * @example
- * elm.innerHTML = await highlightText(code, 'js');
- * @param {String} src The code
- * @param {String} lang The language of the code
- * @param {Boolean} [multiline=true] If it is multiline, it will add a wrapper for the line numbering and header
- * @param {HighlightOptions} [opt={}] Customization options
- * @returns {String} The highlighted string
- */
-export async function highlightText(src, lang, multiline = true, opt = {}) {
-	let tmp = ''
-	await tokenize(src, lang, (str, type) => tmp += toSpan(sanitize(str), type))
-
-	return multiline
-		? `<div><div class="shj-numbers">${'<div></div>'.repeat(!opt.hideLineNumbers && src.split('\n').length)}</div><div>${tmp}</div></div>`
-		: tmp;
-}
-
-/**
- * @function highlightElement
- * @async
- * Highlight a DOM element by getting the new innerHTML with highlightText
- * @param {HTMLElement} elm The DOM element
- * @param {String} [lang] The language of the code (seaching by default on `elm` for a 'shj-lang-' class)
- * @param {String} [mode] The display mode (guessed by default)
- * * inline inside `code` element
- * * oneline inside `div` element and containing only one line
- * * multiline inside `div` element
- * @param {HighlightOptions} [opt={}] Customization options
- */
-export async function highlightElement(elm, lang = elm.className.match(/shj-lang-([\w-]+)/)?.[1], mode, opt) {
-	let txt = elm.textContent;
-	mode ??= `${elm.tagName == 'CODE' ? 'in' : (txt.split('\n').length < 2 ? 'one' : 'multi')}line`;
-	elm.dataset.lang = lang;
-	elm.className = `${[...elm.classList].filter(className => !className.startsWith('shj-') || className.startsWith('shj-mode-')).join(' ')} shj-lang-${lang} shj-${mode}`;
-	elm.innerHTML = await highlightText(txt, lang, mode == 'multiline', opt);
-}
-
-/**
- * @function highlightAll
- * @async
- * Call highlightElement on element with a css class starting with `shj-lang-`
- * @param {HighlightOptions} [opt={}] Customization options
- */
-export let highlightAll = async (opt) =>
-	document
-		.querySelectorAll('[class*="shj-lang-"]')
-		.forEach(elm => highlightElement(elm, undefined, undefined, opt))
-
-
- - - - - -
- -
-
- - - - - - - - diff --git a/doc/js/jsdoc-template.js b/doc/js/jsdoc-template.js deleted file mode 100644 index 0eee5e2..0000000 --- a/doc/js/jsdoc-template.js +++ /dev/null @@ -1,2 +0,0 @@ -!function(t){var e={};function n(a){if(e[a])return e[a].exports;var r=e[a]={i:a,l:!1,exports:{}};return t[a].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,a){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(a,r,function(e){return t[e]}.bind(null,r));return a},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(t,e){e.toArray=function(t){return[].slice.call(t)},e.find=function(t,n){return e.toArray((n||document).querySelectorAll(String(t)))},e.findParent=function(t,e){for(var n=t;(n=n.parentNode)&&!e.call(n););return n},e.on=function(t,n,a,r){"string"==typeof t&&(t=e.find(t)),Array.isArray(t)||(t=[t]),Array.isArray(n)||(n=[n]),t.forEach(function(t){n.forEach(function(e){t.addEventListener(e,a,r||!1)})})},e.onState=function(t,n,a,r){return e.on(t,":"+n,a,r)},e.onGlobalState=function(t,n,a){var r=e.getGlobalStates()[t],o=e.getGlobalElement();return e.onState(o,r,n,a)},e.hasState=function(t,e){return t.classList.contains(e)},e.hasGlobalState=function(t){return e.hasState(e.getGlobalElement(),t)},e.getGlobalElement=function(){return document.body},e.triggerCustomEvent=function(t,e,n){return t.dispatchEvent(new CustomEvent(e,n))},e.triggerState=function(t,n,a,r){return e.triggerCustomEvent(t,":"+n,{detail:{action:a,data:r}})},e.triggerGlobalState=function(t,n,a){return e.triggerState(e.getGlobalElement(),t,n,a)},e.getRawState=function(t,e){return t.getAttribute(e)},e.changeState=function(t,n,a,r){var o,i="data-s-"+n;return a||(a=e.getRawState(t,i))||(a="is-active"),!!/(add|remove|toggle)/.test(n)&&((o=!1!==e.triggerState(t,a,n,r))&&t.classList[n](a),o)},e.addState=function(t,n,a){return e.changeState(t,"add",n,a)},e.addGlobalState=function(t,n,a){return e.addState(e.getGlobalElement(),"add",n,a)},e.removeState=function(t,n,a){return e.changeState(t,"remove",n,a)},e.removeGlobalState=function(t,n,a){return e.removeState(e.getGlobalElement(),"remove",n,a)},e.toggleState=function(t,n,a){return e.changeState(t,"toggle",n,a)},e.toggleGlobalState=function(t,n,a){return e.toggleState(e.getGlobalElement(),"toggle",n,a)},e.getStates=function(t,n){var a,r=e.getRawState(t,n||"data-s");try{a=JSON.parse(r)}catch(t){return{}}return a instanceof Object?a:{}},e.getState=function(t,n,a){return e.getStates(t,n,a)},e.getGlobalStates=function(t){return e.getStates(e.getGlobalElement(),t||"data-gs")},e.changeGlobalState=function(t,n,a){return e.changeState(e.getGlobalElement(),t,n,a)},e.escapeRegExp=function(t){return t.replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&")}},function(t,e,n){"use strict";n.r(e);var a,r;n(2),n(3),n(4),n(5),n(6),n(7);a=n(0),r=function(){var t=location.href.split(/.+\//)[1];a.find('nav li > a[href="'+t+'"]').forEach(function(t){a.addState(t.parentNode)})},a.on(window,"hashchange",function(){a.find("nav li.is-active > a").forEach(function(t){a.removeState(t.parentNode)}),r()}),a.on("a","click",function(){var t=a.find("#page-header-opener")[0];this.hash&&a.hasState(t,"is-active")&&t.click()}),r()},function(t,e,n){},function(t,e,n){},function(t,e,n){var a,r;a=n(0),r=a.getGlobalStates(),a.onState("[data-gs-toggle]","is-active",function(){var t=r[a.getRawState(this,"data-gs-toggle")];a.changeGlobalState("toggle",t)})},function(t,e,n){var a;(a=n(0)).on("[data-gs-toggle]","click",function(){a.toggleState(this)})},function(t,e,n){var a,r;a=n(0),r=a.getGlobalStates(),a.on("input[data-internal-search]",["input","focus","blur"],function(t){var e=this.value.trim(),n=this.getAttribute("data-internal-search"),o=new RegExp("^"+a.escapeRegExp(e),"igm"),i=a.find(n),l="blur"!==t.type,u=e;a.changeGlobalState(u?"add":"remove",r.searching),i.forEach(function(t){var n=t.textContent;o.test(n)&&l?(t.innerHTML=n.replace(o,""+n.slice(0,e.length)+""),a.findParent(t.firstChild,function(){return a.addState(this,"matches"),/ul|ol/i.test(this.tagName)})):(t.innerHTML=n,l&&a.findParent(t.firstChild,function(){return!!/ul|ol/i.test(this.tagName)||(a.removeState(this,"matches"),!1)}))})})},function(t,e){window.addEventListener("load",function(){var t,e,n,a,r=document.getElementsByClassName("prettyprint source linenums"),o=0,i=0;if(r&&r[0])for(a=document.location.hash.substring(1),n=(e=r[0].getElementsByTagName("li")).length;o a[href=\"' + currentPageID + '\"]').forEach(function(link) {\n helpers.addState(link.parentNode);\n });\n };\n\n helpers.on(window, 'hashchange', function() {\n helpers.find('nav li.is-active > a').forEach(function(target) {\n helpers.removeState(target.parentNode);\n });\n\n updateActiveLink();\n });\n\n helpers.on('a', 'click', function() {\n var pageHeaderOpener = helpers.find('#page-header-opener')[0];\n\n /** Close nav when an anchor is clicked. */\n if (this.hash && helpers.hasState(pageHeaderOpener, 'is-active')) {\n pageHeaderOpener.click();\n }\n });\n\n updateActiveLink();\n})();\n","(function() {\n var helpers = require('./helpers');\n var globalStates = helpers.getGlobalStates();\n\n helpers.onState('[data-gs-toggle]', 'is-active', function() {\n var gs = globalStates[helpers.getRawState(this, 'data-gs-toggle')];\n\n helpers.changeGlobalState('toggle', gs);\n });\n})();\n","(function() {\n var helpers = require('./helpers');\n\n helpers.on('[data-gs-toggle]', 'click', function() {\n helpers.toggleState(this);\n });\n})();\n","(function() {\n var helpers = require('./helpers');\n var globalStates = helpers.getGlobalStates();\n\n helpers.on('input[data-internal-search]', ['input', 'focus', 'blur'], function(e) {\n var searchTerm = this.value.trim();\n var targetSelector = this.getAttribute('data-internal-search');\n var searchTermRegExp = new RegExp('^' + helpers.escapeRegExp(searchTerm), 'igm');\n var targets = helpers.find(targetSelector);\n var isActive = e.type !== 'blur';\n var isSearching = searchTerm;\n\n helpers.changeGlobalState(isSearching ? 'add' : 'remove', globalStates.searching);\n\n targets.forEach(function(target) {\n var targetText = target.textContent;\n\n if (searchTermRegExp.test(targetText) && isActive) {\n target.innerHTML = targetText.replace(searchTermRegExp, '' +\n targetText.slice(0, searchTerm.length) + '');\n\n helpers.findParent(target.firstChild, function() {\n helpers.addState(this, 'matches');\n\n return /ul|ol/i.test(this.tagName);\n });\n }\n else {\n target.innerHTML = targetText;\n\n if (isActive) {\n helpers.findParent(target.firstChild, function() {\n if (/ul|ol/i.test(this.tagName)) {\n return true;\n }\n\n helpers.removeState(this, 'matches');\n\n return false;\n });\n }\n }\n });\n });\n})();\n","window.addEventListener('load', function() {\n var source = document.getElementsByClassName('prettyprint source linenums');\n var i = 0;\n var lineNumber = 0;\n var lineId;\n var lines;\n var totalLines;\n var anchorHash;\n\n if (source && source[0]) {\n anchorHash = document.location.hash.substring(1);\n lines = source[0].getElementsByTagName('li');\n totalLines = lines.length;\n\n for (; i < totalLines; i++) {\n lineNumber++;\n lineId = 'line' + lineNumber;\n lines[i].id = lineId;\n if (lineId === anchorHash) {\n lines[i].className += ' selected';\n lines[i].scrollIntoView();\n }\n }\n }\n});\n"],"sourceRoot":""} \ No newline at end of file diff --git a/doc/js/prettify.min.js b/doc/js/prettify.min.js deleted file mode 100644 index 2e75f26..0000000 --- a/doc/js/prettify.min.js +++ /dev/null @@ -1,47 +0,0 @@ -!function(){/* - - Copyright (C) 2006 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -"undefined"!==typeof window&&(window.PR_SHOULD_USE_CONTINUATION=!0); -(function(){function T(a){function d(e){var a=e.charCodeAt(0);if(92!==a)return a;var c=e.charAt(1);return(a=w[c])?a:"0"<=c&&"7">=c?parseInt(e.substring(1),8):"u"===c||"x"===c?parseInt(e.substring(2),16):e.charCodeAt(1)}function f(e){if(32>e)return(16>e?"\\x0":"\\x")+e.toString(16);e=String.fromCharCode(e);return"\\"===e||"-"===e||"]"===e||"^"===e?"\\"+e:e}function c(e){var c=e.substring(1,e.length-1).match(RegExp("\\\\u[0-9A-Fa-f]{4}|\\\\x[0-9A-Fa-f]{2}|\\\\[0-3][0-7]{0,2}|\\\\[0-7]{1,2}|\\\\[\\s\\S]|-|[^-\\\\]","g")); -e=[];var a="^"===c[0],b=["["];a&&b.push("^");for(var a=a?1:0,g=c.length;ak||122k||90k||122h[0]&&(h[1]+1>h[0]&&b.push("-"),b.push(f(h[1])));b.push("]");return b.join("")}function m(e){for(var a=e.source.match(RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g")),b=a.length,d=[],g=0,h=0;g/,null])):d.push(["com",/^#[^\r\n]*/,null,"#"]));a.cStyleComments&&(f.push(["com",/^\/\/[^\r\n]*/,null]),f.push(["com",/^\/\*[\s\S]*?(?:\*\/|$)/,null]));if(c=a.regexLiterals){var m=(c=1|\\/=?|::?|<>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*("+ -("/(?=[^/*"+c+"])(?:[^/\\x5B\\x5C"+c+"]|\\x5C"+m+"|\\x5B(?:[^\\x5C\\x5D"+c+"]|\\x5C"+m+")*(?:\\x5D|$))+/")+")")])}(c=a.types)&&f.push(["typ",c]);c=(""+a.keywords).replace(/^ | $/g,"");c.length&&f.push(["kwd",new RegExp("^(?:"+c.replace(/[\s,]+/g,"|")+")\\b"),null]);d.push(["pln",/^\s+/,null," \r\n\t\u00a0"]);c="^.[^\\s\\w.$@'\"`/\\\\]*";a.regexLiterals&&(c+="(?!s*/)");f.push(["lit",/^@[a-z_$][a-z_$@0-9]*/i,null],["typ",/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],["pln",/^[a-z_$][a-z_$@0-9]*/i, -null],["lit",/^(?:0x[a-f0-9]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+\-]?\d+)?)[a-z]*/i,null,"0123456789"],["pln",/^\\[\s\S]?/,null],["pun",new RegExp(c),null]);return G(d,f)}function L(a,d,f){function c(a){var b=a.nodeType;if(1==b&&!t.test(a.className))if("br"===a.nodeName.toLowerCase())m(a),a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)c(a);else if((3==b||4==b)&&f){var e=a.nodeValue,d=e.match(q);d&&(b=e.substring(0,d.index),a.nodeValue=b,(e=e.substring(d.index+ -d[0].length))&&a.parentNode.insertBefore(l.createTextNode(e),a.nextSibling),m(a),b||a.parentNode.removeChild(a))}}function m(a){function c(a,b){var e=b?a.cloneNode(!1):a,k=a.parentNode;if(k){var k=c(k,1),d=a.nextSibling;k.appendChild(e);for(var f=d;f;f=d)d=f.nextSibling,k.appendChild(f)}return e}for(;!a.nextSibling;)if(a=a.parentNode,!a)return;a=c(a.nextSibling,0);for(var e;(e=a.parentNode)&&1===e.nodeType;)a=e;b.push(a)}for(var t=/(?:^|\s)nocode(?:\s|$)/,q=/\r\n?|\n/,l=a.ownerDocument,n=l.createElement("li");a.firstChild;)n.appendChild(a.firstChild); -for(var b=[n],p=0;p=+m[1],d=/\n/g,t=a.a,q=t.length,f=0,l=a.c,n=l.length,c=0,b=a.g,p=b.length,w=0;b[p]=q;var r,e;for(e=r=0;e=h&&(c+=2);f>=k&&(w+=2)}}finally{g&&(g.style.display=a)}}catch(y){D.console&&console.log(y&&y.stack||y)}}var D="undefined"!==typeof window? -window:{},B=["break,continue,do,else,for,if,return,while"],F=[[B,"auto,case,char,const,default,double,enum,extern,float,goto,inline,int,long,register,restrict,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"],"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],H=[F,"alignas,alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,delegate,dynamic_cast,explicit,export,friend,generic,late_check,mutable,namespace,noexcept,noreturn,nullptr,property,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"], -O=[F,"abstract,assert,boolean,byte,extends,finally,final,implements,import,instanceof,interface,null,native,package,strictfp,super,synchronized,throws,transient"],P=[F,"abstract,add,alias,as,ascending,async,await,base,bool,by,byte,checked,decimal,delegate,descending,dynamic,event,finally,fixed,foreach,from,get,global,group,implicit,in,interface,internal,into,is,join,let,lock,null,object,out,override,orderby,params,partial,readonly,ref,remove,sbyte,sealed,select,set,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,value,var,virtual,where,yield"], -F=[F,"abstract,async,await,constructor,debugger,enum,eval,export,from,function,get,import,implements,instanceof,interface,let,null,of,set,undefined,var,with,yield,Infinity,NaN"],Q=[B,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"],R=[B,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"], -B=[B,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],S=/^(DIR|FILE|array|vector|(de|priority_)?queue|(forward_)?list|stack|(const_)?(reverse_)?iterator|(unordered_)?(multi)?(set|map)|bitset|u?(int|float)\d*)\b/,W=/\S/,X=x({keywords:[H,P,O,F,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",Q,R,B],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}), -I={};t(X,["default-code"]);t(G([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),"default-markup htm html mxml xhtml xml xsl".split(" "));t(G([["pln",/^[\s]+/, -null," \t\r\n"],["atv",/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],["pun",/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]); -t(G([],[["atv",/^[\s\S]+/]]),["uq.val"]);t(x({keywords:H,hashComments:!0,cStyleComments:!0,types:S}),"c cc cpp cxx cyc m".split(" "));t(x({keywords:"null,true,false"}),["json"]);t(x({keywords:P,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:S}),["cs"]);t(x({keywords:O,cStyleComments:!0}),["java"]);t(x({keywords:B,hashComments:!0,multiLineStrings:!0}),["bash","bsh","csh","sh"]);t(x({keywords:Q,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}),["cv","py","python"]);t(x({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END", -hashComments:!0,multiLineStrings:!0,regexLiterals:2}),["perl","pl","pm"]);t(x({keywords:R,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb","ruby"]);t(x({keywords:F,cStyleComments:!0,regexLiterals:!0}),["javascript","js","ts","typescript"]);t(x({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,throw,true,try,unless,until,when,while,yes",hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0, -regexLiterals:!0}),["coffee"]);t(G([],[["str",/^[\s\S]+/]]),["regex"]);var Y=D.PR={createSimpleLexer:G,registerLangHandler:t,sourceDecorator:x,PR_ATTRIB_NAME:"atn",PR_ATTRIB_VALUE:"atv",PR_COMMENT:"com",PR_DECLARATION:"dec",PR_KEYWORD:"kwd",PR_LITERAL:"lit",PR_NOCODE:"nocode",PR_PLAIN:"pln",PR_PUNCTUATION:"pun",PR_SOURCE:"src",PR_STRING:"str",PR_TAG:"tag",PR_TYPE:"typ",prettyPrintOne:D.prettyPrintOne=function(a,d,f){f=f||!1;d=d||null;var c=document.createElement("div");c.innerHTML="
"+a+"
"; -c=c.firstChild;f&&L(c,f,!0);M({j:d,m:f,h:c,l:1,a:null,i:null,c:null,g:null});return c.innerHTML},prettyPrint:D.prettyPrint=function(a,d){function f(){for(var c=D.PR_SHOULD_USE_CONTINUATION?b.now()+250:Infinity;p - - - - Module: term -Terminal adaptor - JSDoc - - - - -
- -
- -
-
-

Module: term -Terminal adaptor

-
- - - - -
- -
- -

term -Terminal adaptor

- - -
- -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- term.js, line 1 -
- - - - - - - -
- - - - - - -
- - - - - - - - - - - - - - - - -

Methods

- - - -
- - - - -

highlightText(src, lang) → {String}

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- term.js, line 10 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
src -
-
- - -String - - - - The code
lang -
-
- - -String - - - - The language of the code
-
- - - - - - - - - - - - - - - -
Returns:
- - -
- The highlighted string -
- - - -
-
- Type -
-
- -String - - -
-
- - - - - - -
- - -
- - - - -

printHighlight(code)

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- term.js, line 26 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
code -
-
- - -String - - - - The code
-
- - - - - - - - - - - - - - - - - - - -
- - -
- - - - -

setTheme -Change the current used theme for highlighting(name)

- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- term.js, line 34 -
- - - - - - - -
- - - - - - - - - - - -
Parameters:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
name -
-
- - -String - - - - The name of the theme
-
- - - - - - - - - - - - - - - - - - - -
- - - - - - - -
- - - - -
- -
-
- - - - - - - - \ No newline at end of file diff --git a/doc/term.js.html b/doc/term.js.html deleted file mode 100644 index e39b5e9..0000000 --- a/doc/term.js.html +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - Source: term.js - JSDoc - - - - -
- -
- -
-
-

Source: term.js

-
- - - - - -
-
/**
- * @module term
- * Terminal adaptor
-*/
-
-import { tokenize } from './index.js';
-
-let theme = import('./themes/default.js');
-
-/**
- * @function highlightText
- * @async
- * Highlight a string passed as argument and return a string that can directly be printed
- * @param {String} src The code
- * @param {String} lang The language of the code
- * @returns {String} The highlighted string
- */
-export const highlightText = async (src, lang) => {
-	let res = '', themeMap = (await theme).default;
-
-	await tokenize(src, lang, (str, token) => res += token ? `${themeMap[token] ?? ''}${str}\x1b[0m` : str);
-
-	return res;
-};
-
-/**
- * @function printHighlight
- * @async
- * Highlight and print a given string
- * @param {String} code The code
- */
-export const printHighlight = async (...arg) => console.log(await highlightText(...arg));
-
-/**
- * @function setTheme
- * Change the current used theme for highlighting
- * @param {String} name The name of the theme
- */
-export const setTheme = async name => theme = import(`./themes/${name}.js`);
-
-
- - - - - -
- -
-
- - - - - - - - diff --git a/examples/data.js b/examples/data.js index 7b8f170..3234eb8 100644 --- a/examples/data.js +++ b/examples/data.js @@ -1,6 +1,4 @@ -import '../typedef.js' - -/** @type {ShjLanguage[]} */ +/** @type {import('../src/index.js').ShjLanguage[]} */ export const languages = [ 'js', 'py', @@ -38,7 +36,7 @@ export const languages = [ 'yaml' ] -/** @type {ShjBrowserTheme[]} */ +/** @type {import('../src/index.js').ShjBrowserTheme[]} */ export const themesBrowser = [ 'default', 'atom-dark', @@ -49,7 +47,7 @@ export const themesBrowser = [ 'visual-studio-dark' ] -/** @type {ShjTerminalTheme[]} */ +/** @type {import('../src/terminal.js').ShjTerminalTheme[]} */ export const themesTerminal = [ 'default', 'atom-dark' diff --git a/examples/node.js b/examples/node-require/node.js similarity index 73% rename from examples/node.js rename to examples/node-require/node.js index 879dc49..0f52cc5 100644 --- a/examples/node.js +++ b/examples/node-require/node.js @@ -5,7 +5,7 @@ const fs = require('fs'), const lang = process.argv[2] ?? 'js'; setTheme('default').then(_ => { - const code = fs.readFileSync(path.resolve(__dirname, `./languages/test.${lang}`)); + const code = fs.readFileSync(path.resolve(__dirname, `../languages/test.${lang}`)); printHighlight(code, lang); }); \ No newline at end of file diff --git a/examples/node-require/package-lock.json b/examples/node-require/package-lock.json new file mode 100644 index 0000000..69d6464 --- /dev/null +++ b/examples/node-require/package-lock.json @@ -0,0 +1,29 @@ +{ + "name": "test", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "test", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@speed-highlight/core": "file:../.." + } + }, + "../..": { + "version": "1.2.4", + "license": "CC0-1.0", + "devDependencies": { + "@semantic-release/git": "^10.0.1", + "semantic-release": "^21.0.7", + "typescript": "^5.3.3" + } + }, + "node_modules/@speed-highlight/core": { + "resolved": "../..", + "link": true + } + } +} diff --git a/examples/node-require/package.json b/examples/node-require/package.json new file mode 100644 index 0000000..5d2c97b --- /dev/null +++ b/examples/node-require/package.json @@ -0,0 +1,13 @@ +{ + "name": "test", + "version": "1.0.0", + "description": "", + "scripts": { + "test": "node node.js" + }, + "author": "", + "license": "ISC", + "dependencies": { + "@speed-highlight/core": "file:../.." + } +} diff --git a/examples/node-ts-module/.gitignore b/examples/node-ts-module/.gitignore new file mode 100644 index 0000000..aa4a6da --- /dev/null +++ b/examples/node-ts-module/.gitignore @@ -0,0 +1,2 @@ +*.js +*.js.map \ No newline at end of file diff --git a/examples/node-ts-module/package-lock.json b/examples/node-ts-module/package-lock.json new file mode 100644 index 0000000..31827af --- /dev/null +++ b/examples/node-ts-module/package-lock.json @@ -0,0 +1,231 @@ +{ + "name": "test", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "test", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@speed-highlight/core": "file:../.." + }, + "devDependencies": { + "ts-node": "^10.9.2", + "typescript": "^5.3.3" + } + }, + "../..": { + "name": "@speed-highlight/core", + "version": "1.2.4", + "license": "CC0-1.0", + "devDependencies": { + "@semantic-release/git": "^10.0.1", + "semantic-release": "^21.0.7", + "typescript": "^5.3.3" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@speed-highlight/core": { + "resolved": "../..", + "link": true + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true + }, + "node_modules/@types/node": { + "version": "20.10.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.6.tgz", + "integrity": "sha512-Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==", + "dev": true, + "peer": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/acorn": { + "version": "8.11.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", + "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.1.tgz", + "integrity": "sha512-TgUZgYvqZprrl7YldZNoa9OciCAyZR+Ejm9eXzKCmjsF5IKp/wgQ7Z/ZpjpGTIUPwrHQIcYeI8qDh4PsEwxMbw==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dev": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true, + "peer": true + }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true + }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "engines": { + "node": ">=6" + } + } + } +} diff --git a/examples/node-ts-module/package.json b/examples/node-ts-module/package.json new file mode 100644 index 0000000..10768a4 --- /dev/null +++ b/examples/node-ts-module/package.json @@ -0,0 +1,18 @@ +{ + "name": "test", + "version": "1.0.0", + "description": "", + "scripts": { + "test": "tsc && node script.js" + }, + "author": "", + "license": "ISC", + "type": "module", + "dependencies": { + "@speed-highlight/core": "file:../.." + }, + "devDependencies": { + "ts-node": "^10.9.2", + "typescript": "^5.3.3" + } +} diff --git a/examples/node-ts-module/script.ts b/examples/node-ts-module/script.ts new file mode 100644 index 0000000..734eeed --- /dev/null +++ b/examples/node-ts-module/script.ts @@ -0,0 +1,8 @@ +import { printHighlight, setTheme, ShjLanguage } from "@speed-highlight/core/terminal"; +import { readFile } from "fs/promises"; + +const lang: ShjLanguage = process.argv[2] as ShjLanguage ?? 'js'; +const code = await readFile(`../languages/test.${lang}`, "utf-8"); + +await setTheme("default"); +await printHighlight(code, lang); diff --git a/examples/node-ts-module/tsconfig.json b/examples/node-ts-module/tsconfig.json new file mode 100644 index 0000000..3e7fe4a --- /dev/null +++ b/examples/node-ts-module/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + // "module": "ESNext", + // "target": "ESNext", + // "moduleResolution": "node", + + + "esModuleInterop": true, + "lib": ["ESNext"], + "module": "ESNext", + "preserveConstEnums": true, + "moduleResolution": "node", + "strict": true, + "sourceMap": true, + "target": "ESNext", + "types": ["node"], + }, + "include": ["script.ts"], + "exclude": ["node_modules"] +} \ No newline at end of file diff --git a/examples/worker.html b/examples/worker.html index ad53b9e..26a67c0 100644 --- a/examples/worker.html +++ b/examples/worker.html @@ -8,8 +8,7 @@
this.code = 'highlighted on a web worker'; -this.isAwesome = new Boolean(.5); -this.doesNotWorkOnFirefox = '💩'
+this.isAwesome = new Boolean(.5);