diff --git a/types/marked-terminal/index.d.ts b/types/marked-terminal/index.d.ts new file mode 100644 index 0000000000..30e4b8fe38 --- /dev/null +++ b/types/marked-terminal/index.d.ts @@ -0,0 +1,58 @@ +// Type definitions for marked-terminal 3.1 +// Project: https://github.com/mikaelbr/marked-terminal +// Definitions by: Bryan Kendall +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Chalk } from 'chalk'; +import { Renderer } from 'marked'; + +export as namespace TerminalRenderer; + +export = TerminalRenderer; + +declare class TerminalRenderer extends Renderer { + constructor(options?: TerminalRenderer.TerminalRendererOptions) +} + +declare namespace TerminalRenderer { + interface TerminalRendererOptions { + code?: Chalk | ((s: string) => string); + blockquote?: Chalk | ((s: string) => string); + html?: Chalk | ((s: string) => string); + heading?: Chalk | ((s: string) => string); + firstHeading?: Chalk | ((s: string) => string); + hr?: Chalk | ((s: string) => string); + listitem?: Chalk | ((s: string) => string); + table?: Chalk | ((s: string) => string); + paragraph?: Chalk | ((s: string) => string); + strong?: Chalk | ((s: string) => string); + em?: Chalk | ((s: string) => string); + codespan?: Chalk | ((s: string) => string); + del?: Chalk | ((s: string) => string); + link?: Chalk | ((s: string) => string); + href?: Chalk | ((s: string) => string); + + // Formats the bulletpoints and numbers for lists + list?: (body: string, ordered?: boolean) => string; + + // Reflow and print-out width + width?: number; // only applicable when reflow is true + reflowText?: boolean; + + // Should it prefix headers? + showSectionPrefix?: boolean; + + // Whether or not to undo marked escaping + // of enitities (" -> " etc) + unescape?: boolean; + + // Whether or not to show emojis + emoji?: boolean; + + // Options passed to cli-table + tableOptions?: any; + + // The size of tabs in number of spaces or as tab characters + tab?: number; + } +} diff --git a/types/marked-terminal/marked-terminal-tests.ts b/types/marked-terminal/marked-terminal-tests.ts new file mode 100644 index 0000000000..230dfa1adc --- /dev/null +++ b/types/marked-terminal/marked-terminal-tests.ts @@ -0,0 +1,29 @@ +import * as marked from 'marked'; +import * as TerminalRenderer from 'marked-terminal'; +import chalk from 'chalk'; + +marked.setOptions({ + // Define custom renderer + renderer: new TerminalRenderer() +}); + +marked.setOptions({ + // Define custom renderer + renderer: new TerminalRenderer({ + // Change style for code + codespan: chalk.underline.magenta, + // Can also override color/styling by own functions. + firstHeading: (text: string) => `*** ${text}` + }) +}); + +marked.setOptions({ + // Define custom renderer + renderer: new TerminalRenderer({ + reflowText: true, + width: 60 + }) +}); + +// Show the parsed data +console.log(marked('# a basic string\nwith stuff')); diff --git a/types/marked-terminal/tsconfig.json b/types/marked-terminal/tsconfig.json new file mode 100644 index 0000000000..77a046fc31 --- /dev/null +++ b/types/marked-terminal/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "marked-terminal-tests.ts" + ] +} diff --git a/types/marked-terminal/tslint.json b/types/marked-terminal/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/marked-terminal/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }