.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-parse / lib / parser.js
1 'use strict';
2
3 var xtend = require('xtend');
4 var toggle = require('state-toggle');
5 var vfileLocation = require('vfile-location');
6 var unescape = require('./unescape');
7 var decode = require('./decode');
8 var tokenizer = require('./tokenizer');
9
10 module.exports = Parser;
11
12 function Parser(doc, file) {
13   this.file = file;
14   this.offset = {};
15   this.options = xtend(this.options);
16   this.setOptions({});
17
18   this.inList = false;
19   this.inBlock = false;
20   this.inLink = false;
21   this.atStart = true;
22
23   this.toOffset = vfileLocation(file).toOffset;
24   this.unescape = unescape(this, 'escape');
25   this.decode = decode(this);
26 }
27
28 var proto = Parser.prototype;
29
30 /* Expose core. */
31 proto.setOptions = require('./set-options');
32 proto.parse = require('./parse');
33
34 /* Expose `defaults`. */
35 proto.options = require('./defaults');
36
37 /* Enter and exit helpers. */
38 proto.exitStart = toggle('atStart', true);
39 proto.enterList = toggle('inList', false);
40 proto.enterLink = toggle('inLink', false);
41 proto.enterBlock = toggle('inBlock', false);
42
43 /* Nodes that can interupt a paragraph:
44  *
45  * ```markdown
46  * A paragraph, followed by a thematic break.
47  * ___
48  * ```
49  *
50  * In the above example, the thematic break “interupts”
51  * the paragraph. */
52 proto.interruptParagraph = [
53   ['thematicBreak'],
54   ['atxHeading'],
55   ['fencedCode'],
56   ['blockquote'],
57   ['html'],
58   ['setextHeading', {commonmark: false}],
59   ['definition', {commonmark: false}],
60   ['footnote', {commonmark: false}]
61 ];
62
63 /* Nodes that can interupt a list:
64  *
65  * ```markdown
66  * - One
67  * ___
68  * ```
69  *
70  * In the above example, the thematic break “interupts”
71  * the list. */
72 proto.interruptList = [
73   ['fencedCode', {pedantic: false}],
74   ['thematicBreak', {pedantic: false}],
75   ['definition', {commonmark: false}],
76   ['footnote', {commonmark: false}]
77 ];
78
79 /* Nodes that can interupt a blockquote:
80  *
81  * ```markdown
82  * > A paragraph.
83  * ___
84  * ```
85  *
86  * In the above example, the thematic break “interupts”
87  * the blockquote. */
88 proto.interruptBlockquote = [
89   ['indentedCode', {commonmark: true}],
90   ['fencedCode', {commonmark: true}],
91   ['atxHeading', {commonmark: true}],
92   ['setextHeading', {commonmark: true}],
93   ['thematicBreak', {commonmark: true}],
94   ['html', {commonmark: true}],
95   ['list', {commonmark: true}],
96   ['definition', {commonmark: false}],
97   ['footnote', {commonmark: false}]
98 ];
99
100 /* Handlers. */
101 proto.blockTokenizers = {
102   newline: require('./tokenize/newline'),
103   indentedCode: require('./tokenize/code-indented'),
104   fencedCode: require('./tokenize/code-fenced'),
105   blockquote: require('./tokenize/blockquote'),
106   atxHeading: require('./tokenize/heading-atx'),
107   thematicBreak: require('./tokenize/thematic-break'),
108   list: require('./tokenize/list'),
109   setextHeading: require('./tokenize/heading-setext'),
110   html: require('./tokenize/html-block'),
111   footnote: require('./tokenize/footnote-definition'),
112   definition: require('./tokenize/definition'),
113   table: require('./tokenize/table'),
114   paragraph: require('./tokenize/paragraph')
115 };
116
117 proto.inlineTokenizers = {
118   escape: require('./tokenize/escape'),
119   autoLink: require('./tokenize/auto-link'),
120   url: require('./tokenize/url'),
121   html: require('./tokenize/html-inline'),
122   link: require('./tokenize/link'),
123   reference: require('./tokenize/reference'),
124   strong: require('./tokenize/strong'),
125   emphasis: require('./tokenize/emphasis'),
126   deletion: require('./tokenize/delete'),
127   code: require('./tokenize/code-inline'),
128   break: require('./tokenize/break'),
129   text: require('./tokenize/text')
130 };
131
132 /* Expose precedence. */
133 proto.blockMethods = keys(proto.blockTokenizers);
134 proto.inlineMethods = keys(proto.inlineTokenizers);
135
136 /* Tokenizers. */
137 proto.tokenizeBlock = tokenizer('block');
138 proto.tokenizeInline = tokenizer('inline');
139 proto.tokenizeFactory = tokenizer;
140
141 /* Get all keys in `value`. */
142 function keys(value) {
143   var result = [];
144   var key;
145
146   for (key in value) {
147     result.push(key);
148   }
149
150   return result;
151 }