@khanacademy/simple-markdown 0.8.6 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,187 @@
1
- // @flow
2
- export * from "../src/index.js";
1
+ /**
2
+ * Simple-Markdown
3
+ * ===============
4
+ *
5
+ * Simple-Markdown's primary goal is to be easy to adapt. It aims
6
+ * to be compliant with John Gruber's [Markdown Syntax page][1],
7
+ * but compatiblity with other markdown implementations' edge-cases
8
+ * will be sacrificed where it conflicts with simplicity or
9
+ * extensibility.
10
+ *
11
+ * If your goal is to simply embed a standard markdown implementation
12
+ * in your website, simple-markdown is probably not the best library
13
+ * for you (although it should work). But if you have struggled to
14
+ * customize an existing library to meet your needs, simple-markdown
15
+ * might be able to help.
16
+ *
17
+ * Many of the regexes and original logic has been adapted from
18
+ * the wonderful [marked.js](https://github.com/chjj/marked)
19
+ */
20
+ import * as React from "react";
21
+ type Capture = (Array<string> & {
22
+ index: number;
23
+ }) | (Array<string> & {
24
+ index?: number;
25
+ });
26
+ type Attr = string | number | boolean | null | undefined;
27
+ type SingleASTNode = {
28
+ type: string;
29
+ [key: string]: any;
30
+ };
31
+ type UnTypedASTNode = {
32
+ [key: string]: any;
33
+ };
34
+ type ASTNode = SingleASTNode | Array<SingleASTNode>;
35
+ type State = {
36
+ key?: string | number | undefined;
37
+ inline?: boolean | null | undefined;
38
+ [key: string]: any;
39
+ };
40
+ type ReactElement = React.ReactElement<any>;
41
+ type ReactElements = React.ReactNode;
42
+ type MatchFunction = {
43
+ regex?: RegExp;
44
+ } & ((source: string, state: State, prevCapture: string) => Capture | null | undefined);
45
+ type Parser = (source: string, state?: State | null | undefined) => Array<SingleASTNode>;
46
+ type ParseFunction = (capture: Capture, nestedParse: Parser, state: State) => UnTypedASTNode | ASTNode;
47
+ type SingleNodeParseFunction = (capture: Capture, nestedParse: Parser, state: State) => UnTypedASTNode;
48
+ type Output<Result> = (node: ASTNode, state?: State | null | undefined) => Result;
49
+ type NodeOutput<Result> = (node: SingleASTNode, nestedOutput: Output<Result>, state: State) => Result;
50
+ type ArrayNodeOutput<Result> = (node: Array<SingleASTNode>, nestedOutput: Output<Result>, state: State) => Result;
51
+ type ReactOutput = Output<ReactElements>;
52
+ type ReactNodeOutput = NodeOutput<ReactElements>;
53
+ type HtmlOutput = Output<string>;
54
+ type HtmlNodeOutput = NodeOutput<string>;
55
+ type ParserRule = {
56
+ readonly order: number;
57
+ readonly match: MatchFunction;
58
+ readonly quality?: (capture: Capture, state: State, prevCapture: string) => number;
59
+ readonly parse: ParseFunction;
60
+ };
61
+ type SingleNodeParserRule = {
62
+ readonly order: number;
63
+ readonly match: MatchFunction;
64
+ readonly quality?: (capture: Capture, state: State, prevCapture: string) => number;
65
+ readonly parse: SingleNodeParseFunction;
66
+ };
67
+ type ReactOutputRule = {
68
+ readonly react: ReactNodeOutput | null;
69
+ };
70
+ type HtmlOutputRule = {
71
+ readonly html: HtmlNodeOutput | null;
72
+ };
73
+ type ArrayRule = {
74
+ readonly react?: ArrayNodeOutput<ReactElements>;
75
+ readonly html?: ArrayNodeOutput<string>;
76
+ readonly [key: string]: ArrayNodeOutput<any>;
77
+ };
78
+ type ParserRules = {
79
+ readonly Array?: ArrayRule;
80
+ readonly [type: string]: ParserRule;
81
+ };
82
+ type OutputRules<Rule> = {
83
+ readonly Array?: ArrayRule;
84
+ readonly [type: string]: Rule;
85
+ };
86
+ type Rules<OutputRule> = {
87
+ readonly Array?: ArrayRule;
88
+ readonly [type: string]: ParserRule & OutputRule;
89
+ };
90
+ type ReactRules = {
91
+ readonly Array?: {
92
+ readonly react: ArrayNodeOutput<ReactElements>;
93
+ };
94
+ readonly [type: string]: ParserRule & ReactOutputRule;
95
+ };
96
+ type HtmlRules = {
97
+ readonly Array?: {
98
+ readonly html: ArrayNodeOutput<string>;
99
+ };
100
+ readonly [type: string]: ParserRule & HtmlOutputRule;
101
+ };
102
+ type NonNullReactOutputRule = {
103
+ readonly react: ReactNodeOutput;
104
+ };
105
+ type ElementReactOutputRule = {
106
+ readonly react: NodeOutput<ReactElement>;
107
+ };
108
+ type TextReactOutputRule = {
109
+ readonly react: NodeOutput<string>;
110
+ };
111
+ type NonNullHtmlOutputRule = {
112
+ readonly html: HtmlNodeOutput;
113
+ };
114
+ type DefaultInRule = SingleNodeParserRule & ReactOutputRule & HtmlOutputRule;
115
+ type TextInOutRule = SingleNodeParserRule & TextReactOutputRule & NonNullHtmlOutputRule;
116
+ type LenientInOutRule = SingleNodeParserRule & NonNullReactOutputRule & NonNullHtmlOutputRule;
117
+ type DefaultInOutRule = SingleNodeParserRule & ElementReactOutputRule & NonNullHtmlOutputRule;
118
+ type DefaultRules = {
119
+ readonly Array: {
120
+ readonly react: ArrayNodeOutput<ReactElements>;
121
+ readonly html: ArrayNodeOutput<string>;
122
+ };
123
+ readonly heading: DefaultInOutRule;
124
+ readonly nptable: DefaultInRule;
125
+ readonly lheading: DefaultInRule;
126
+ readonly hr: DefaultInOutRule;
127
+ readonly codeBlock: DefaultInOutRule;
128
+ readonly fence: DefaultInRule;
129
+ readonly blockQuote: DefaultInOutRule;
130
+ readonly list: DefaultInOutRule;
131
+ readonly def: LenientInOutRule;
132
+ readonly table: DefaultInOutRule;
133
+ readonly tableSeparator: DefaultInRule;
134
+ readonly newline: TextInOutRule;
135
+ readonly paragraph: DefaultInOutRule;
136
+ readonly escape: DefaultInRule;
137
+ readonly autolink: DefaultInRule;
138
+ readonly mailto: DefaultInRule;
139
+ readonly url: DefaultInRule;
140
+ readonly link: DefaultInOutRule;
141
+ readonly image: DefaultInOutRule;
142
+ readonly reflink: DefaultInRule;
143
+ readonly refimage: DefaultInRule;
144
+ readonly em: DefaultInOutRule;
145
+ readonly strong: DefaultInOutRule;
146
+ readonly u: DefaultInOutRule;
147
+ readonly del: DefaultInOutRule;
148
+ readonly inlineCode: DefaultInOutRule;
149
+ readonly br: DefaultInOutRule;
150
+ readonly text: TextInOutRule;
151
+ };
152
+ type Exports = {
153
+ readonly defaultRules: DefaultRules;
154
+ readonly parserFor: (rules: ParserRules, defaultState?: State | null | undefined) => Parser;
155
+ readonly outputFor: <Rule>(rules: OutputRules<Rule>, param: keyof Rule, defaultState?: State | null | undefined) => Output<any>;
156
+ readonly ruleOutput: <Rule>(rules: OutputRules<Rule>, param: keyof Rule) => NodeOutput<any>;
157
+ readonly reactFor: (arg1: ReactNodeOutput) => ReactOutput;
158
+ readonly htmlFor: (arg1: HtmlNodeOutput) => HtmlOutput;
159
+ readonly inlineRegex: (regex: RegExp) => MatchFunction;
160
+ readonly blockRegex: (regex: RegExp) => MatchFunction;
161
+ readonly anyScopeRegex: (regex: RegExp) => MatchFunction;
162
+ readonly parseInline: (parse: Parser, content: string, state: State) => ASTNode;
163
+ readonly parseBlock: (parse: Parser, content: string, state: State) => ASTNode;
164
+ readonly markdownToReact: (source: string, state?: State | null | undefined) => ReactElements;
165
+ readonly markdownToHtml: (source: string, state?: State | null | undefined) => string;
166
+ readonly ReactMarkdown: (props: {
167
+ source: string;
168
+ [key: string]: any;
169
+ }) => ReactElement;
170
+ readonly defaultRawParse: (source: string, state?: State | null | undefined) => Array<SingleASTNode>;
171
+ readonly defaultBlockParse: (source: string, state?: State | null | undefined) => Array<SingleASTNode>;
172
+ readonly defaultInlineParse: (source: string, state?: State | null | undefined) => Array<SingleASTNode>;
173
+ readonly defaultImplicitParse: (source: string, state?: State | null | undefined) => Array<SingleASTNode>;
174
+ readonly defaultReactOutput: ReactOutput;
175
+ readonly defaultHtmlOutput: HtmlOutput;
176
+ readonly preprocess: (source: string) => string;
177
+ readonly sanitizeText: (text: Attr) => string;
178
+ readonly sanitizeUrl: (url?: string | null | undefined) => string | null | undefined;
179
+ readonly unescapeUrl: (url: string) => string;
180
+ readonly htmlTag: (tagName: string, content: string, attributes?: Partial<Record<any, Attr | null | undefined>> | null | undefined, isClosed?: boolean | null | undefined) => string;
181
+ readonly reactElement: (type: string, key: string | null, props: {
182
+ [key: string]: any;
183
+ }) => ReactElement;
184
+ };
185
+ export type { State, Parser, Output, ReactOutput, HtmlOutput, Capture, MatchFunction, ParseFunction, NodeOutput, ArrayNodeOutput, ReactNodeOutput, ParserRule, ReactOutputRule, HtmlOutputRule, ParserRules, OutputRules, Rules, ReactRules, HtmlRules, SingleASTNode, };
186
+ declare var SimpleMarkdown: Exports;
187
+ export default SimpleMarkdown;