diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 815d84b27..8dfb91f02 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -129,7 +129,7 @@ All definitions files include a header with the author and editors, so at some p * [HelloJS](http://adodson.com/hello.js) (by [Pavel Zika](https://github.com/PavelPZ)) * [Highcharts](http://www.highcharts.com/) (by [damianog](https://github.com/damianog)) * [Highland](http://highlandjs.org/) (by [Bart van der Schoor](https://github.com/Bartvds/)) -* [highlight.js](https://github.com/isagalaev/highlight.js) (by [Niklas Mollenhauer](https://github.com/nikeee)) +* [highlight.js](https://github.com/isagalaev/highlight.js) (by [Niklas Mollenhauer](https://github.com/nikeee) and [Jeremy Hull](https://github.com/sourrust)) * [History.js](https://github.com/browserstate/history.js) (by [Boris Yankov](https://github.com/borisyankov)) * [Html2Canvas.js](https://github.com/niklasvh/html2canvas/) (by [Richard Hepburn](https://github.com/rwhepburn)) * [htmlparser2](https://github.com/fb55/htmlparser2/) (by [James Roland Cabresos](https://github.com/staticfunction)) diff --git a/highlightjs/highlightjs-7.5.0.d.ts b/highlightjs/highlightjs-7.5.0.d.ts new file mode 100644 index 000000000..725f78fbc --- /dev/null +++ b/highlightjs/highlightjs-7.5.0.d.ts @@ -0,0 +1,82 @@ +// Type definitions for highlight.js v7.5.0 +// Project: https://github.com/isagalaev/highlight.js +// Definitions by: Niklas Mollenhauer +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "highlight.js" +{ + module hljs + { + export var LANGUAGES: { [name: string] : any; }; + + export function blockText(block: Node, ignoreNewLines: boolean) : string; + export function blockLanguage(block: Node) : string; + + export function highlight(language_name: string, value: string) : IHighlightResult + export function highlightAuto(text: string) : IHighlightResult + + export function fixMarkup(value: string, tabReplace: boolean, useBR: boolean) : string; + + export function highlightBlock(block: Node, tabReplace?: boolean, useBR?: boolean) : void; + + export function initHighlighting(): void; + export function initHighlightingOnLoad(): void; + + export var tabReplace : string; + + // Common regexps + export var IDENT_RE: string; + export var UNDERSCORE_IDENT_RE: string; + export var NUMBER_RE: string; + export var C_NUMBER_RE: string; + export var BINARY_NUMBER_RE: string; + export var RE_STARTERS_RE: string; + + // Common modes + export var BACKSLASH_ESCAPE : IMode; + export var APOS_STRING_MODE : IMode; + export var QUOTE_STRING_MODE : IMode; + export var C_LINE_COMMENT_MODE : IMode; + export var C_BLOCK_COMMENT_MODE : IMode; + export var HASH_COMMENT_MODE : IMode; + export var NUMBER_MODE : IMode; + export var C_NUMBER_MODE : IMode; + export var BINARY_NUMBER_MODE : IMode; + + export interface IHighlightResult + { + relevance: number; + keyword_count: number; + value: string; + } + + export interface IAutoHighlightResult extends IHighlightResult + { + language: string; + second_best?: IAutoHighlightResult; + } + + // Reference: + // https://github.com/isagalaev/highlight.js/blob/master/docs/reference.rst + export interface IMode + { + className?: string; + begin: string; + end?: string; + beginWithKeyword?: boolean; + endsWithParent?: boolean; + lexems?: string; + keywords?: Object; + illegal?: string; + excludeBegin?: boolean; + excludeEnd?: boolean; + returnBegin?: boolean; + returnEnd?: boolean; + contains?: IMode[]; + starts?: string; + subLanguage?: string; + relevance?: number; + } + } + export = hljs; +} diff --git a/highlightjs/highlightjs-tests.ts b/highlightjs/highlightjs-tests.ts index 749be67cc..233d1fa3e 100644 --- a/highlightjs/highlightjs-tests.ts +++ b/highlightjs/highlightjs-tests.ts @@ -12,7 +12,7 @@ import hljs = require("highlight.js"); var code = "using System;\npublic class Test\n{\npublic static void Main()\n{\n// your code goes here\n}\n}"; var lang = "cs"; -hljs.tabReplace = " "; // 4 spaces +hljs.configure({ tabReplace: " " }); // 4 spaces var hl = hljs.highlight(lang, code).value; -hl = hljs.highlightAuto(code).value; \ No newline at end of file +hl = hljs.highlightAuto(code).value; diff --git a/highlightjs/highlightjs.d.ts b/highlightjs/highlightjs.d.ts index d730029b5..dc7606d88 100644 --- a/highlightjs/highlightjs.d.ts +++ b/highlightjs/highlightjs.d.ts @@ -1,28 +1,37 @@ -// Type definitions for highlight.js +// Type definitions for highlight.js v8.2.0 // Project: https://github.com/isagalaev/highlight.js -// Definitions by: Niklas Mollenhauer +// Definitions by: Niklas Mollenhauer , Jeremy Hull // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module "highlight.js" { module hljs { - export var LANGUAGES: { [name: string] : any; }; + export function highlight( + name: string, + value: string, + ignore_illegals?: boolean, + continuation?: boolean) : IHighlightResult; + export function highlightAuto( + value: string, + languageSubset?: string[]) : IAutoHighlightResult; - export function blockText(block: Node, ignoreNewLines: boolean) : string; - export function blockLanguage(block: Node) : string; + export function fixMarkup(value: string) : string; - export function highlight(language_name: string, value: string) : IHighlightResult - export function highlightAuto(text: string) : IHighlightResult + export function highlightBlock(block: Node) : void; - export function fixMarkup(value: string, tabReplace: boolean, useBR: boolean) : string; + export function configure(options: IOptions): void; - export function highlightBlock(block: Node, tabReplace?: boolean, useBR?: boolean) : void; - export function initHighlighting(): void; export function initHighlightingOnLoad(): void; - export var tabReplace : string; + export function registerLanguage( + name: string, + language: (hljs?: HLJSStatic) => IModeBase): void; + export function listLanguages(): string[]; + export function getLanguage(name: string): IMode; + + export function inherit(parent: Object, obj: Object): Object; // Common regexps export var IDENT_RE: string; @@ -36,46 +45,109 @@ declare module "highlight.js" export var BACKSLASH_ESCAPE : IMode; export var APOS_STRING_MODE : IMode; export var QUOTE_STRING_MODE : IMode; + export var PHRASAL_WORDS_MODE : IMode; export var C_LINE_COMMENT_MODE : IMode; export var C_BLOCK_COMMENT_MODE : IMode; export var HASH_COMMENT_MODE : IMode; export var NUMBER_MODE : IMode; export var C_NUMBER_MODE : IMode; export var BINARY_NUMBER_MODE : IMode; + export var CSS_NUMBER_MODE : IMode; + export var REGEX_MODE : IMode; + export var TITLE_MODE : IMode; + export var UNDERSCORE_TITLE_MODE : IMode; - export interface IHighlightResult + export interface IHighlightResultBase { relevance: number; - keyword_count: number; + language: string; value: string; } - export interface IAutoHighlightResult extends IHighlightResult + export interface IAutoHighlightResult extends IHighlightResultBase { - language: string; second_best?: IAutoHighlightResult; } + export interface IHighlightResult extends IHighlightResultBase + { + top: ICompiledMode; + } + + export interface HLJSStatic + { + inherit(parent: Object, obj: Object): Object; + + // Common regexps + IDENT_RE: string; + UNDERSCORE_IDENT_RE: string; + NUMBER_RE: string; + C_NUMBER_RE: string; + BINARY_NUMBER_RE: string; + RE_STARTERS_RE: string; + + // Common modes + BACKSLASH_ESCAPE : IMode; + APOS_STRING_MODE : IMode; + QUOTE_STRING_MODE : IMode; + PHRASAL_WORDS_MODE : IMode; + C_LINE_COMMENT_MODE : IMode; + C_BLOCK_COMMENT_MODE : IMode; + HASH_COMMENT_MODE : IMode; + NUMBER_MODE : IMode; + C_NUMBER_MODE : IMode; + BINARY_NUMBER_MODE : IMode; + CSS_NUMBER_MODE : IMode; + REGEX_MODE : IMode; + TITLE_MODE : IMode; + UNDERSCORE_TITLE_MODE : IMode; + } + // Reference: // https://github.com/isagalaev/highlight.js/blob/master/docs/reference.rst - export interface IMode + export interface IModeBase { className?: string; - begin: string; + aliases?: string[]; + begin?: string; end?: string; - beginWithKeyword?: boolean; + case_insensitive?: boolean; + beginKeyword?: string; endsWithParent?: boolean; lexems?: string; - keywords?: Object; illegal?: string; excludeBegin?: boolean; excludeEnd?: boolean; returnBegin?: boolean; returnEnd?: boolean; - contains?: IMode[]; starts?: string; subLanguage?: string; + subLanguageMode?: string; relevance?: number; + variants?: IMode[]; + } + + export interface IMode extends IModeBase + { + keywords?: any; + contains?: 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[]; } } export = hljs;