add typings for marked-terminal

This commit is contained in:
Bryan Kendall
2018-12-14 09:47:35 -08:00
parent d79ae8bfd3
commit 9117ae70c8
4 changed files with 112 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
// Type definitions for marked-terminal 3.1
// Project: https://github.com/mikaelbr/marked-terminal
// Definitions by: Bryan Kendall <https://github.com/bkendall>
// 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 (" -> &quot; 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;
}
}
@@ -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'));
+24
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }