-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
7,383 additions
and
12,800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: Release | ||
|
||
"on": | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<import('.').ShjLanguage> | ||
export function detectLanguage(code: string): ShjLanguage; | ||
export type ShjLanguage = import('./index.js').ShjLanguage; | ||
//# sourceMappingURL=detect.d.ts.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> }> | ||
}); | ||
}; | ||
|
||
export type ShjLanguageDefinition = Array<ShjLanguageComponent>; | ||
|
||
/////////// 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<T extends string = ShjLanguage>( | ||
src: string, | ||
lang: T, | ||
callback: (value: string, token: ShjToken) => void | ||
): Promise<void>; | ||
|
||
export function tokenize(src: string, lang: ShjLanguage | any[], token: (arg0: string, arg1: ShjToken | undefined) => void): Promise<void>; | ||
/** | ||
* 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<String>} The highlighted string | ||
*/ | ||
export declare function highlightText<T extends string = ShjLanguage>( | ||
src: string, | ||
lang: T, | ||
multiline?: boolean, | ||
opt?: ShjOptions | ||
): Promise<string>; | ||
|
||
export function highlightText(src: string, lang: ShjLanguage, multiline?: boolean, opt?: ShjOptions): Promise<string>; | ||
/** | ||
* 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<void>; | ||
export function highlightAll(opt?: ShjOptions): Promise<any>; | ||
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<T extends string = ShjLanguage>( | ||
elm: Element, | ||
lang?: T, | ||
mode?: ShjDisplayMode, | ||
opt?: ShjOptions | ||
): Promise<void>; | ||
|
||
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<void>; | ||
|
||
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<import('.').ShjLanguage> | ||
export function detectLanguage(code: string): ShjLanguage; | ||
export type ShjLanguage = import('./index.js').ShjLanguage; | ||
//# sourceMappingURL=detect.d.ts.map |
Oops, something went wrong.