forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommonmark.d.ts
214 lines (198 loc) · 6.92 KB
/
commonmark.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
// Type definitions for commonmark.js 0.22.1
// Project: https://github.com/jgm/commonmark.js
// Definitions by: Nico Jansen <https://github.com/nicojs>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace commonmark {
export interface NodeWalkingStep {
/**
* a boolean, which is true when we enter a Node from a parent or sibling, and false when we reenter it from a child
*/
entering: boolean;
/**
* The node belonging to this step
*/
node: Node;
}
export interface NodeWalker {
/**
* Returns an object with properties entering and node. Returns null when we have finished walking the tree.
*/
next(): NodeWalkingStep;
/**
* Resets the iterator to resume at the specified node and setting for entering. (Normally this isn't needed unless you do destructive updates to the Node tree.)
*/
resumeAt(node: Node, entering?: boolean): void;
}
export interface Position extends Array<Array<number>> {
}
export interface ListData {
type?: string,
tight?: boolean,
delimiter?: string,
bulletChar?: string
}
export class Node {
constructor(nodeType: string, sourcepos?: Position);
isContainer: boolean;
/**
* (read-only): one of Text, Softbreak, Hardbreak, Emph, Strong, Html, Link, Image, Code, Document, Paragraph, BlockQuote, Item, List, Heading, CodeBlock, HtmlBlock ThematicBreak.
*/
type: string;
/**
* (read-only): a Node or null.
*/
firstChild: Node;
/**
* (read-only): a Node or null.
*/
lastChild: Node;
/**
* (read-only): a Node or null.
*/
next: Node;
/**
* (read-only): a Node or null.
*/
prev: Node;
/**
* (read-only): a Node or null.
*/
parent: Node;
/**
* (read-only): an Array with the following form: [[startline, startcolumn], [endline, endcolumn]]
*/
sourcepos: Position;
/**
* the literal String content of the node or null.
*/
literal: string;
/**
* link or image destination (String) or null.
*/
destination: string;
/**
* link or image title (String) or null.
*/
title: string;
/**
* fenced code block info string (String) or null.
*/
info: string;
/**
* heading level (Number).
*/
level: number;
/**
* either Bullet or Ordered (or undefined).
*/
listType: string;
/**
* true if list is tight
*/
listTight: boolean;
/**
* a Number, the starting number of an ordered list.
*/
listStart: number;
/**
* a String, either ) or . for an ordered list.
*/
listDelimiter: string;
/**
* used only for CustomBlock or CustomInline.
*/
onEnter: string;
/**
* used only for CustomBlock or CustomInline.
*/
onExit: string;
/**
* Append a Node child to the end of the Node's children.
*/
appendChild(child: Node): void;
/**
* Prepend a Node child to the beginning of the Node's children.
*/
prependChild(child: Node): void;
/**
* Remove the Node from the tree, severing its links with siblings and parents, and closing up gaps as needed.
*/
unlink(): void;
/**
* Insert a Node sibling after the Node.
*/
insertAfter(sibling: Node): void;
/**
* Insert a Node sibling before the Node.
*/
insertBefore(sibling: Node): void;
/**
* Returns a NodeWalker that can be used to iterate through the Node tree rooted in the Node
*/
walker(): NodeWalker;
/**
* Setting the backing object of listType, listTight, listStat and listDelimiter directly.
* Not needed unless creating list nodes directly. Should be fixed from v>0.22.1
* https://github.com/jgm/commonmark.js/issues/74
*/
_listData: ListData;
}
/**
* Instead of converting Markdown directly to HTML, as most converters do, commonmark.js parses Markdown to an AST (abstract syntax tree), and then renders this AST as HTML.
* This opens up the possibility of manipulating the AST between parsing and rendering. For example, one could transform emphasis into ALL CAPS.
*/
export class Parser {
/**
* Constructs a new Parser
*/
constructor(options?: ParserOptions);
parse(input: string): Node;
}
export interface ParserOptions {
/**
* if true, straight quotes will be made curly, -- will be changed to an en dash, --- will be changed to an em dash, and ... will be changed to ellipses.
*/
smart?: boolean;
time?: boolean;
}
export interface HtmlRenderingOptions extends XmlRenderingOptions {
/**
* if true, raw HTML will not be passed through to HTML output (it will be replaced by comments), and potentially unsafe URLs in links and images (those beginning with javascript:, vbscript:, file:, and with a few exceptions data:) will be replaced with empty strings.
*/
safe?: boolean;
/**
* if true, straight quotes will be made curly, -- will be changed to an en dash, --- will be changed to an em dash, and ... will be changed to ellipses.
*/
smart?: boolean;
/**
* if true, source position information for block-level elements will be rendered in the data-sourcepos attribute (for HTML) or the sourcepos attribute (for XML).
*/
sourcepos?: boolean;
}
export class HtmlRenderer {
constructor(options?: HtmlRenderingOptions)
render(root: Node): string;
/**
* Let's you override the softbreak properties of a renderer. So, to make soft breaks render as hard breaks in HTML:
* writer.softbreak = "<br />";
*/
softbreak: string;
/**
* Override the function that will be used to escape (sanitize) the html output. Return value is used to add to the html output
* @param input the input to escape
* @param isAttributeValue indicates wheter or not the input value will be used as value of an html attribute.
*/
escape: (input: string, isAttributeValue: boolean) => string;
}
export interface XmlRenderingOptions {
time?: boolean;
sourcepos?: boolean;
}
export class XmlRenderer {
constructor(options?: XmlRenderingOptions)
render(root: Node): string;
}
}
declare module 'commonmark' {
export = commonmark;
}