mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-18 12:33:17 +08:00
Adding Definitions for Kramed (#14462)
* Definitions for Kramed * Fixed tslint errors * Fixed exports after fixing tslint export warning
This commit is contained in:
committed by
Mohamed Hegazy
parent
489156cadf
commit
e4aa39ef69
160
kramed/index.d.ts
vendored
Normal file
160
kramed/index.d.ts
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
// Type definitions for Kramed 0.5
|
||||
// Project: https://github.com/GitbookIO/kramed
|
||||
// Definitions by: Matthew Wilkes <https://github.com/tonicblue>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export interface KramedStatic {
|
||||
/**
|
||||
* Compiles kramdown to HTML.
|
||||
*
|
||||
* @param src String of kramdown source to be compiled
|
||||
* @param callback Function called when the kramdownString has been fully parsed when using async highlighting
|
||||
* @return String of compiled HTML
|
||||
*/
|
||||
(src: string, callback: () => void): string;
|
||||
|
||||
/**
|
||||
* Compiles kramdown to HTML.
|
||||
*
|
||||
* @param src String of kramdown source to be compiled
|
||||
* @param options Hash of options
|
||||
* @param callback Function called when the kramdownString has been fully parsed when using async highlighting
|
||||
* @return String of compiled HTML
|
||||
*/
|
||||
(src: string, options?: KramedOptions, callback?: () => void): string;
|
||||
|
||||
/**
|
||||
* @param src String of kramdown source to be compiled
|
||||
* @param options Hash of options
|
||||
*/
|
||||
lexer(src: string, options?: KramedOptions): any[];
|
||||
|
||||
/**
|
||||
* Compiles kramdown to HTML.
|
||||
*
|
||||
* @param src String of kramdown source to be compiled
|
||||
* @param callback Function called when the kramdownString has been fully parsed when using async highlighting
|
||||
* @return String of compiled HTML
|
||||
*/
|
||||
parse(src: string, callback: () => void): string;
|
||||
|
||||
/**
|
||||
* Compiles kramdown to HTML.
|
||||
*
|
||||
* @param src String of kramdown source to be compiled
|
||||
* @param options Hash of options
|
||||
* @param callback Function called when the kramdownString has been fully parsed when using async highlighting
|
||||
* @return String of compiled HTML
|
||||
*/
|
||||
parse(src: string, options?: KramedOptions, callback?: () => void): string;
|
||||
|
||||
/**
|
||||
* @param options Hash of options
|
||||
*/
|
||||
parser(src: any[], options?: KramedOptions): string;
|
||||
|
||||
/**
|
||||
* Sets the default options.
|
||||
*
|
||||
* @param options Hash of options
|
||||
*/
|
||||
setOptions(options: KramedOptions): KramedStatic;
|
||||
|
||||
Renderer: {
|
||||
new(): KramedRenderer;
|
||||
};
|
||||
|
||||
Parser: {
|
||||
new(options: KramedOptions): KramedParser;
|
||||
};
|
||||
}
|
||||
|
||||
export interface KramedRenderer {
|
||||
code(code: string, language: string): string;
|
||||
blockquote(quote: string): string;
|
||||
html(html: string): string;
|
||||
heading(text: string, level: number, raw: string): string;
|
||||
hr(): string;
|
||||
list(body: string, ordered: boolean): string;
|
||||
listitem(text: string): string;
|
||||
paragraph(text: string): string;
|
||||
table(header: string, body: string): string;
|
||||
tablerow(content: string): string;
|
||||
tablecell(content: string, flags: {
|
||||
header: boolean,
|
||||
align: string
|
||||
}): string;
|
||||
strong(text: string): string;
|
||||
em(text: string): string;
|
||||
codespan(code: string): string;
|
||||
br(): string;
|
||||
del(text: string): string;
|
||||
link(href: string, title: string, text: string): string;
|
||||
image(href: string, title: string, text: string): string;
|
||||
text(text: string): string;
|
||||
}
|
||||
|
||||
export interface KramedParser {
|
||||
parse(source: any[]): string;
|
||||
}
|
||||
|
||||
export interface KramedOptions {
|
||||
/**
|
||||
* Type: object Default: new Renderer()
|
||||
*
|
||||
* An object containing functions to render tokens to HTML.
|
||||
*/
|
||||
renderer?: KramedRenderer;
|
||||
|
||||
/**
|
||||
* Enable GitHub flavored kramdown.
|
||||
*/
|
||||
gfm?: boolean;
|
||||
|
||||
/**
|
||||
* Enable GFM tables. This option requires the gfm option to be true.
|
||||
*/
|
||||
tables?: boolean;
|
||||
|
||||
/**
|
||||
* Enable GFM line breaks. This option requires the gfm option to be true.
|
||||
*/
|
||||
breaks?: boolean;
|
||||
|
||||
/**
|
||||
* Conform to obscure parts of kramdown.pl as much as possible. Don't fix any of the original kramdown bugs or poor behavior.
|
||||
*/
|
||||
pedantic?: boolean;
|
||||
|
||||
/**
|
||||
* Sanitize the output. Ignore any HTML that has been input.
|
||||
*/
|
||||
sanitize?: boolean;
|
||||
|
||||
/**
|
||||
* Use smarter list behavior than the original kramdown. May eventually be default with the old behavior moved into pedantic.
|
||||
*/
|
||||
smartLists?: boolean;
|
||||
|
||||
/**
|
||||
* Shows an HTML error message when rendering fails.
|
||||
*/
|
||||
silent?: boolean;
|
||||
|
||||
/**
|
||||
* A function to highlight code blocks. The function takes three arguments: code, lang, and callback.
|
||||
*/
|
||||
highlight?(code: string, lang: string, callback?: () => void): string;
|
||||
|
||||
/**
|
||||
* Set the prefix for code block classes.
|
||||
*/
|
||||
langPrefix?: string;
|
||||
|
||||
/**
|
||||
* Use "smart" typograhic punctuation for things like quotes and dashes.
|
||||
*/
|
||||
smartypants?: boolean;
|
||||
}
|
||||
|
||||
export declare var kramed: KramedStatic;
|
||||
43
kramed/kramed-tests.ts
Normal file
43
kramed/kramed-tests.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
import { KramedOptions, kramed, KramedParser, KramedStatic, KramedRenderer } from 'kramed';
|
||||
|
||||
var options: KramedOptions = {
|
||||
gfm: true,
|
||||
tables: true,
|
||||
breaks: false,
|
||||
pedantic: false,
|
||||
sanitize: true,
|
||||
smartLists: true,
|
||||
silent: false,
|
||||
highlight: function (code: string, lang: string) {
|
||||
return '';
|
||||
},
|
||||
langPrefix: 'lang-',
|
||||
smartypants: false,
|
||||
renderer: new kramed.Renderer()
|
||||
};
|
||||
|
||||
function callback() {
|
||||
console.log('callback called');
|
||||
}
|
||||
|
||||
kramed.setOptions(options);
|
||||
|
||||
console.log(kramed('i am using __kramdown__.'));
|
||||
console.log(kramed('i am using __kramdown__.', options));
|
||||
console.log(kramed('i am using __kramdown__.', callback));
|
||||
console.log(kramed('i am using __kramdown__.', options, callback));
|
||||
|
||||
console.log(kramed.parse('i am using __kramdown__.'));
|
||||
console.log(kramed.parse('i am using __kramdown__.', options));
|
||||
console.log(kramed.parse('i am using __kramdown__.', callback));
|
||||
console.log(kramed.parse('i am using __kramdown__.', options, callback));
|
||||
|
||||
var text = 'something';
|
||||
var tokens = kramed.lexer(text, options);
|
||||
console.log(kramed.parser(tokens));
|
||||
|
||||
var renderer = new kramed.Renderer();
|
||||
renderer.heading = function(text, level, raw) {
|
||||
return text + level.toString() + raw;
|
||||
};
|
||||
20
kramed/tsconfig.json
Normal file
20
kramed/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"kramed-tests.ts"
|
||||
]
|
||||
}
|
||||
1
kramed/tslint.json
Normal file
1
kramed/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user