UNPKG

5.52 kBTypeScriptView Raw
1/**
2 * AST Node types list on TxtNode.
3 * Constant value of types
4 * @see https://github.com/textlint/textlint/blob/master/docs/txtnode.md
5 */
6import type { ASTNodeTypes } from "./ASTNodeTypes";
7/**
8 * Key of ASTNodeTypes or any string
9 * For example, TxtNodeType is "Document".
10 */
11export type TxtNodeType = keyof typeof ASTNodeTypes;
12/**
13 * Any TxtNode types
14 */
15export type AnyTxtNode = TxtNode | TxtTextNode | TxtParentNode;
16/**
17 * Position's line start with 1.
18 * Position's column start with 0.
19 * This is for compatibility with JavaScript AST.
20 * https://gist.github.com/azu/8866b2cb9b7a933e01fe
21 */
22export type TxtNodePosition = {
23 line: number;
24 column: number;
25};
26/**
27 * Location
28 */
29export type TxtNodeLocation = {
30 start: TxtNodePosition;
31 end: TxtNodePosition;
32};
33/**
34 * Range starts with 0
35 */
36export type TxtNodeRange = readonly [startIndex: number, endIndex: number];
37/**
38 * TxtNode is abstract interface of AST Node.
39 * Probably, Real TxtNode implementation has more properties.
40 */
41export interface TxtNode {
42 type: TxtNodeType;
43 raw: string;
44 range: TxtNodeRange;
45 loc: TxtNodeLocation;
46 parent?: TxtParentNode;
47 [index: string]: any;
48}
49/**
50 * Text Node.
51 * Text Node has inline value.
52 * For example, `Str` Node is an TxtTextNode.
53 */
54export interface TxtTextNode extends TxtNode {
55 value: string;
56}
57/**
58 * Parent Node.
59 * Parent Node has children that are consist of TxtParentNode or TxtTextNode
60 */
61export interface TxtParentNode extends TxtNode {
62 children: Content[];
63}
64export type AlignType = "left" | "right" | "center" | null;
65export type ReferenceType = "shortcut" | "collapsed" | "full";
66export type Content = TopLevelContent | ListContent | TableContent | RowContent | PhrasingContent;
67/**
68 * All node definition types.
69 */
70export type TopLevelContent = BlockContent;
71/**
72 * All node types that may be used where markdown block content is accepted.
73 * These types are accepted inside block quotes, list items, and roots.
74 */
75export type BlockContent = TxtParagraphNode | TxtHeaderNode | TxtHorizontalRuleNode | TxtBlockQuoteNode | TxtListNode | TxtTableNode | TxtHtmlNode | TxtCodeBlockNode;
76/**
77 * All node types that are acceptable inside lists.
78 */
79export type ListContent = TxtListItemNode;
80/**
81 * All node types that are acceptable inside tables (not table cells).
82 */
83export type TableContent = TxtTableRowNode;
84/**
85 * All node types that are acceptable inside tables rows (not table cells)
86 */
87export type RowContent = TxtTableCellNode;
88/**
89 * All node types that are acceptable in a (interactive) phrasing context (so not in links).
90 */
91export type PhrasingContent = TxtLinkNode | StaticPhrasingContent;
92/**
93 * All node types that are acceptable in a static phrasing context.
94 */
95export type StaticPhrasingContent = TxtStrNode | TxtEmphasisNode | TxtStrongNode | TxtDeleteNode | TxtHtmlNode | TxtCodeNode | TxtBreakNode | TxtImageNode;
96export interface TxtDocumentNode extends TxtParentNode {
97 type: "Document";
98}
99export interface TxtParagraphNode extends TxtParentNode {
100 type: "Paragraph";
101 children: PhrasingContent[];
102}
103export interface TxtHeaderNode extends TxtParentNode {
104 type: "Header";
105 depth: 1 | 2 | 3 | 4 | 5 | 6;
106 children: PhrasingContent[];
107}
108export interface TxtHorizontalRuleNode extends TxtNode {
109 type: "HorizontalRule";
110}
111export interface TxtBlockQuoteNode extends TxtParentNode {
112 type: "BlockQuote";
113 children: BlockContent[];
114}
115export interface TxtListNode extends TxtParentNode {
116 type: "List";
117 ordered?: boolean | null | undefined;
118 start?: number | null | undefined;
119 spread?: boolean | null | undefined;
120 children: ListContent[];
121}
122export interface TxtListItemNode extends TxtParentNode {
123 type: "ListItem";
124 checked?: boolean | null | undefined;
125 spread?: boolean | null | undefined;
126 children: BlockContent[];
127}
128export interface TxtTableNode extends TxtParentNode {
129 type: "Table";
130 align?: AlignType[] | null | undefined;
131 children: TableContent[];
132}
133export interface TxtTableRowNode extends TxtParentNode {
134 type: "TableRow";
135 children: RowContent[];
136}
137export interface TxtTableCellNode extends TxtParentNode {
138 type: "TableCell";
139 children: PhrasingContent[];
140}
141export interface TxtHtmlNode extends TxtTextNode {
142 type: "Html";
143}
144export interface TxtCommentNode extends TxtTextNode {
145 type: "Comment";
146}
147export interface TxtCodeBlockNode extends TxtTextNode {
148 type: "CodeBlock";
149 lang?: string | null | undefined;
150 meta?: string | null | undefined;
151}
152export interface TxtStrNode extends TxtTextNode {
153 type: "Str";
154}
155export interface TxtEmphasisNode extends TxtParentNode {
156 type: "Emphasis";
157 children: PhrasingContent[];
158}
159export interface TxtStrongNode extends TxtParentNode {
160 type: "Strong";
161 children: PhrasingContent[];
162}
163export interface TxtDeleteNode extends TxtParentNode {
164 type: "Delete";
165 children: PhrasingContent[];
166}
167export interface TxtCodeNode extends TxtTextNode {
168 type: "Code";
169}
170export interface TxtBreakNode extends TxtNode {
171 type: "Break";
172}
173export interface TxtLinkNode extends TxtParentNode, TxtResource {
174 type: "Link";
175 children: StaticPhrasingContent[];
176}
177export interface TxtImageNode extends TxtNode, TxtResource, TxtAlternative {
178 type: "Image";
179}
180export interface TxtResource {
181 url: string;
182 title?: string | null | undefined;
183}
184export interface TxtAlternative {
185 alt?: string | null | undefined;
186}
187//# sourceMappingURL=NodeType.d.ts.map
\No newline at end of file