@alexlit/lint-kit 107.1.0 → 107.2.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/package.json +1 -1
- package/packages/config-eslint/package.json +4 -4
- package/packages/config-markdownlint/node_modules/markdown-it/LICENSE +22 -0
- package/packages/config-markdownlint/node_modules/markdown-it/README.md +309 -0
- package/packages/config-markdownlint/node_modules/markdown-it/bin/markdown-it.js +117 -0
- package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.js +8441 -0
- package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.min.js +3 -0
- package/packages/config-markdownlint/node_modules/markdown-it/index.js +4 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/entities.js +6 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_blocks.js +70 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_re.js +28 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/utils.js +317 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/index.js +7 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_destination.js +80 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_label.js +48 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_title.js +55 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/index.js +582 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_block.js +131 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_core.js +61 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_inline.js +192 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/commonmark.js +81 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/default.js +41 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/zero.js +63 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/renderer.js +341 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/ruler.js +352 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/blockquote.js +226 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/code.js +34 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/fence.js +98 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/heading.js +55 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/hr.js +45 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/html_block.js +74 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/lheading.js +83 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/list.js +362 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/paragraph.js +51 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/reference.js +198 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/state_block.js +231 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/table.js +221 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/block.js +16 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/inline.js +13 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/linkify.js +142 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/normalize.js +21 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/replacements.js +105 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/smartquotes.js +201 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/state_core.js +20 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/text_join.js +45 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/autolink.js +76 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/backticks.js +63 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/balance_pairs.js +130 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/emphasis.js +130 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/entity.js +55 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/escape.js +71 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/fragments_join.js +41 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/html_inline.js +58 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/image.js +152 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/link.js +150 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/linkify.js +62 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/newline.js +46 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/state_inline.js +158 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/strikethrough.js +130 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/text.js +89 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/token.js +201 -0
- package/packages/config-markdownlint/node_modules/markdown-it/package.json +87 -0
- package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +428 -0
- package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +92 -0
- package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/README.md +1026 -0
- package/packages/config-markdownlint/node_modules/markdownlint/demo/markdownlint-browser.js +6814 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +376 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +20 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +2335 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +59 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +53 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +51 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +57 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +54 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +28 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +29 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +31 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +47 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +24 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +98 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +82 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +55 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +45 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +69 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +35 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +34 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +41 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +61 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +100 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +70 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.js +1025 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark.cjs +426 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.js +10 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.js +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +1152 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.js +14 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.ts +406 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.js +1476 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.js +22 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.js +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.js +76 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.js +73 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.js +86 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.js +86 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.js +60 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.js +46 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.js +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.js +96 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.js +53 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.js +34 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md019.js +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.js +62 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md021.js +62 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.js +108 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.js +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.js +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.js +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.js +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.js +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.js +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.js +67 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.js +61 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.js +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.js +78 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.js +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.js +79 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.js +24 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.js +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.js +91 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.js +97 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.js +67 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.js +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.js +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.js +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.js +64 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.js +107 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.js +60 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.js +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.js +28 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.js +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.js +89 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.js +172 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.js +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.js +59 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.js +125 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.js +65 -0
- package/packages/config-markdownlint/node_modules/markdownlint/package.json +109 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +297 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +266 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +1762 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +5 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +22 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +12 -0
- package/packages/config-markdownlint/package.json +3 -3
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// Parser state class
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var Token = require('../token');
|
|
6
|
+
var isSpace = require('../common/utils').isSpace;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function StateBlock(src, md, env, tokens) {
|
|
10
|
+
var ch, s, start, pos, len, indent, offset, indent_found;
|
|
11
|
+
|
|
12
|
+
this.src = src;
|
|
13
|
+
|
|
14
|
+
// link to parser instance
|
|
15
|
+
this.md = md;
|
|
16
|
+
|
|
17
|
+
this.env = env;
|
|
18
|
+
|
|
19
|
+
//
|
|
20
|
+
// Internal state vartiables
|
|
21
|
+
//
|
|
22
|
+
|
|
23
|
+
this.tokens = tokens;
|
|
24
|
+
|
|
25
|
+
this.bMarks = []; // line begin offsets for fast jumps
|
|
26
|
+
this.eMarks = []; // line end offsets for fast jumps
|
|
27
|
+
this.tShift = []; // offsets of the first non-space characters (tabs not expanded)
|
|
28
|
+
this.sCount = []; // indents for each line (tabs expanded)
|
|
29
|
+
|
|
30
|
+
// An amount of virtual spaces (tabs expanded) between beginning
|
|
31
|
+
// of each line (bMarks) and real beginning of that line.
|
|
32
|
+
//
|
|
33
|
+
// It exists only as a hack because blockquotes override bMarks
|
|
34
|
+
// losing information in the process.
|
|
35
|
+
//
|
|
36
|
+
// It's used only when expanding tabs, you can think about it as
|
|
37
|
+
// an initial tab length, e.g. bsCount=21 applied to string `\t123`
|
|
38
|
+
// means first tab should be expanded to 4-21%4 === 3 spaces.
|
|
39
|
+
//
|
|
40
|
+
this.bsCount = [];
|
|
41
|
+
|
|
42
|
+
// block parser variables
|
|
43
|
+
this.blkIndent = 0; // required block content indent (for example, if we are
|
|
44
|
+
// inside a list, it would be positioned after list marker)
|
|
45
|
+
this.line = 0; // line index in src
|
|
46
|
+
this.lineMax = 0; // lines count
|
|
47
|
+
this.tight = false; // loose/tight mode for lists
|
|
48
|
+
this.ddIndent = -1; // indent of the current dd block (-1 if there isn't any)
|
|
49
|
+
this.listIndent = -1; // indent of the current list block (-1 if there isn't any)
|
|
50
|
+
|
|
51
|
+
// can be 'blockquote', 'list', 'root', 'paragraph' or 'reference'
|
|
52
|
+
// used in lists to determine if they interrupt a paragraph
|
|
53
|
+
this.parentType = 'root';
|
|
54
|
+
|
|
55
|
+
this.level = 0;
|
|
56
|
+
|
|
57
|
+
// renderer
|
|
58
|
+
this.result = '';
|
|
59
|
+
|
|
60
|
+
// Create caches
|
|
61
|
+
// Generate markers.
|
|
62
|
+
s = this.src;
|
|
63
|
+
indent_found = false;
|
|
64
|
+
|
|
65
|
+
for (start = pos = indent = offset = 0, len = s.length; pos < len; pos++) {
|
|
66
|
+
ch = s.charCodeAt(pos);
|
|
67
|
+
|
|
68
|
+
if (!indent_found) {
|
|
69
|
+
if (isSpace(ch)) {
|
|
70
|
+
indent++;
|
|
71
|
+
|
|
72
|
+
if (ch === 0x09) {
|
|
73
|
+
offset += 4 - offset % 4;
|
|
74
|
+
} else {
|
|
75
|
+
offset++;
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
} else {
|
|
79
|
+
indent_found = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (ch === 0x0A || pos === len - 1) {
|
|
84
|
+
if (ch !== 0x0A) { pos++; }
|
|
85
|
+
this.bMarks.push(start);
|
|
86
|
+
this.eMarks.push(pos);
|
|
87
|
+
this.tShift.push(indent);
|
|
88
|
+
this.sCount.push(offset);
|
|
89
|
+
this.bsCount.push(0);
|
|
90
|
+
|
|
91
|
+
indent_found = false;
|
|
92
|
+
indent = 0;
|
|
93
|
+
offset = 0;
|
|
94
|
+
start = pos + 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Push fake entry to simplify cache bounds checks
|
|
99
|
+
this.bMarks.push(s.length);
|
|
100
|
+
this.eMarks.push(s.length);
|
|
101
|
+
this.tShift.push(0);
|
|
102
|
+
this.sCount.push(0);
|
|
103
|
+
this.bsCount.push(0);
|
|
104
|
+
|
|
105
|
+
this.lineMax = this.bMarks.length - 1; // don't count last fake line
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Push new token to "stream".
|
|
109
|
+
//
|
|
110
|
+
StateBlock.prototype.push = function (type, tag, nesting) {
|
|
111
|
+
var token = new Token(type, tag, nesting);
|
|
112
|
+
token.block = true;
|
|
113
|
+
|
|
114
|
+
if (nesting < 0) this.level--; // closing tag
|
|
115
|
+
token.level = this.level;
|
|
116
|
+
if (nesting > 0) this.level++; // opening tag
|
|
117
|
+
|
|
118
|
+
this.tokens.push(token);
|
|
119
|
+
return token;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
StateBlock.prototype.isEmpty = function isEmpty(line) {
|
|
123
|
+
return this.bMarks[line] + this.tShift[line] >= this.eMarks[line];
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
StateBlock.prototype.skipEmptyLines = function skipEmptyLines(from) {
|
|
127
|
+
for (var max = this.lineMax; from < max; from++) {
|
|
128
|
+
if (this.bMarks[from] + this.tShift[from] < this.eMarks[from]) {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return from;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// Skip spaces from given position.
|
|
136
|
+
StateBlock.prototype.skipSpaces = function skipSpaces(pos) {
|
|
137
|
+
var ch;
|
|
138
|
+
|
|
139
|
+
for (var max = this.src.length; pos < max; pos++) {
|
|
140
|
+
ch = this.src.charCodeAt(pos);
|
|
141
|
+
if (!isSpace(ch)) { break; }
|
|
142
|
+
}
|
|
143
|
+
return pos;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Skip spaces from given position in reverse.
|
|
147
|
+
StateBlock.prototype.skipSpacesBack = function skipSpacesBack(pos, min) {
|
|
148
|
+
if (pos <= min) { return pos; }
|
|
149
|
+
|
|
150
|
+
while (pos > min) {
|
|
151
|
+
if (!isSpace(this.src.charCodeAt(--pos))) { return pos + 1; }
|
|
152
|
+
}
|
|
153
|
+
return pos;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// Skip char codes from given position
|
|
157
|
+
StateBlock.prototype.skipChars = function skipChars(pos, code) {
|
|
158
|
+
for (var max = this.src.length; pos < max; pos++) {
|
|
159
|
+
if (this.src.charCodeAt(pos) !== code) { break; }
|
|
160
|
+
}
|
|
161
|
+
return pos;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// Skip char codes reverse from given position - 1
|
|
165
|
+
StateBlock.prototype.skipCharsBack = function skipCharsBack(pos, code, min) {
|
|
166
|
+
if (pos <= min) { return pos; }
|
|
167
|
+
|
|
168
|
+
while (pos > min) {
|
|
169
|
+
if (code !== this.src.charCodeAt(--pos)) { return pos + 1; }
|
|
170
|
+
}
|
|
171
|
+
return pos;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// cut lines range from source.
|
|
175
|
+
StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF) {
|
|
176
|
+
var i, lineIndent, ch, first, last, queue, lineStart,
|
|
177
|
+
line = begin;
|
|
178
|
+
|
|
179
|
+
if (begin >= end) {
|
|
180
|
+
return '';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
queue = new Array(end - begin);
|
|
184
|
+
|
|
185
|
+
for (i = 0; line < end; line++, i++) {
|
|
186
|
+
lineIndent = 0;
|
|
187
|
+
lineStart = first = this.bMarks[line];
|
|
188
|
+
|
|
189
|
+
if (line + 1 < end || keepLastLF) {
|
|
190
|
+
// No need for bounds check because we have fake entry on tail.
|
|
191
|
+
last = this.eMarks[line] + 1;
|
|
192
|
+
} else {
|
|
193
|
+
last = this.eMarks[line];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
while (first < last && lineIndent < indent) {
|
|
197
|
+
ch = this.src.charCodeAt(first);
|
|
198
|
+
|
|
199
|
+
if (isSpace(ch)) {
|
|
200
|
+
if (ch === 0x09) {
|
|
201
|
+
lineIndent += 4 - (lineIndent + this.bsCount[line]) % 4;
|
|
202
|
+
} else {
|
|
203
|
+
lineIndent++;
|
|
204
|
+
}
|
|
205
|
+
} else if (first - lineStart < this.tShift[line]) {
|
|
206
|
+
// patched tShift masked characters to look like spaces (blockquotes, list markers)
|
|
207
|
+
lineIndent++;
|
|
208
|
+
} else {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
first++;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (lineIndent > indent) {
|
|
216
|
+
// partially expanding tabs in code blocks, e.g '\t\tfoobar'
|
|
217
|
+
// with indent=2 becomes ' \tfoobar'
|
|
218
|
+
queue[i] = new Array(lineIndent - indent + 1).join(' ') + this.src.slice(first, last);
|
|
219
|
+
} else {
|
|
220
|
+
queue[i] = this.src.slice(first, last);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return queue.join('');
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// re-export Token class to use in block rules
|
|
228
|
+
StateBlock.prototype.Token = Token;
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
module.exports = StateBlock;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// GFM table, https://github.github.com/gfm/#tables-extension-
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var isSpace = require('../common/utils').isSpace;
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function getLine(state, line) {
|
|
9
|
+
var pos = state.bMarks[line] + state.tShift[line],
|
|
10
|
+
max = state.eMarks[line];
|
|
11
|
+
|
|
12
|
+
return state.src.slice(pos, max);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function escapedSplit(str) {
|
|
16
|
+
var result = [],
|
|
17
|
+
pos = 0,
|
|
18
|
+
max = str.length,
|
|
19
|
+
ch,
|
|
20
|
+
isEscaped = false,
|
|
21
|
+
lastPos = 0,
|
|
22
|
+
current = '';
|
|
23
|
+
|
|
24
|
+
ch = str.charCodeAt(pos);
|
|
25
|
+
|
|
26
|
+
while (pos < max) {
|
|
27
|
+
if (ch === 0x7c/* | */) {
|
|
28
|
+
if (!isEscaped) {
|
|
29
|
+
// pipe separating cells, '|'
|
|
30
|
+
result.push(current + str.substring(lastPos, pos));
|
|
31
|
+
current = '';
|
|
32
|
+
lastPos = pos + 1;
|
|
33
|
+
} else {
|
|
34
|
+
// escaped pipe, '\|'
|
|
35
|
+
current += str.substring(lastPos, pos - 1);
|
|
36
|
+
lastPos = pos;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
isEscaped = (ch === 0x5c/* \ */);
|
|
41
|
+
pos++;
|
|
42
|
+
|
|
43
|
+
ch = str.charCodeAt(pos);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
result.push(current + str.substring(lastPos));
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
module.exports = function table(state, startLine, endLine, silent) {
|
|
53
|
+
var ch, lineText, pos, i, l, nextLine, columns, columnCount, token,
|
|
54
|
+
aligns, t, tableLines, tbodyLines, oldParentType, terminate,
|
|
55
|
+
terminatorRules, firstCh, secondCh;
|
|
56
|
+
|
|
57
|
+
// should have at least two lines
|
|
58
|
+
if (startLine + 2 > endLine) { return false; }
|
|
59
|
+
|
|
60
|
+
nextLine = startLine + 1;
|
|
61
|
+
|
|
62
|
+
if (state.sCount[nextLine] < state.blkIndent) { return false; }
|
|
63
|
+
|
|
64
|
+
// if it's indented more than 3 spaces, it should be a code block
|
|
65
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) { return false; }
|
|
66
|
+
|
|
67
|
+
// first character of the second line should be '|', '-', ':',
|
|
68
|
+
// and no other characters are allowed but spaces;
|
|
69
|
+
// basically, this is the equivalent of /^[-:|][-:|\s]*$/ regexp
|
|
70
|
+
|
|
71
|
+
pos = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
72
|
+
if (pos >= state.eMarks[nextLine]) { return false; }
|
|
73
|
+
|
|
74
|
+
firstCh = state.src.charCodeAt(pos++);
|
|
75
|
+
if (firstCh !== 0x7C/* | */ && firstCh !== 0x2D/* - */ && firstCh !== 0x3A/* : */) { return false; }
|
|
76
|
+
|
|
77
|
+
if (pos >= state.eMarks[nextLine]) { return false; }
|
|
78
|
+
|
|
79
|
+
secondCh = state.src.charCodeAt(pos++);
|
|
80
|
+
if (secondCh !== 0x7C/* | */ && secondCh !== 0x2D/* - */ && secondCh !== 0x3A/* : */ && !isSpace(secondCh)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// if first character is '-', then second character must not be a space
|
|
85
|
+
// (due to parsing ambiguity with list)
|
|
86
|
+
if (firstCh === 0x2D/* - */ && isSpace(secondCh)) { return false; }
|
|
87
|
+
|
|
88
|
+
while (pos < state.eMarks[nextLine]) {
|
|
89
|
+
ch = state.src.charCodeAt(pos);
|
|
90
|
+
|
|
91
|
+
if (ch !== 0x7C/* | */ && ch !== 0x2D/* - */ && ch !== 0x3A/* : */ && !isSpace(ch)) { return false; }
|
|
92
|
+
|
|
93
|
+
pos++;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
lineText = getLine(state, startLine + 1);
|
|
97
|
+
|
|
98
|
+
columns = lineText.split('|');
|
|
99
|
+
aligns = [];
|
|
100
|
+
for (i = 0; i < columns.length; i++) {
|
|
101
|
+
t = columns[i].trim();
|
|
102
|
+
if (!t) {
|
|
103
|
+
// allow empty columns before and after table, but not in between columns;
|
|
104
|
+
// e.g. allow ` |---| `, disallow ` ---||--- `
|
|
105
|
+
if (i === 0 || i === columns.length - 1) {
|
|
106
|
+
continue;
|
|
107
|
+
} else {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!/^:?-+:?$/.test(t)) { return false; }
|
|
113
|
+
if (t.charCodeAt(t.length - 1) === 0x3A/* : */) {
|
|
114
|
+
aligns.push(t.charCodeAt(0) === 0x3A/* : */ ? 'center' : 'right');
|
|
115
|
+
} else if (t.charCodeAt(0) === 0x3A/* : */) {
|
|
116
|
+
aligns.push('left');
|
|
117
|
+
} else {
|
|
118
|
+
aligns.push('');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
lineText = getLine(state, startLine).trim();
|
|
123
|
+
if (lineText.indexOf('|') === -1) { return false; }
|
|
124
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
|
|
125
|
+
columns = escapedSplit(lineText);
|
|
126
|
+
if (columns.length && columns[0] === '') columns.shift();
|
|
127
|
+
if (columns.length && columns[columns.length - 1] === '') columns.pop();
|
|
128
|
+
|
|
129
|
+
// header row will define an amount of columns in the entire table,
|
|
130
|
+
// and align row should be exactly the same (the rest of the rows can differ)
|
|
131
|
+
columnCount = columns.length;
|
|
132
|
+
if (columnCount === 0 || columnCount !== aligns.length) { return false; }
|
|
133
|
+
|
|
134
|
+
if (silent) { return true; }
|
|
135
|
+
|
|
136
|
+
oldParentType = state.parentType;
|
|
137
|
+
state.parentType = 'table';
|
|
138
|
+
|
|
139
|
+
// use 'blockquote' lists for termination because it's
|
|
140
|
+
// the most similar to tables
|
|
141
|
+
terminatorRules = state.md.block.ruler.getRules('blockquote');
|
|
142
|
+
|
|
143
|
+
token = state.push('table_open', 'table', 1);
|
|
144
|
+
token.map = tableLines = [ startLine, 0 ];
|
|
145
|
+
|
|
146
|
+
token = state.push('thead_open', 'thead', 1);
|
|
147
|
+
token.map = [ startLine, startLine + 1 ];
|
|
148
|
+
|
|
149
|
+
token = state.push('tr_open', 'tr', 1);
|
|
150
|
+
token.map = [ startLine, startLine + 1 ];
|
|
151
|
+
|
|
152
|
+
for (i = 0; i < columns.length; i++) {
|
|
153
|
+
token = state.push('th_open', 'th', 1);
|
|
154
|
+
if (aligns[i]) {
|
|
155
|
+
token.attrs = [ [ 'style', 'text-align:' + aligns[i] ] ];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
token = state.push('inline', '', 0);
|
|
159
|
+
token.content = columns[i].trim();
|
|
160
|
+
token.children = [];
|
|
161
|
+
|
|
162
|
+
token = state.push('th_close', 'th', -1);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
token = state.push('tr_close', 'tr', -1);
|
|
166
|
+
token = state.push('thead_close', 'thead', -1);
|
|
167
|
+
|
|
168
|
+
for (nextLine = startLine + 2; nextLine < endLine; nextLine++) {
|
|
169
|
+
if (state.sCount[nextLine] < state.blkIndent) { break; }
|
|
170
|
+
|
|
171
|
+
terminate = false;
|
|
172
|
+
for (i = 0, l = terminatorRules.length; i < l; i++) {
|
|
173
|
+
if (terminatorRules[i](state, nextLine, endLine, true)) {
|
|
174
|
+
terminate = true;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (terminate) { break; }
|
|
180
|
+
lineText = getLine(state, nextLine).trim();
|
|
181
|
+
if (!lineText) { break; }
|
|
182
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) { break; }
|
|
183
|
+
columns = escapedSplit(lineText);
|
|
184
|
+
if (columns.length && columns[0] === '') columns.shift();
|
|
185
|
+
if (columns.length && columns[columns.length - 1] === '') columns.pop();
|
|
186
|
+
|
|
187
|
+
if (nextLine === startLine + 2) {
|
|
188
|
+
token = state.push('tbody_open', 'tbody', 1);
|
|
189
|
+
token.map = tbodyLines = [ startLine + 2, 0 ];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
token = state.push('tr_open', 'tr', 1);
|
|
193
|
+
token.map = [ nextLine, nextLine + 1 ];
|
|
194
|
+
|
|
195
|
+
for (i = 0; i < columnCount; i++) {
|
|
196
|
+
token = state.push('td_open', 'td', 1);
|
|
197
|
+
if (aligns[i]) {
|
|
198
|
+
token.attrs = [ [ 'style', 'text-align:' + aligns[i] ] ];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
token = state.push('inline', '', 0);
|
|
202
|
+
token.content = columns[i] ? columns[i].trim() : '';
|
|
203
|
+
token.children = [];
|
|
204
|
+
|
|
205
|
+
token = state.push('td_close', 'td', -1);
|
|
206
|
+
}
|
|
207
|
+
token = state.push('tr_close', 'tr', -1);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (tbodyLines) {
|
|
211
|
+
token = state.push('tbody_close', 'tbody', -1);
|
|
212
|
+
tbodyLines[1] = nextLine;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
token = state.push('table_close', 'table', -1);
|
|
216
|
+
tableLines[1] = nextLine;
|
|
217
|
+
|
|
218
|
+
state.parentType = oldParentType;
|
|
219
|
+
state.line = nextLine;
|
|
220
|
+
return true;
|
|
221
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module.exports = function block(state) {
|
|
5
|
+
var token;
|
|
6
|
+
|
|
7
|
+
if (state.inlineMode) {
|
|
8
|
+
token = new state.Token('inline', '', 0);
|
|
9
|
+
token.content = state.src;
|
|
10
|
+
token.map = [ 0, 1 ];
|
|
11
|
+
token.children = [];
|
|
12
|
+
state.tokens.push(token);
|
|
13
|
+
} else {
|
|
14
|
+
state.md.block.parse(state.src, state.md, state.env, state.tokens);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function inline(state) {
|
|
4
|
+
var tokens = state.tokens, tok, i, l;
|
|
5
|
+
|
|
6
|
+
// Parse inlines
|
|
7
|
+
for (i = 0, l = tokens.length; i < l; i++) {
|
|
8
|
+
tok = tokens[i];
|
|
9
|
+
if (tok.type === 'inline') {
|
|
10
|
+
state.md.inline.parse(tok.content, state.md, state.env, tok.children);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Replace link-like texts with link nodes.
|
|
2
|
+
//
|
|
3
|
+
// Currently restricted by `md.validateLink()` to http/https/ftp
|
|
4
|
+
//
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var arrayReplaceAt = require('../common/utils').arrayReplaceAt;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function isLinkOpen(str) {
|
|
12
|
+
return /^<a[>\s]/i.test(str);
|
|
13
|
+
}
|
|
14
|
+
function isLinkClose(str) {
|
|
15
|
+
return /^<\/a\s*>/i.test(str);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
module.exports = function linkify(state) {
|
|
20
|
+
var i, j, l, tokens, token, currentToken, nodes, ln, text, pos, lastPos,
|
|
21
|
+
level, htmlLinkLevel, url, fullUrl, urlText,
|
|
22
|
+
blockTokens = state.tokens,
|
|
23
|
+
links;
|
|
24
|
+
|
|
25
|
+
if (!state.md.options.linkify) { return; }
|
|
26
|
+
|
|
27
|
+
for (j = 0, l = blockTokens.length; j < l; j++) {
|
|
28
|
+
if (blockTokens[j].type !== 'inline' ||
|
|
29
|
+
!state.md.linkify.pretest(blockTokens[j].content)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
tokens = blockTokens[j].children;
|
|
34
|
+
|
|
35
|
+
htmlLinkLevel = 0;
|
|
36
|
+
|
|
37
|
+
// We scan from the end, to keep position when new tags added.
|
|
38
|
+
// Use reversed logic in links start/end match
|
|
39
|
+
for (i = tokens.length - 1; i >= 0; i--) {
|
|
40
|
+
currentToken = tokens[i];
|
|
41
|
+
|
|
42
|
+
// Skip content of markdown links
|
|
43
|
+
if (currentToken.type === 'link_close') {
|
|
44
|
+
i--;
|
|
45
|
+
while (tokens[i].level !== currentToken.level && tokens[i].type !== 'link_open') {
|
|
46
|
+
i--;
|
|
47
|
+
}
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Skip content of html tag links
|
|
52
|
+
if (currentToken.type === 'html_inline') {
|
|
53
|
+
if (isLinkOpen(currentToken.content) && htmlLinkLevel > 0) {
|
|
54
|
+
htmlLinkLevel--;
|
|
55
|
+
}
|
|
56
|
+
if (isLinkClose(currentToken.content)) {
|
|
57
|
+
htmlLinkLevel++;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (htmlLinkLevel > 0) { continue; }
|
|
61
|
+
|
|
62
|
+
if (currentToken.type === 'text' && state.md.linkify.test(currentToken.content)) {
|
|
63
|
+
|
|
64
|
+
text = currentToken.content;
|
|
65
|
+
links = state.md.linkify.match(text);
|
|
66
|
+
|
|
67
|
+
// Now split string to nodes
|
|
68
|
+
nodes = [];
|
|
69
|
+
level = currentToken.level;
|
|
70
|
+
lastPos = 0;
|
|
71
|
+
|
|
72
|
+
// forbid escape sequence at the start of the string,
|
|
73
|
+
// this avoids http\://example.com/ from being linkified as
|
|
74
|
+
// http:<a href="//example.com/">//example.com/</a>
|
|
75
|
+
if (links.length > 0 &&
|
|
76
|
+
links[0].index === 0 &&
|
|
77
|
+
i > 0 &&
|
|
78
|
+
tokens[i - 1].type === 'text_special') {
|
|
79
|
+
links = links.slice(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for (ln = 0; ln < links.length; ln++) {
|
|
83
|
+
url = links[ln].url;
|
|
84
|
+
fullUrl = state.md.normalizeLink(url);
|
|
85
|
+
if (!state.md.validateLink(fullUrl)) { continue; }
|
|
86
|
+
|
|
87
|
+
urlText = links[ln].text;
|
|
88
|
+
|
|
89
|
+
// Linkifier might send raw hostnames like "example.com", where url
|
|
90
|
+
// starts with domain name. So we prepend http:// in those cases,
|
|
91
|
+
// and remove it afterwards.
|
|
92
|
+
//
|
|
93
|
+
if (!links[ln].schema) {
|
|
94
|
+
urlText = state.md.normalizeLinkText('http://' + urlText).replace(/^http:\/\//, '');
|
|
95
|
+
} else if (links[ln].schema === 'mailto:' && !/^mailto:/i.test(urlText)) {
|
|
96
|
+
urlText = state.md.normalizeLinkText('mailto:' + urlText).replace(/^mailto:/, '');
|
|
97
|
+
} else {
|
|
98
|
+
urlText = state.md.normalizeLinkText(urlText);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
pos = links[ln].index;
|
|
102
|
+
|
|
103
|
+
if (pos > lastPos) {
|
|
104
|
+
token = new state.Token('text', '', 0);
|
|
105
|
+
token.content = text.slice(lastPos, pos);
|
|
106
|
+
token.level = level;
|
|
107
|
+
nodes.push(token);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
token = new state.Token('link_open', 'a', 1);
|
|
111
|
+
token.attrs = [ [ 'href', fullUrl ] ];
|
|
112
|
+
token.level = level++;
|
|
113
|
+
token.markup = 'linkify';
|
|
114
|
+
token.info = 'auto';
|
|
115
|
+
nodes.push(token);
|
|
116
|
+
|
|
117
|
+
token = new state.Token('text', '', 0);
|
|
118
|
+
token.content = urlText;
|
|
119
|
+
token.level = level;
|
|
120
|
+
nodes.push(token);
|
|
121
|
+
|
|
122
|
+
token = new state.Token('link_close', 'a', -1);
|
|
123
|
+
token.level = --level;
|
|
124
|
+
token.markup = 'linkify';
|
|
125
|
+
token.info = 'auto';
|
|
126
|
+
nodes.push(token);
|
|
127
|
+
|
|
128
|
+
lastPos = links[ln].lastIndex;
|
|
129
|
+
}
|
|
130
|
+
if (lastPos < text.length) {
|
|
131
|
+
token = new state.Token('text', '', 0);
|
|
132
|
+
token.content = text.slice(lastPos);
|
|
133
|
+
token.level = level;
|
|
134
|
+
nodes.push(token);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// replace current node
|
|
138
|
+
blockTokens[j].children = tokens = arrayReplaceAt(tokens, i, nodes);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Normalize input string
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// https://spec.commonmark.org/0.29/#line-ending
|
|
7
|
+
var NEWLINES_RE = /\r\n?|\n/g;
|
|
8
|
+
var NULL_RE = /\0/g;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
module.exports = function normalize(state) {
|
|
12
|
+
var str;
|
|
13
|
+
|
|
14
|
+
// Normalize newlines
|
|
15
|
+
str = state.src.replace(NEWLINES_RE, '\n');
|
|
16
|
+
|
|
17
|
+
// Replace NULL characters
|
|
18
|
+
str = str.replace(NULL_RE, '\uFFFD');
|
|
19
|
+
|
|
20
|
+
state.src = str;
|
|
21
|
+
};
|