forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
showdown.d.ts
332 lines (288 loc) · 9.29 KB
/
showdown.d.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// Type definitions for Showdown 1.4.1
// Project: https://github.com/coreyti/showdown
// Definitions by: cbowdon <https://github.com/cbowdon>, Pei-Tang Huang <https://github.com/tan9/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace Showdown {
interface Extension {
/**
* Property defines the nature of said sub-extensions and can assume 2 values:
*
* * `lang` - Language extensions add new markdown syntax to showdown.
* * `output` - Output extensions (or modifiers) alter the HTML output generated by showdown
*/
type: string;
}
/**
* Regex/replace style extensions are very similar to javascript's string.replace function.
* Two properties are given, `regex` and `replace`.
*/
interface RegexReplaceExtension extends Extension {
/**
* Should be either a string or a RegExp object.
*
* Keep in mind that, if a string is used, it will automatically be given a g modifier,
* that is, it is assumed to be a global replacement.
*/
regex?: string | RegExp;
/**
* Can be either a string or a function. If replace is a string,
* it can use the $1 syntax for group substitution,
* exactly as if it were making use of string.replace (internally it does this actually).
*/
replace?: any; // string | Replace
}
/**
* If you'd just like to do everything yourself,you can specify a filter property.
* The filter property should be a function that acts as a callback.
*/
interface FilterExtension extends Extension {
filter?: (text: string, converter: Converter, options?: ConverterOptions) => string;
}
/**
* Defines a plugin/extension
* Each single extension can be one of two types:
*
* + Language Extension -- Language extensions are ones that that add new markdown syntax to showdown. For example, say you wanted ^^youtube http://www.youtube.com/watch?v=oHg5SJYRHA0 to automatically render as an embedded YouTube video, that would be a language extension.
* + Output Modifiers -- After showdown has run, and generated HTML, an output modifier would change that HTML. For example, say you wanted to change <div class="header"> to be <header>, that would be an output modifier.
*
* Each extension can provide two combinations of interfaces for showdown.
*/
interface ShowdownExtension extends RegexReplaceExtension, FilterExtension {
}
interface ConverterExtensions {
language: ShowdownExtension[];
output: ShowdownExtension[];
}
interface ShowdownOptions {
/**
* Omit the trailing newline in a code block. Ex:
*
* This:
* <code><pre>var foo = 'bar';
* </pre></code>
*
* Becomes this:
* <code><pre>var foo = 'bar';</pre></code>
*
* @default false
*/
omitExtraWLInCodeBlocks?: boolean;
/**
* Disable the automatic generation of header ids. Setting to true overrides <strong>prefixHeaderId</strong>.
*
* @default false
*/
noHeaderId?: boolean;
/**
* Add a prefix to the generated header ids.
* Passing a string will prefix that string to the header id.
* Setting to true will add a generic 'section' prefix.
*
* @default false
*/
prefixHeaderId?: string | boolean;
/**
* Enable support for setting image dimensions from within markdown syntax.
* Examples:
*
* ![foo](foo.jpg =100x80) simple, assumes units are in px
* ![bar](bar.jpg =100x*) sets the height to "auto"
* ![baz](baz.jpg =80%x5em) Image with width of 80% and height of 5em
*
* @default false
*/
parseImgDimensions?: boolean;
/**
* Set the header starting level. For instance, setting this to 3 means that
*
* # foo
*
* will be parsed as
*
* <h3>foo</h3>
*
* @default 1
*/
headerLevelStart?: number;
/**
* Turning this on will stop showdown from interpreting underscores in the middle of
* words as <em> and <strong> and instead treat them as literal underscores.
*
* Example:
*
* some text with__underscores__in middle
*
* will be parsed as
*
* <p>some text with__underscores__in middle</p>
*
* @default false
*/
literalMidWordUnderscores?: boolean;
/**
* Enable support for strikethrough syntax.
* `~~strikethrough~~` as `<del>strikethrough</del>`.
*
* @default false
*/
strikethrough?: boolean;
/**
* Enable support for tables syntax. Example:
*
* | h1 | h2 | h3 |
* |:------|:-------:|--------:|
* | 100 | [a][1] | ![b][2] |
* | *foo* | **bar** | ~~baz~~ |
*
* See the wiki for more info
*
* @default false
*/
tables?: boolean;
/**
* If enabled adds an id property to table headers tags.
*
* @default false
*/
tablesHeaderId?: boolean;
/**
* Enable support for GFM code block style.
*
* @default true
*/
ghCodeBlocks?: boolean;
/**
* Enable support for GFM takslists. Example:
*
* - [x] This task is done
* - [ ] This is still pending
*
* @default false
*/
tasklists?: boolean;
/**
* Prevents weird effects in live previews due to incomplete input.
*
* @default false
*/
smoothLivePreview?: boolean;
}
interface ConverterOptions extends ShowdownOptions {
extensions?: string | string[];
}
interface Converter {
/**
* @param text The input text (markdown)
* @return The output HTML
*/
makeHtml(text: string): string;
/**
* Setting a "local" option only affects the specified Converter object.
*
* @param optionKey
* @param string
*/
setOption(optionKey: string, value: string): void;
/**
* Get the option of this Converter instance.
*
* @param optionKey
*/
getOption(optionKey: string): any;
/**
* Get the options of this Converter instance.
*/
getOptions(): ShowdownOptions;
/**
* Add extension to THIS converter.
*
* @param extension
* @param name
*/
addExtension(extension: ShowdownExtension, name: string): void;
/**
* Use a global registered extension with THIS converter
*
* @param extensionName Name of the previously registered extension.
*/
useExtension(extensionName: string): void;
/**
* Get all extensions.
*
* @return all extensions.
*/
getAllExtensions(): ConverterExtensions;
/**
* Remove an extension from THIS converter.
*
* Note: This is a costly operation. It's better to initialize a new converter
* and specify the extensions you wish to use.
*
* @param extensions
*/
removeExtension(extensions: ShowdownExtension[] | ShowdownExtension): void;
}
interface ConverterStatic {
/**
* @constructor
* @param converterOptions Configuration object, describes which extensions to apply
*/
new(converterOptions?: ConverterOptions): Converter;
}
/** Constructor function for a Converter */
var Converter: ConverterStatic;
/**
* Setting a "global" option affects all instances of showdown
*/
function setOption(optionKey: string, value: string): void;
/**
* Retrieve previous set global option.
* @param optionKey
*/
function getOption(optionKey: string): any;
/**
* Retrieve previous set global options.
*/
function getOptions(): ShowdownOptions;
/**
* Reset options.
*/
function resetOptions(): void;
/**
* Retrieve the default options.
*/
function getDefaultOptions(): ShowdownOptions;
/**
* Register an extension.
*
* @prarm name
* @param extenstion
*/
function extension(name: string, extension: (() => ShowdownExtension) | (() => ShowdownExtension[]) | ShowdownExtension): void;
/**
* Get an extension.
*
* @param name
* @return The extensions array.
*/
function extension(name: string): ShowdownExtension[];
/**
* Get all extensions.
*
* @return all extensions.
*/
function getAllExtensions(): {[name: string]: ShowdownExtension[]};
/**
* Remove an extension.
*
* @param name
*/
function removeExtension(name: string): void;
/**
* Reset extensions.
*/
function resetExtensions(): void;
}
declare module "showdown" {
export = Showdown;
}