Merge pull request #274 from rtfpessoa/improve-highlightjs-types
clean: Improve highlight.js types
This commit is contained in:
commit
db48e96dca
4 changed files with 47 additions and 83 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { HighlightJS, ICompiledMode, IHighlightResult, IAutoHighlightResult } from './highlight.js-interface';
|
||||
import { HighlightJS } from 'highlight.js/lib/highlight.js';
|
||||
import { ICompiledMode, IHighlightResult, IAutoHighlightResult } from 'highlight.js';
|
||||
import { nodeStream, mergeStreams } from './highlight.js-helpers';
|
||||
|
||||
import { html, Diff2HtmlConfig, defaultDiff2HtmlConfig } from '../../diff2html';
|
||||
|
|
|
|||
|
|
@ -1,69 +0,0 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
/* eslint-disable @typescript-eslint/interface-name-prefix */
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
|
||||
export interface HighlightJS {
|
||||
highlight(name: string, value: string, ignore_illegals?: boolean, continuation?: ICompiledMode): IHighlightResult;
|
||||
|
||||
highlightAuto(value: string, languageSubset?: string[]): IAutoHighlightResult;
|
||||
|
||||
getLanguage(name: string): IMode;
|
||||
}
|
||||
|
||||
export interface IAutoHighlightResult extends IHighlightResultBase {
|
||||
second_best?: IAutoHighlightResult;
|
||||
}
|
||||
|
||||
export interface IHighlightResultBase {
|
||||
relevance: number;
|
||||
language: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface IHighlightResult extends IHighlightResultBase {
|
||||
top: ICompiledMode;
|
||||
}
|
||||
|
||||
export interface IMode extends IModeBase {
|
||||
keywords?: any;
|
||||
contains?: IMode[];
|
||||
}
|
||||
|
||||
// Reference:
|
||||
// https://github.com/isagalaev/highlight.js/blob/master/docs/reference.rst
|
||||
export interface IModeBase {
|
||||
className?: string;
|
||||
aliases?: string[];
|
||||
begin?: string | RegExp;
|
||||
end?: string | RegExp;
|
||||
case_insensitive?: boolean;
|
||||
beginKeyword?: string;
|
||||
endsWithParent?: boolean;
|
||||
lexems?: string;
|
||||
illegal?: string;
|
||||
excludeBegin?: boolean;
|
||||
excludeEnd?: boolean;
|
||||
returnBegin?: boolean;
|
||||
returnEnd?: boolean;
|
||||
starts?: string;
|
||||
subLanguage?: string;
|
||||
subLanguageMode?: string;
|
||||
relevance?: number;
|
||||
variants?: IMode[];
|
||||
}
|
||||
|
||||
export interface ICompiledMode extends IModeBase {
|
||||
compiled: boolean;
|
||||
contains?: ICompiledMode[];
|
||||
keywords?: Object;
|
||||
terminators: RegExp;
|
||||
terminator_end?: string;
|
||||
}
|
||||
|
||||
export interface IOptions {
|
||||
classPrefix?: string;
|
||||
tabReplace?: string;
|
||||
useBR?: boolean;
|
||||
languages?: string[];
|
||||
}
|
||||
|
|
@ -1,18 +1,8 @@
|
|||
import { HighlightJS } from './highlight.js-interface';
|
||||
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
/* eslint-disable @typescript-eslint/interface-name-prefix */
|
||||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
/*
|
||||
* Adapted Highlight.js External APIs
|
||||
* Used to avoid importing all the languages
|
||||
*/
|
||||
|
||||
// Require the highlight.js library without languages
|
||||
const highlightJS = require('highlight.js/lib/highlight.js');
|
||||
import highlightJS from 'highlight.js/lib/highlight.js';
|
||||
|
||||
// Separately require languages
|
||||
// highlightJS.registerLanguage('1c', require('highlight.js/lib/languages/1c'));
|
||||
// highlightJS.registerLanguage('abnf', require('highlight.js/lib/languages/abnf'));
|
||||
|
|
@ -200,4 +190,4 @@ highlightJS.registerLanguage('vim', require('highlight.js/lib/languages/vim'));
|
|||
// highlightJS.registerLanguage('xquery', require('highlight.js/lib/languages/xquery'));
|
||||
// highlightJS.registerLanguage('zephir', require('highlight.js/lib/languages/zephir'));
|
||||
|
||||
export const hljs: HighlightJS = highlightJS as HighlightJS;
|
||||
export const hljs = highlightJS;
|
||||
|
|
|
|||
42
typings/highlight.js.d.ts
vendored
Normal file
42
typings/highlight.js.d.ts
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
declare module 'highlight.js/lib/highlight.js' {
|
||||
import hljs from 'highlight.js';
|
||||
|
||||
export type HighlightJS = typeof hljs;
|
||||
|
||||
export default hljs;
|
||||
|
||||
export const highlight: typeof hljs.highlight;
|
||||
export const highlightAuto: typeof hljs.highlightAuto;
|
||||
export const fixMarkup: typeof hljs.fixMarkup;
|
||||
export const highlightBlock: typeof hljs.highlightBlock;
|
||||
export const configure: typeof hljs.configure;
|
||||
export const initHighlighting: typeof hljs.initHighlighting;
|
||||
export const initHighlightingOnLoad: typeof hljs.initHighlightingOnLoad;
|
||||
export const registerLanguage: typeof hljs.registerLanguage;
|
||||
export const listLanguages: typeof hljs.listLanguages;
|
||||
export const getLanguage: typeof hljs.getLanguage;
|
||||
export const inherit: typeof hljs.inherit;
|
||||
export const COMMENT: typeof hljs.COMMENT;
|
||||
|
||||
export const IDENT_RE: typeof hljs.IDENT_RE;
|
||||
export const UNDERSCORE_IDENT_RE: typeof hljs.UNDERSCORE_IDENT_RE;
|
||||
export const NUMBER_RE: typeof hljs.NUMBER_RE;
|
||||
export const C_NUMBER_RE: typeof hljs.C_NUMBER_RE;
|
||||
export const BINARY_NUMBER_RE: typeof hljs.BINARY_NUMBER_RE;
|
||||
export const RE_STARTERS_RE: typeof hljs.RE_STARTERS_RE;
|
||||
|
||||
export const BACKSLASH_ESCAPE: typeof hljs.BACKSLASH_ESCAPE;
|
||||
export const APOS_STRING_MODE: typeof hljs.APOS_STRING_MODE;
|
||||
export const QUOTE_STRING_MODE: typeof hljs.QUOTE_STRING_MODE;
|
||||
export const PHRASAL_WORDS_MODE: typeof hljs.PHRASAL_WORDS_MODE;
|
||||
export const C_LINE_COMMENT_MODE: typeof hljs.C_LINE_COMMENT_MODE;
|
||||
export const C_BLOCK_COMMENT_MODE: typeof hljs.C_BLOCK_COMMENT_MODE;
|
||||
export const HASH_COMMENT_MODE: typeof hljs.HASH_COMMENT_MODE;
|
||||
export const NUMBER_MODE: typeof hljs.NUMBER_MODE;
|
||||
export const C_NUMBER_MODE: typeof hljs.C_NUMBER_MODE;
|
||||
export const BINARY_NUMBER_MODE: typeof hljs.BINARY_NUMBER_MODE;
|
||||
export const CSS_NUMBER_MODE: typeof hljs.CSS_NUMBER_MODE;
|
||||
export const REGEX_MODE: typeof hljs.REGEX_MODE;
|
||||
export const TITLE_MODE: typeof hljs.TITLE_MODE;
|
||||
export const UNDERSCORE_TITLE_MODE: typeof hljs.UNDERSCORE_TITLE_MODE;
|
||||
}
|
||||
Loading…
Reference in a new issue