@diplodoc/transform 4.0.0
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/CHANGELOG.diplodoc.md +38 -0
- package/CHANGELOG.md +404 -0
- package/LICENSE +21 -0
- package/README.md +41 -0
- package/README.ru.md +36 -0
- package/dist/css/yfm.css +736 -0
- package/dist/css/yfm.css.map +7 -0
- package/dist/css/yfm.min.css +2 -0
- package/dist/css/yfm.min.css.map +7 -0
- package/dist/js/code.d.ts +1 -0
- package/dist/js/cut.d.ts +1 -0
- package/dist/js/index.d.ts +5 -0
- package/dist/js/polyfill.d.ts +1 -0
- package/dist/js/tabs.d.ts +1 -0
- package/dist/js/term/index.d.ts +1 -0
- package/dist/js/term/utils.d.ts +10 -0
- package/dist/js/utils.d.ts +2 -0
- package/dist/js/yfm.js +432 -0
- package/dist/js/yfm.js.map +7 -0
- package/dist/js/yfm.min.js +2 -0
- package/dist/js/yfm.min.js.map +7 -0
- package/lib/getObject.d.ts +2 -0
- package/lib/getObject.js +11 -0
- package/lib/getObject.js.map +1 -0
- package/lib/headings.d.ts +4 -0
- package/lib/headings.js +73 -0
- package/lib/headings.js.map +1 -0
- package/lib/highlight.d.ts +3 -0
- package/lib/highlight.js +29 -0
- package/lib/highlight.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +35 -0
- package/lib/index.js.map +1 -0
- package/lib/liquid/conditions.d.ts +4 -0
- package/lib/liquid/conditions.js +181 -0
- package/lib/liquid/conditions.js.map +1 -0
- package/lib/liquid/cycles.d.ts +4 -0
- package/lib/liquid/cycles.js +160 -0
- package/lib/liquid/cycles.js.map +1 -0
- package/lib/liquid/errors.d.ts +3 -0
- package/lib/liquid/errors.js +13 -0
- package/lib/liquid/errors.js.map +1 -0
- package/lib/liquid/evaluation.d.ts +3 -0
- package/lib/liquid/evaluation.js +138 -0
- package/lib/liquid/evaluation.js.map +1 -0
- package/lib/liquid/filters.d.ts +9 -0
- package/lib/liquid/filters.js +22 -0
- package/lib/liquid/filters.js.map +1 -0
- package/lib/liquid/index.d.ts +9 -0
- package/lib/liquid/index.js +87 -0
- package/lib/liquid/index.js.map +1 -0
- package/lib/liquid/lexical.d.ts +14 -0
- package/lib/liquid/lexical.js +79 -0
- package/lib/liquid/lexical.js.map +1 -0
- package/lib/liquid/services/argv.d.ts +15 -0
- package/lib/liquid/services/argv.js +17 -0
- package/lib/liquid/services/argv.js.map +1 -0
- package/lib/liquid/sourceMap.d.ts +24 -0
- package/lib/liquid/sourceMap.js +56 -0
- package/lib/liquid/sourceMap.js.map +1 -0
- package/lib/liquid/substitutions.d.ts +2 -0
- package/lib/liquid/substitutions.js +36 -0
- package/lib/liquid/substitutions.js.map +1 -0
- package/lib/liquid/utils.d.ts +8 -0
- package/lib/liquid/utils.js +24 -0
- package/lib/liquid/utils.js.map +1 -0
- package/lib/log.d.ts +18 -0
- package/lib/log.js +54 -0
- package/lib/log.js.map +1 -0
- package/lib/md.d.ts +14 -0
- package/lib/md.js +96 -0
- package/lib/md.js.map +1 -0
- package/lib/plugins/anchors/collect.d.ts +5 -0
- package/lib/plugins/anchors/collect.js +81 -0
- package/lib/plugins/anchors/collect.js.map +1 -0
- package/lib/plugins/anchors/constants.d.ts +2 -0
- package/lib/plugins/anchors/constants.js +6 -0
- package/lib/plugins/anchors/constants.js.map +1 -0
- package/lib/plugins/anchors/index.d.ts +7 -0
- package/lib/plugins/anchors/index.js +134 -0
- package/lib/plugins/anchors/index.js.map +1 -0
- package/lib/plugins/changelog/collect.d.ts +8 -0
- package/lib/plugins/changelog/collect.js +50 -0
- package/lib/plugins/changelog/collect.js.map +1 -0
- package/lib/plugins/changelog/index.d.ts +6 -0
- package/lib/plugins/changelog/index.js +131 -0
- package/lib/plugins/changelog/index.js.map +1 -0
- package/lib/plugins/changelog/types.d.ts +10 -0
- package/lib/plugins/changelog/types.js +3 -0
- package/lib/plugins/changelog/types.js.map +1 -0
- package/lib/plugins/checkbox/checkbox.d.ts +7 -0
- package/lib/plugins/checkbox/checkbox.js +91 -0
- package/lib/plugins/checkbox/checkbox.js.map +1 -0
- package/lib/plugins/checkbox/index.d.ts +8 -0
- package/lib/plugins/checkbox/index.js +12 -0
- package/lib/plugins/checkbox/index.js.map +1 -0
- package/lib/plugins/code.d.ts +3 -0
- package/lib/plugins/code.js +61 -0
- package/lib/plugins/code.js.map +1 -0
- package/lib/plugins/cut.d.ts +3 -0
- package/lib/plugins/cut.js +70 -0
- package/lib/plugins/cut.js.map +1 -0
- package/lib/plugins/deflist.d.ts +3 -0
- package/lib/plugins/deflist.js +8 -0
- package/lib/plugins/deflist.js.map +1 -0
- package/lib/plugins/file/const.d.ts +27 -0
- package/lib/plugins/file/const.js +47 -0
- package/lib/plugins/file/const.js.map +1 -0
- package/lib/plugins/file/file.d.ts +8 -0
- package/lib/plugins/file/file.js +63 -0
- package/lib/plugins/file/file.js.map +1 -0
- package/lib/plugins/file/index.d.ts +4 -0
- package/lib/plugins/file/index.js +9 -0
- package/lib/plugins/file/index.js.map +1 -0
- package/lib/plugins/images/collect.d.ts +8 -0
- package/lib/plugins/images/collect.js +43 -0
- package/lib/plugins/images/collect.js.map +1 -0
- package/lib/plugins/images/index.d.ts +10 -0
- package/lib/plugins/images/index.js +81 -0
- package/lib/plugins/images/index.js.map +1 -0
- package/lib/plugins/imsize/const.d.ts +7 -0
- package/lib/plugins/imsize/const.js +12 -0
- package/lib/plugins/imsize/const.js.map +1 -0
- package/lib/plugins/imsize/helpers.d.ts +6 -0
- package/lib/plugins/imsize/helpers.js +64 -0
- package/lib/plugins/imsize/helpers.js.map +1 -0
- package/lib/plugins/imsize/index.d.ts +8 -0
- package/lib/plugins/imsize/index.js +12 -0
- package/lib/plugins/imsize/index.js.map +1 -0
- package/lib/plugins/imsize/plugin.d.ts +3 -0
- package/lib/plugins/imsize/plugin.js +188 -0
- package/lib/plugins/imsize/plugin.js.map +1 -0
- package/lib/plugins/includes/collect.d.ts +8 -0
- package/lib/plugins/includes/collect.js +49 -0
- package/lib/plugins/includes/collect.js.map +1 -0
- package/lib/plugins/includes/index.d.ts +8 -0
- package/lib/plugins/includes/index.js +98 -0
- package/lib/plugins/includes/index.js.map +1 -0
- package/lib/plugins/links/collect.d.ts +7 -0
- package/lib/plugins/links/collect.js +74 -0
- package/lib/plugins/links/collect.js.map +1 -0
- package/lib/plugins/links/constants.d.ts +1 -0
- package/lib/plugins/links/constants.js +5 -0
- package/lib/plugins/links/constants.js.map +1 -0
- package/lib/plugins/links/index.d.ts +24 -0
- package/lib/plugins/links/index.js +178 -0
- package/lib/plugins/links/index.js.map +1 -0
- package/lib/plugins/meta.d.ts +3 -0
- package/lib/plugins/meta.js +8 -0
- package/lib/plugins/meta.js.map +1 -0
- package/lib/plugins/monospace.d.ts +3 -0
- package/lib/plugins/monospace.js +109 -0
- package/lib/plugins/monospace.js.map +1 -0
- package/lib/plugins/notes.d.ts +3 -0
- package/lib/plugins/notes.js +103 -0
- package/lib/plugins/notes.js.map +1 -0
- package/lib/plugins/sup.d.ts +3 -0
- package/lib/plugins/sup.js +8 -0
- package/lib/plugins/sup.js.map +1 -0
- package/lib/plugins/table/index.d.ts +3 -0
- package/lib/plugins/table/index.js +215 -0
- package/lib/plugins/table/index.js.map +1 -0
- package/lib/plugins/tabs.d.ts +4 -0
- package/lib/plugins/tabs.js +4 -0
- package/lib/plugins/tabs.js.map +1 -0
- package/lib/plugins/term/constants.d.ts +1 -0
- package/lib/plugins/term/constants.js +5 -0
- package/lib/plugins/term/constants.js.map +1 -0
- package/lib/plugins/term/index.d.ts +3 -0
- package/lib/plugins/term/index.js +108 -0
- package/lib/plugins/term/index.js.map +1 -0
- package/lib/plugins/term/termDefinitions.d.ts +4 -0
- package/lib/plugins/term/termDefinitions.js +125 -0
- package/lib/plugins/term/termDefinitions.js.map +1 -0
- package/lib/plugins/typings.d.ts +12 -0
- package/lib/plugins/typings.js +3 -0
- package/lib/plugins/typings.js.map +1 -0
- package/lib/plugins/utils.d.ts +6 -0
- package/lib/plugins/utils.js +30 -0
- package/lib/plugins/utils.js.map +1 -0
- package/lib/plugins/video/const.d.ts +10 -0
- package/lib/plugins/video/const.js +22 -0
- package/lib/plugins/video/const.js.map +1 -0
- package/lib/plugins/video/index.d.ts +8 -0
- package/lib/plugins/video/index.js +104 -0
- package/lib/plugins/video/index.js.map +1 -0
- package/lib/plugins/video/parsers.d.ts +6 -0
- package/lib/plugins/video/parsers.js +64 -0
- package/lib/plugins/video/parsers.js.map +1 -0
- package/lib/plugins/video/types.d.ts +34 -0
- package/lib/plugins/video/types.js +3 -0
- package/lib/plugins/video/types.js.map +1 -0
- package/lib/plugins/video/utils.d.ts +2 -0
- package/lib/plugins/video/utils.js +25 -0
- package/lib/plugins/video/utils.js.map +1 -0
- package/lib/plugins.d.ts +3 -0
- package/lib/plugins.js +36 -0
- package/lib/plugins.js.map +1 -0
- package/lib/sanitize.d.ts +12 -0
- package/lib/sanitize.js +572 -0
- package/lib/sanitize.js.map +1 -0
- package/lib/title.d.ts +7 -0
- package/lib/title.js +18 -0
- package/lib/title.js.map +1 -0
- package/lib/typings.d.ts +57 -0
- package/lib/typings.js +3 -0
- package/lib/typings.js.map +1 -0
- package/lib/utils.d.ts +13 -0
- package/lib/utils.js +79 -0
- package/lib/utils.js.map +1 -0
- package/lib/utilsFS.d.ts +27 -0
- package/lib/utilsFS.js +89 -0
- package/lib/utilsFS.js.map +1 -0
- package/lib/yfmlint/index.d.ts +26 -0
- package/lib/yfmlint/index.js +72 -0
- package/lib/yfmlint/index.js.map +1 -0
- package/lib/yfmlint/markdownlint-custom-rule/index.d.ts +9 -0
- package/lib/yfmlint/markdownlint-custom-rule/index.js +22 -0
- package/lib/yfmlint/markdownlint-custom-rule/index.js.map +1 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm001.d.ts +2 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm001.js +28 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm001.js.map +1 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm002.d.ts +2 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm002.js +33 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm002.js.map +1 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm003.d.ts +2 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm003.js +33 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm003.js.map +1 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm004.d.ts +2 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm004.js +28 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm004.js.map +1 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm005.d.ts +2 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm005.js +28 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm005.js.map +1 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm006.d.ts +2 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm006.js +28 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm006.js.map +1 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm007.d.ts +2 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm007.js +29 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm007.js.map +1 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm008.d.ts +2 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm008.js +28 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm008.js.map +1 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm009.d.ts +2 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm009.js +47 -0
- package/lib/yfmlint/markdownlint-custom-rule/yfm009.js.map +1 -0
- package/lib/yfmlint/typings.d.ts +12 -0
- package/lib/yfmlint/typings.js +3 -0
- package/lib/yfmlint/typings.js.map +1 -0
- package/lib/yfmlint/utils.d.ts +9 -0
- package/lib/yfmlint/utils.js +22 -0
- package/lib/yfmlint/utils.js.map +1 -0
- package/lib/yfmlint/yfmlint.d.ts +3 -0
- package/lib/yfmlint/yfmlint.js +69 -0
- package/lib/yfmlint/yfmlint.js.map +1 -0
- package/package.json +106 -0
- package/src/.eslintrc +10 -0
- package/src/js/code.ts +65 -0
- package/src/js/cut.ts +57 -0
- package/src/js/index.ts +6 -0
- package/src/js/polyfill.js +27 -0
- package/src/js/term/index.ts +79 -0
- package/src/js/term/utils.ts +151 -0
- package/src/js/utils.ts +9 -0
- package/src/scss/_anchor.scss +33 -0
- package/src/scss/_code.scss +23 -0
- package/src/scss/_common.scss +407 -0
- package/src/scss/_cut.scss +42 -0
- package/src/scss/_file.scss +35 -0
- package/src/scss/_highlight.scss +96 -0
- package/src/scss/_note.scss +73 -0
- package/src/scss/_print.scss +20 -0
- package/src/scss/_term.scss +79 -0
- package/src/scss/_variables.scss +16 -0
- package/src/scss/yfm.scss +11 -0
- package/src/transform/getObject.ts +10 -0
- package/src/transform/headings.ts +88 -0
- package/src/transform/highlight.ts +33 -0
- package/src/transform/index.ts +50 -0
- package/src/transform/liquid/conditions.ts +259 -0
- package/src/transform/liquid/cycles.ts +244 -0
- package/src/transform/liquid/errors.ts +10 -0
- package/src/transform/liquid/evaluation.ts +145 -0
- package/src/transform/liquid/filters.ts +19 -0
- package/src/transform/liquid/index.ts +141 -0
- package/src/transform/liquid/lexical.ts +86 -0
- package/src/transform/liquid/services/argv.ts +23 -0
- package/src/transform/liquid/sourceMap.ts +72 -0
- package/src/transform/liquid/substitutions.ts +40 -0
- package/src/transform/liquid/utils.ts +30 -0
- package/src/transform/log.ts +60 -0
- package/src/transform/md.ts +123 -0
- package/src/transform/plugins/anchors/collect.ts +101 -0
- package/src/transform/plugins/anchors/constants.ts +2 -0
- package/src/transform/plugins/anchors/index.ts +166 -0
- package/src/transform/plugins/changelog/collect.ts +66 -0
- package/src/transform/plugins/changelog/index.ts +164 -0
- package/src/transform/plugins/changelog/types.ts +10 -0
- package/src/transform/plugins/checkbox/checkbox.ts +107 -0
- package/src/transform/plugins/checkbox/index.ts +15 -0
- package/src/transform/plugins/code.ts +79 -0
- package/src/transform/plugins/cut.ts +98 -0
- package/src/transform/plugins/deflist.ts +5 -0
- package/src/transform/plugins/file/README.md +34 -0
- package/src/transform/plugins/file/const.ts +46 -0
- package/src/transform/plugins/file/file.ts +82 -0
- package/src/transform/plugins/file/index.ts +10 -0
- package/src/transform/plugins/images/collect.ts +60 -0
- package/src/transform/plugins/images/index.ts +119 -0
- package/src/transform/plugins/imsize/const.ts +7 -0
- package/src/transform/plugins/imsize/helpers.ts +75 -0
- package/src/transform/plugins/imsize/index.ts +14 -0
- package/src/transform/plugins/imsize/plugin.ts +214 -0
- package/src/transform/plugins/includes/collect.ts +73 -0
- package/src/transform/plugins/includes/index.ts +127 -0
- package/src/transform/plugins/links/collect.ts +92 -0
- package/src/transform/plugins/links/constants.ts +1 -0
- package/src/transform/plugins/links/index.ts +218 -0
- package/src/transform/plugins/meta.ts +5 -0
- package/src/transform/plugins/monospace.ts +141 -0
- package/src/transform/plugins/notes.ts +134 -0
- package/src/transform/plugins/sup.ts +5 -0
- package/src/transform/plugins/table/index.ts +290 -0
- package/src/transform/plugins/tabs.ts +3 -0
- package/src/transform/plugins/term/constants.ts +1 -0
- package/src/transform/plugins/term/index.ts +139 -0
- package/src/transform/plugins/term/termDefinitions.ts +177 -0
- package/src/transform/plugins/typings.ts +14 -0
- package/src/transform/plugins/utils.ts +38 -0
- package/src/transform/plugins/video/const.ts +20 -0
- package/src/transform/plugins/video/index.ts +134 -0
- package/src/transform/plugins/video/parsers.ts +65 -0
- package/src/transform/plugins/video/types.ts +27 -0
- package/src/transform/plugins/video/utils.ts +24 -0
- package/src/transform/plugins.ts +35 -0
- package/src/transform/sanitize.ts +596 -0
- package/src/transform/title.ts +22 -0
- package/src/transform/typings.ts +64 -0
- package/src/transform/utils.ts +91 -0
- package/src/transform/utilsFS.ts +128 -0
- package/src/transform/yfmlint/README.md +48 -0
- package/src/transform/yfmlint/index.ts +124 -0
- package/src/transform/yfmlint/markdownlint-custom-rule/index.ts +9 -0
- package/src/transform/yfmlint/markdownlint-custom-rule/yfm001.ts +36 -0
- package/src/transform/yfmlint/markdownlint-custom-rule/yfm002.ts +33 -0
- package/src/transform/yfmlint/markdownlint-custom-rule/yfm003.ts +33 -0
- package/src/transform/yfmlint/markdownlint-custom-rule/yfm004.ts +27 -0
- package/src/transform/yfmlint/markdownlint-custom-rule/yfm005.ts +27 -0
- package/src/transform/yfmlint/markdownlint-custom-rule/yfm006.ts +26 -0
- package/src/transform/yfmlint/markdownlint-custom-rule/yfm007.ts +28 -0
- package/src/transform/yfmlint/markdownlint-custom-rule/yfm008.ts +26 -0
- package/src/transform/yfmlint/markdownlint-custom-rule/yfm009.ts +54 -0
- package/src/transform/yfmlint/typings.ts +13 -0
- package/src/transform/yfmlint/utils.ts +31 -0
- package/src/transform/yfmlint/yfmlint.ts +73 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type MarkdownIt from 'markdown-it';
|
|
2
|
+
import type ParserInline from 'markdown-it/lib/parser_inline';
|
|
3
|
+
import type Token from 'markdown-it/lib/token';
|
|
4
|
+
import {ImsizeAttr} from './const';
|
|
5
|
+
import {parseImageSize} from './helpers';
|
|
6
|
+
|
|
7
|
+
export const imageWithSize = (md: MarkdownIt): ParserInline.RuleInline => {
|
|
8
|
+
// eslint-disable-next-line complexity
|
|
9
|
+
return (state, silent) => {
|
|
10
|
+
if (state.src.charCodeAt(state.pos) !== 0x21 /* ! */) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (state.src.charCodeAt(state.pos + 1) !== 0x5b /* [ */) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const labelStart = state.pos + 2;
|
|
19
|
+
const labelEnd = md.helpers.parseLinkLabel(state, state.pos + 1, false);
|
|
20
|
+
|
|
21
|
+
// parser failed to find ']', so it's not a valid link
|
|
22
|
+
if (labelEnd < 0) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let href = '';
|
|
27
|
+
let title = '';
|
|
28
|
+
let width = '';
|
|
29
|
+
let height = '';
|
|
30
|
+
|
|
31
|
+
const oldPos = state.pos;
|
|
32
|
+
const max = state.posMax;
|
|
33
|
+
|
|
34
|
+
let pos = labelEnd + 1;
|
|
35
|
+
if (pos < max && state.src.charCodeAt(pos) === 0x28 /* ( */) {
|
|
36
|
+
//
|
|
37
|
+
// Inline link
|
|
38
|
+
//
|
|
39
|
+
|
|
40
|
+
// [link]( <href> "title" )
|
|
41
|
+
// ^^ skipping these spaces
|
|
42
|
+
pos++;
|
|
43
|
+
for (; pos < max; pos++) {
|
|
44
|
+
const code = state.src.charCodeAt(pos);
|
|
45
|
+
if (code !== 0x20 && code !== 0x0a) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (pos >= max) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// [link]( <href> "title" )
|
|
54
|
+
// ^^^^^^ parsing link destination
|
|
55
|
+
let start = pos;
|
|
56
|
+
const destResult = md.helpers.parseLinkDestination(state.src, pos, state.posMax);
|
|
57
|
+
if (destResult.ok) {
|
|
58
|
+
href = state.md.normalizeLink(destResult.str);
|
|
59
|
+
if (state.md.validateLink(href)) {
|
|
60
|
+
pos = destResult.pos;
|
|
61
|
+
} else {
|
|
62
|
+
href = '';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// [link]( <href> "title" )
|
|
67
|
+
// ^^ skipping these spaces
|
|
68
|
+
start = pos;
|
|
69
|
+
for (; pos < max; pos++) {
|
|
70
|
+
const code = state.src.charCodeAt(pos);
|
|
71
|
+
if (code !== 0x20 && code !== 0x0a) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// [link]( <href> "title" )
|
|
77
|
+
// ^^^^^^^ parsing link title
|
|
78
|
+
const titleResult = md.helpers.parseLinkTitle(state.src, pos, state.posMax);
|
|
79
|
+
if (pos < max && start !== pos && titleResult.ok) {
|
|
80
|
+
title = titleResult.str;
|
|
81
|
+
pos = titleResult.pos;
|
|
82
|
+
|
|
83
|
+
// [link]( <href> "title" )
|
|
84
|
+
// ^^ skipping these spaces
|
|
85
|
+
for (; pos < max; pos++) {
|
|
86
|
+
const code = state.src.charCodeAt(pos);
|
|
87
|
+
if (code !== 0x20 && code !== 0x0a) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
title = '';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// [link]( <href> "title" =WxH )
|
|
96
|
+
// ^^^^ parsing image size
|
|
97
|
+
if (pos - 1 >= 0) {
|
|
98
|
+
const code = state.src.charCodeAt(pos - 1);
|
|
99
|
+
|
|
100
|
+
// there must be at least one white spaces
|
|
101
|
+
// between previous field and the size
|
|
102
|
+
if (code === 0x20) {
|
|
103
|
+
const sizeResult = parseImageSize(state.src, pos, state.posMax);
|
|
104
|
+
if (sizeResult.ok) {
|
|
105
|
+
width = sizeResult.width;
|
|
106
|
+
height = sizeResult.height;
|
|
107
|
+
pos = sizeResult.pos;
|
|
108
|
+
|
|
109
|
+
// [link]( <href> "title" =WxH )
|
|
110
|
+
// ^^ skipping these spaces
|
|
111
|
+
for (; pos < max; pos++) {
|
|
112
|
+
const code = state.src.charCodeAt(pos);
|
|
113
|
+
// eslint-disable-next-line max-depth
|
|
114
|
+
if (code !== 0x20 && code !== 0x0a) {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (pos >= max || state.src.charCodeAt(pos) !== 0x29 /* ) */) {
|
|
123
|
+
state.pos = oldPos;
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
pos++;
|
|
127
|
+
} else {
|
|
128
|
+
//
|
|
129
|
+
// Link reference
|
|
130
|
+
//
|
|
131
|
+
if (typeof state.env.references === 'undefined') {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// [foo] [bar]
|
|
136
|
+
// ^^ optional whitespace (can include newlines)
|
|
137
|
+
for (; pos < max; pos++) {
|
|
138
|
+
const code = state.src.charCodeAt(pos);
|
|
139
|
+
if (code !== 0x20 && code !== 0x0a) {
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let label = '';
|
|
145
|
+
|
|
146
|
+
if (pos < max && state.src.charCodeAt(pos) === 0x5b /* [ */) {
|
|
147
|
+
const start = pos + 1;
|
|
148
|
+
pos = md.helpers.parseLinkLabel(state, pos);
|
|
149
|
+
if (pos >= 0) {
|
|
150
|
+
label = state.src.slice(start, pos++);
|
|
151
|
+
} else {
|
|
152
|
+
pos = labelEnd + 1;
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
pos = labelEnd + 1;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// covers label === '' and label === undefined
|
|
159
|
+
// (collapsed reference link and shortcut reference link respectively)
|
|
160
|
+
if (!label) {
|
|
161
|
+
label = state.src.slice(labelStart, labelEnd);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const ref = state.env.references[md.utils.normalizeReference(label)];
|
|
165
|
+
if (!ref) {
|
|
166
|
+
state.pos = oldPos;
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
href = ref.href;
|
|
170
|
+
title = ref.title;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//
|
|
174
|
+
// We found the end of the link, and know for a fact it's a valid link;
|
|
175
|
+
// so all that's left to do is to call tokenizer.
|
|
176
|
+
//
|
|
177
|
+
if (!silent) {
|
|
178
|
+
state.pos = labelStart;
|
|
179
|
+
state.posMax = labelEnd;
|
|
180
|
+
|
|
181
|
+
const tokens: Token[] = [];
|
|
182
|
+
const newState = new state.md.inline.State(
|
|
183
|
+
state.src.slice(labelStart, labelEnd),
|
|
184
|
+
state.md,
|
|
185
|
+
state.env,
|
|
186
|
+
tokens,
|
|
187
|
+
);
|
|
188
|
+
newState.md.inline.tokenize(newState);
|
|
189
|
+
|
|
190
|
+
const token = state.push('image', 'img', 0);
|
|
191
|
+
token.children = tokens;
|
|
192
|
+
token.attrs = [
|
|
193
|
+
[ImsizeAttr.Src, href],
|
|
194
|
+
[ImsizeAttr.Alt, ''],
|
|
195
|
+
];
|
|
196
|
+
|
|
197
|
+
if (title) {
|
|
198
|
+
token.attrs.push([ImsizeAttr.Title, title]);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (width !== '') {
|
|
202
|
+
token.attrs.push([ImsizeAttr.Width, width]);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (height !== '') {
|
|
206
|
+
token.attrs.push([ImsizeAttr.Height, height]);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
state.pos = pos;
|
|
211
|
+
state.posMax = max;
|
|
212
|
+
return true;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {relative} from 'path';
|
|
2
|
+
import {bold} from 'chalk';
|
|
3
|
+
|
|
4
|
+
import {isFileExists, resolveRelativePath} from '../../utilsFS';
|
|
5
|
+
import {MarkdownItPluginOpts} from '../typings';
|
|
6
|
+
|
|
7
|
+
const includesPaths: string[] = [];
|
|
8
|
+
|
|
9
|
+
type Opts = MarkdownItPluginOpts & {
|
|
10
|
+
destPath: string;
|
|
11
|
+
copyFile(path: string, dest: string, opts: Opts): void;
|
|
12
|
+
singlePage: Boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const collect = (input: string, options: Opts) => {
|
|
16
|
+
const {root, path, destPath = '', log, copyFile, singlePage} = options;
|
|
17
|
+
const INCLUDE_REGEXP = /{%\s*include\s*(notitle)?\s*\[(.+?)]\((.+?)\)\s*%}/g;
|
|
18
|
+
|
|
19
|
+
let match,
|
|
20
|
+
result = input;
|
|
21
|
+
|
|
22
|
+
while ((match = INCLUDE_REGEXP.exec(result)) !== null) {
|
|
23
|
+
let [, , , relativePath] = match;
|
|
24
|
+
const [matchedInclude] = match;
|
|
25
|
+
|
|
26
|
+
let includePath = resolveRelativePath(path, relativePath);
|
|
27
|
+
const hashIndex = relativePath.lastIndexOf('#');
|
|
28
|
+
if (hashIndex > -1 && !isFileExists(includePath)) {
|
|
29
|
+
includePath = includePath.slice(0, includePath.lastIndexOf('#'));
|
|
30
|
+
relativePath = relativePath.slice(0, hashIndex);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const targetDestPath = resolveRelativePath(destPath, relativePath);
|
|
34
|
+
|
|
35
|
+
if (includesPaths.includes(includePath)) {
|
|
36
|
+
log.error(`Circular includes: ${bold(includesPaths.concat(path).join(' ▶ '))}`);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (singlePage && !includesPaths.length) {
|
|
41
|
+
const newRelativePath = relative(root, includePath);
|
|
42
|
+
const newInclude = matchedInclude.replace(relativePath, newRelativePath);
|
|
43
|
+
|
|
44
|
+
result = result.replace(matchedInclude, newInclude);
|
|
45
|
+
|
|
46
|
+
const delta = matchedInclude.length - newInclude.length;
|
|
47
|
+
INCLUDE_REGEXP.lastIndex = INCLUDE_REGEXP.lastIndex - delta;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
includesPaths.push(includePath);
|
|
51
|
+
const includeOptions = {
|
|
52
|
+
...options,
|
|
53
|
+
path: includePath,
|
|
54
|
+
destPath: targetDestPath,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
copyFile(includePath, targetDestPath, includeOptions);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
log.error(`No such file or has no access to ${bold(includePath)} in ${bold(path)}`);
|
|
61
|
+
} finally {
|
|
62
|
+
includesPaths.pop();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (singlePage) {
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return null;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export = collect;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {bold} from 'chalk';
|
|
2
|
+
|
|
3
|
+
import {getFileTokens, GetFileTokensOpts, getFullIncludePath, isFileExists} from '../../utilsFS';
|
|
4
|
+
import {findBlockTokens} from '../../utils';
|
|
5
|
+
import Token from 'markdown-it/lib/token';
|
|
6
|
+
import {MarkdownItPluginCb, MarkdownItPluginOpts} from '../typings';
|
|
7
|
+
import {StateCore} from 'src/transform/typings';
|
|
8
|
+
|
|
9
|
+
const INCLUDE_REGEXP = /^{%\s*include\s*(notitle)?\s*\[(.+?)]\((.+?)\)\s*%}$/;
|
|
10
|
+
|
|
11
|
+
function stripTitleTokens(tokens: Token[]) {
|
|
12
|
+
if (tokens[0].type === 'heading_open' && tokens[2].type === 'heading_close') {
|
|
13
|
+
tokens.splice(0, 3);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type Options = MarkdownItPluginOpts &
|
|
18
|
+
GetFileTokensOpts & {
|
|
19
|
+
notFoundCb: (v: string) => void;
|
|
20
|
+
noReplaceInclude: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function unfoldIncludes(state: StateCore, path: string, options: Options) {
|
|
24
|
+
const {root, notFoundCb, log, noReplaceInclude = false} = options;
|
|
25
|
+
const {tokens} = state;
|
|
26
|
+
let i = 0;
|
|
27
|
+
|
|
28
|
+
while (i < tokens.length) {
|
|
29
|
+
const openToken = tokens[i];
|
|
30
|
+
const contentToken = tokens[i + 1];
|
|
31
|
+
const closeToken = tokens[i + 2];
|
|
32
|
+
let match;
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
openToken.type === 'paragraph_open' &&
|
|
36
|
+
contentToken.type === 'inline' &&
|
|
37
|
+
(match = contentToken.content.match(INCLUDE_REGEXP)) &&
|
|
38
|
+
closeToken.type === 'paragraph_close'
|
|
39
|
+
) {
|
|
40
|
+
try {
|
|
41
|
+
const [, keyword /* description */, , includePath] = match;
|
|
42
|
+
|
|
43
|
+
const fullIncludePath = getFullIncludePath(includePath, root, path);
|
|
44
|
+
let pathname = fullIncludePath;
|
|
45
|
+
let hash = '';
|
|
46
|
+
const hashIndex = fullIncludePath.lastIndexOf('#');
|
|
47
|
+
if (hashIndex > -1 && !isFileExists(pathname)) {
|
|
48
|
+
pathname = fullIncludePath.slice(0, hashIndex);
|
|
49
|
+
hash = fullIncludePath.slice(hashIndex + 1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!pathname.startsWith(root)) {
|
|
53
|
+
i++;
|
|
54
|
+
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const fileTokens = getFileTokens(pathname, state, options);
|
|
59
|
+
|
|
60
|
+
let includedTokens;
|
|
61
|
+
if (hash) {
|
|
62
|
+
includedTokens = findBlockTokens(fileTokens, hash);
|
|
63
|
+
} else {
|
|
64
|
+
includedTokens = fileTokens;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (keyword === 'notitle') {
|
|
68
|
+
stripTitleTokens(includedTokens);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (noReplaceInclude) {
|
|
72
|
+
i++;
|
|
73
|
+
} else {
|
|
74
|
+
tokens.splice(i, 3, ...includedTokens);
|
|
75
|
+
|
|
76
|
+
i += includedTokens.length;
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
// @ts-ignore for some reason typescript fails here
|
|
80
|
+
const errPath = e.path.replace(root, '');
|
|
81
|
+
|
|
82
|
+
if (notFoundCb) {
|
|
83
|
+
notFoundCb(errPath);
|
|
84
|
+
}
|
|
85
|
+
log.error(`Skip error: ${e} in ${errPath}`);
|
|
86
|
+
|
|
87
|
+
i++;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
i++;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const index: MarkdownItPluginCb<Options> = (md, options) => {
|
|
96
|
+
const {path: optPath, log} = options;
|
|
97
|
+
|
|
98
|
+
const plugin = (state: StateCore) => {
|
|
99
|
+
const {env} = state;
|
|
100
|
+
const path = env.path || optPath;
|
|
101
|
+
|
|
102
|
+
env.includes = env.includes || [];
|
|
103
|
+
|
|
104
|
+
const isCircularInclude = env.includes.includes(path);
|
|
105
|
+
|
|
106
|
+
if (isCircularInclude && state.env.disableCircularError) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (isCircularInclude) {
|
|
111
|
+
log.error(`Circular includes: ${bold(env.includes.concat(path).join(' ▶ '))}`);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
env.includes.push(path);
|
|
116
|
+
unfoldIncludes(state, path, options);
|
|
117
|
+
env.includes.pop();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
md.core.ruler.before('curly_attributes', 'includes', plugin);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
md.core.ruler.push('includes', plugin);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export = index;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import {sep} from 'path';
|
|
3
|
+
import url from 'url';
|
|
4
|
+
import {getHrefTokenAttr, isLocalUrl} from '../../utils';
|
|
5
|
+
import {getSinglePageAnchorId, resolveRelativePath} from '../../utilsFS';
|
|
6
|
+
import index from './index';
|
|
7
|
+
import {PAGE_LINK_REGEXP} from './constants';
|
|
8
|
+
|
|
9
|
+
const replaceLinkHref = (input: string, href: string, newHref: string) => {
|
|
10
|
+
/* Try not replace include syntax */
|
|
11
|
+
return input.replace(`](${href})`, `](${newHref})`);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type Options = {
|
|
15
|
+
root: string;
|
|
16
|
+
path: string;
|
|
17
|
+
singlePage: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/* Replace the links to the markdown and yaml files if the singlePage option is passed in the options
|
|
21
|
+
* Example: replace [Text](../../path/to/file.md#anchor) with [Text](#_path_to_file_anchor)
|
|
22
|
+
* */
|
|
23
|
+
const collect = (input: string, options: Options) => {
|
|
24
|
+
const {root, path: startPath, singlePage} = options;
|
|
25
|
+
|
|
26
|
+
if (!singlePage) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let result = input;
|
|
31
|
+
|
|
32
|
+
/* Syntax "{% include [Text](_includes/file.md) %}" is parsed as link. Need to ignore errors */
|
|
33
|
+
const needSkipLinkFn = (href: string) => href.includes(`_includes${sep}`);
|
|
34
|
+
const transformLink = (href: string) => href;
|
|
35
|
+
const md = new MarkdownIt().use(index, {...options, transformLink, needSkipLinkFn});
|
|
36
|
+
const tokens = md.parse(result, {});
|
|
37
|
+
|
|
38
|
+
let i = 0;
|
|
39
|
+
while (i < tokens.length) {
|
|
40
|
+
if (tokens[i].type === 'inline') {
|
|
41
|
+
const childrenTokens = tokens[i].children || [];
|
|
42
|
+
let j = 0;
|
|
43
|
+
|
|
44
|
+
while (j < childrenTokens.length) {
|
|
45
|
+
const isLinkOpenToken = childrenTokens[j].type === 'link_open';
|
|
46
|
+
|
|
47
|
+
if (!isLinkOpenToken) {
|
|
48
|
+
j++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const linkToken = childrenTokens[j];
|
|
53
|
+
const href = getHrefTokenAttr(linkToken);
|
|
54
|
+
|
|
55
|
+
const isIncludeLink = resolveRelativePath(startPath, href).includes(
|
|
56
|
+
`_includes${sep}`,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (!href || !isLocalUrl(href) || isIncludeLink) {
|
|
60
|
+
j++;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const {pathname, hash} = url.parse(href);
|
|
65
|
+
if (pathname) {
|
|
66
|
+
const isPageFile = PAGE_LINK_REGEXP.test(pathname);
|
|
67
|
+
if (isPageFile) {
|
|
68
|
+
const newHref = getSinglePageAnchorId({
|
|
69
|
+
root,
|
|
70
|
+
currentPath: startPath,
|
|
71
|
+
pathname,
|
|
72
|
+
hash,
|
|
73
|
+
});
|
|
74
|
+
result = replaceLinkHref(result, href, newHref);
|
|
75
|
+
}
|
|
76
|
+
} else if (hash) {
|
|
77
|
+
const newHref = getSinglePageAnchorId({root, currentPath: startPath, hash});
|
|
78
|
+
result = replaceLinkHref(result, href, newHref);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
j++;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
i++;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// eslint-disable-next-line consistent-return
|
|
89
|
+
return result;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export = collect;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PAGE_LINK_REGEXP = /\.(md|ya?ml)$/i;
|