/
index.ts
149 lines (128 loc) · 3.94 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import MarkdownIt = require('markdown-it/lib');
import ParserInline = require('markdown-it/lib/parser_inline');
import ParserBlock = require('markdown-it/lib/parser_block');
import ParserCore = require('markdown-it/lib/parser_core');
import Renderer = require('markdown-it/lib/renderer');
import LinkifyIt = require('linkify-it');
{
const md = new MarkdownIt();
let options: MarkdownIt.Options;
// all empty
options = {};
// Commonmark
options = {
html: true,
xhtmlOut: true,
breaks: false,
langPrefix: 'language-',
linkify: false,
typographer: false,
quotes: '\u201c\u201d\u2018\u2019' /* “”‘’ */,
highlight: null,
};
// Zero
options = {
html: false,
xhtmlOut: false,
breaks: false,
langPrefix: 'language-',
linkify: false,
typographer: false,
quotes: '\u201c\u201d\u2018\u2019' /* “”‘’ */,
highlight: null,
};
// default
options = {
html: false,
xhtmlOut: false,
breaks: false,
langPrefix: 'language-',
linkify: false,
typographer: false,
quotes: '\u201c\u201d\u2018\u2019' /* “”‘’ */,
highlight: null,
};
// highlight
options = {
html: false,
xhtmlOut: false,
breaks: false,
langPrefix: 'language-',
linkify: false,
typographer: false,
quotes: '\u201c\u201d\u2018\u2019' /* “”‘’ */,
highlight: function(str, lang, attrs) { return ""; },
};
}
{
const md = new MarkdownIt();
const inline: ParserInline = md.inline;
const block: ParserBlock = md.block;
const core: ParserCore = md.core;
const renderer: Renderer = md.renderer;
const linkify: LinkifyIt.LinkifyIt = md.linkify;
const options: MarkdownIt.Options = md.options;
}
{
const md = MarkdownIt()
.set({ html: true, breaks: true })
.set({ typographer: true });
}
{
const md = MarkdownIt()
.configure('default')
.configure('zero')
.configure('commonmark');
}
{
const md = MarkdownIt()
.enable(['sub', 'sup'])
.enable(['sub', 'sup'], true)
.disable(['sub', 'sup'])
.disable(['sub', 'sup'], true)
.enable('smartquotes')
.enable('smartquotes', true)
.disable('smartquotes')
.disable('smartquotes', true);
}
{
// Test plugin generic types
const plugin: MarkdownIt.PluginSimple = (md: MarkdownIt) => {};
const plugin1 = (md: MarkdownIt, param?: boolean) => {};
const plugin2 = (md: MarkdownIt, param1?: string, param2?: number) => {};
const plugin3 = (md: MarkdownIt, ...params: any[]) => {};
const plugin4: MarkdownIt.PluginWithOptions<{ foo: boolean; bar: number }> = (md, options) => {};
const plugin5: MarkdownIt.PluginWithParams = (md, flag?: boolean, str?: string, num?: number) => {};
const md = MarkdownIt()
.use(plugin)
.use(plugin, 'foobar')
.use(plugin1, false)
.use(plugin2, 'foobar', 123)
.use(plugin3, {})
.use(plugin4)
.use(plugin4, { foo: true, bar: 123 })
.use(plugin5)
.use(plugin5, true, 'foobar', 123);
}
{
const md = new MarkdownIt();
const flag: boolean = md.validateLink('https://github.com/');
const link: string = md.normalizeLink('https://github.com/');
const text: string = md.normalizeLinkText('http://host/');
}
{
const md = new MarkdownIt();
let result: string;
result = md.render('# Foobar');
result = md.render('# Foobar', {});
const tokens = md.parse('# Foobar', {});
result = md.renderer.render(tokens, md.options, {});
}
{
const md = new MarkdownIt();
let result: string;
result = md.renderInline('__foobar__');
result = md.renderInline('__foobar__', {});
const tokens = md.parseInline('__foobar__', {});
result = md.renderer.renderInline(tokens, md.options, {});
}