@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,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs_1 = require("fs");
|
|
3
|
+
const path_1 = require("path");
|
|
4
|
+
const chalk_1 = require("chalk");
|
|
5
|
+
const utilsFS_1 = require("../../utilsFS");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
function replaceImageSrc(token, state, { assetsPublicPath = path_1.sep, root = '', path: optsPath, log }) {
|
|
8
|
+
var _a;
|
|
9
|
+
const src = token.attrGet('src') || '';
|
|
10
|
+
const currentPath = state.env.path || optsPath;
|
|
11
|
+
if (!(0, utils_1.isLocalUrl)(src)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const path = (0, utilsFS_1.resolveRelativePath)(currentPath, src);
|
|
15
|
+
if ((0, utilsFS_1.isFileExists)(path)) {
|
|
16
|
+
(_a = state.md.assets) === null || _a === void 0 ? void 0 : _a.push(path);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
log.error(`Asset not found: ${(0, chalk_1.bold)(src)} in ${(0, chalk_1.bold)(currentPath)}`);
|
|
20
|
+
}
|
|
21
|
+
const relativeToRoot = path.replace(root + path_1.sep, '');
|
|
22
|
+
const publicSrc = (0, path_1.join)(assetsPublicPath, relativeToRoot);
|
|
23
|
+
token.attrSet('src', publicSrc);
|
|
24
|
+
}
|
|
25
|
+
function convertSvg(token, state, { path: optsPath, log, notFoundCb, root }) {
|
|
26
|
+
const currentPath = state.env.path || optsPath;
|
|
27
|
+
const path = (0, utilsFS_1.resolveRelativePath)(currentPath, token.attrGet('src') || '');
|
|
28
|
+
try {
|
|
29
|
+
const content = (0, fs_1.readFileSync)(path, 'utf8');
|
|
30
|
+
const svgToken = new state.Token('image_svg', '', 0);
|
|
31
|
+
svgToken.attrSet('content', content);
|
|
32
|
+
return svgToken;
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
log.error(`SVG ${path} from ${currentPath} not found`);
|
|
36
|
+
if (notFoundCb) {
|
|
37
|
+
notFoundCb(path.replace(root, ''));
|
|
38
|
+
}
|
|
39
|
+
return token;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const index = (md, opts) => {
|
|
43
|
+
md.assets = [];
|
|
44
|
+
const plugin = (state) => {
|
|
45
|
+
const tokens = state.tokens;
|
|
46
|
+
let i = 0;
|
|
47
|
+
while (i < tokens.length) {
|
|
48
|
+
if (tokens[i].type !== 'inline') {
|
|
49
|
+
i++;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const childrenTokens = tokens[i].children || [];
|
|
53
|
+
let j = 0;
|
|
54
|
+
while (j < childrenTokens.length) {
|
|
55
|
+
if (childrenTokens[j].type === 'image') {
|
|
56
|
+
const imgSrc = childrenTokens[j].attrGet('src') || '';
|
|
57
|
+
if (imgSrc.endsWith('.svg') && !(0, utils_1.isExternalHref)(imgSrc)) {
|
|
58
|
+
childrenTokens[j] = convertSvg(childrenTokens[j], state, opts);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
replaceImageSrc(childrenTokens[j], state, opts);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
j++;
|
|
65
|
+
}
|
|
66
|
+
i++;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
md.core.ruler.before('includes', 'images', plugin);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
md.core.ruler.push('images', plugin);
|
|
74
|
+
}
|
|
75
|
+
md.renderer.rules.image_svg = (tokens, index) => {
|
|
76
|
+
const token = tokens[index];
|
|
77
|
+
return token.attrGet('content') || '';
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
module.exports = index;
|
|
81
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/images/index.ts"],"names":[],"mappings":";AAAA,2BAAgC;AAChC,+BAA+B;AAC/B,iCAA2B;AAE3B,2CAAgE;AAChE,uCAAuD;AASvD,SAAS,eAAe,CACpB,KAAY,EACZ,KAAgB,EAChB,EAAC,gBAAgB,GAAG,UAAG,EAAE,IAAI,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAY;;IAEnE,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACvC,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,QAAQ,CAAC;IAE/C,IAAI,CAAC,IAAA,kBAAU,EAAC,GAAG,CAAC,EAAE;QAClB,OAAO;KACV;IAED,MAAM,IAAI,GAAG,IAAA,6BAAmB,EAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAEnD,IAAI,IAAA,sBAAY,EAAC,IAAI,CAAC,EAAE;QACpB,MAAA,KAAK,CAAC,EAAE,CAAC,MAAM,0CAAE,IAAI,CAAC,IAAI,CAAC,CAAC;KAC/B;SAAM;QACH,GAAG,CAAC,KAAK,CAAC,oBAAoB,IA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AAQ,EAAE,MAAM,CAAC,CAAC;KACxC;IAED,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAE5B,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC,CAAC;AACN,CAAC,CAAC;AAEF,iBAAS,KAAK,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImsizeAttr = void 0;
|
|
4
|
+
var ImsizeAttr;
|
|
5
|
+
(function (ImsizeAttr) {
|
|
6
|
+
ImsizeAttr["Src"] = "src";
|
|
7
|
+
ImsizeAttr["Alt"] = "alt";
|
|
8
|
+
ImsizeAttr["Title"] = "title";
|
|
9
|
+
ImsizeAttr["Width"] = "width";
|
|
10
|
+
ImsizeAttr["Height"] = "height";
|
|
11
|
+
})(ImsizeAttr = exports.ImsizeAttr || (exports.ImsizeAttr = {}));
|
|
12
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/transform/plugins/imsize/const.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAMX;AAND,WAAY,UAAU;IAClB,yBAAW,CAAA;IACX,yBAAW,CAAA;IACX,6BAAe,CAAA;IACf,6BAAe,CAAA;IACf,+BAAiB,CAAA;AACrB,CAAC,EANW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAMrB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseImageSize = void 0;
|
|
4
|
+
/* eslint-disable no-param-reassign */
|
|
5
|
+
function parseImageSize(str, pos, max) {
|
|
6
|
+
const result = {
|
|
7
|
+
ok: false,
|
|
8
|
+
pos: 0,
|
|
9
|
+
width: '',
|
|
10
|
+
height: '',
|
|
11
|
+
};
|
|
12
|
+
if (pos >= max) {
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
let code = str.charCodeAt(pos);
|
|
16
|
+
if (code !== 0x3d /* = */) {
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
pos++;
|
|
20
|
+
// size must follow = without any white spaces as follows
|
|
21
|
+
// (1) =300x200
|
|
22
|
+
// (2) =300x
|
|
23
|
+
// (3) =x200
|
|
24
|
+
code = str.charCodeAt(pos);
|
|
25
|
+
if (code !== 0x78 /* x */ && (code < 0x30 || code > 0x39) /* [0-9] */) {
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
// parse width
|
|
29
|
+
const resultW = parseNextNumber(str, pos, max);
|
|
30
|
+
pos = resultW.pos;
|
|
31
|
+
// next charactor must be 'x'
|
|
32
|
+
code = str.charCodeAt(pos);
|
|
33
|
+
if (code !== 0x78 /* x */) {
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
pos++;
|
|
37
|
+
// parse height
|
|
38
|
+
const resultH = parseNextNumber(str, pos, max);
|
|
39
|
+
pos = resultH.pos;
|
|
40
|
+
result.width = resultW.value;
|
|
41
|
+
result.height = resultH.value;
|
|
42
|
+
result.pos = pos;
|
|
43
|
+
result.ok = true;
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
exports.parseImageSize = parseImageSize;
|
|
47
|
+
function parseNextNumber(str, pos, max) {
|
|
48
|
+
let code;
|
|
49
|
+
const start = pos;
|
|
50
|
+
const result = {
|
|
51
|
+
pos,
|
|
52
|
+
ok: false,
|
|
53
|
+
value: '',
|
|
54
|
+
};
|
|
55
|
+
code = str.charCodeAt(pos);
|
|
56
|
+
while ((pos < max && code >= 0x30 /* 0 */ && code <= 0x39) /* 9 */ || code === 0x25 /* % */) {
|
|
57
|
+
code = str.charCodeAt(++pos);
|
|
58
|
+
}
|
|
59
|
+
result.ok = true;
|
|
60
|
+
result.pos = pos;
|
|
61
|
+
result.value = str.slice(start, pos);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/transform/plugins/imsize/helpers.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,SAAgB,cAAc,CAAC,GAAW,EAAE,GAAW,EAAE,GAAW;IAChE,MAAM,MAAM,GAAG;QACX,EAAE,EAAE,KAAK;QACT,GAAG,EAAE,CAAC;QACN,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;KACb,CAAC;IAEF,IAAI,GAAG,IAAI,GAAG,EAAE;QACZ,OAAO,MAAM,CAAC;KACjB;IAED,IAAI,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAE/B,IAAI,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE;QACvB,OAAO,MAAM,CAAC;KACjB;IAED,GAAG,EAAE,CAAC;IAEN,yDAAyD;IACzD,eAAe;IACf,YAAY;IACZ,YAAY;IACZ,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,IAAI,KAAK,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE;QACnE,OAAO,MAAM,CAAC;KACjB;IAED,cAAc;IACd,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC/C,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAElB,6BAA6B;IAC7B,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,IAAI,KAAK,IAAI,CAAC,OAAO,E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|
|
4
|
+
* Imsize plugin for markdown-it.
|
|
5
|
+
* This plugin overloads original image renderer.
|
|
6
|
+
* Forked from https://github.com/tatsy/markdown-it-imsize
|
|
7
|
+
*/
|
|
8
|
+
const imsize = (md) => {
|
|
9
|
+
md.inline.ruler.before('emphasis', 'image', (0, plugin_1.imageWithSize)(md));
|
|
10
|
+
};
|
|
11
|
+
module.exports = imsize;
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/imsize/index.ts"],"names":[],"mappings":";AACA,qCAAuC;AAEvC;;;;GAIG;AAEH,MAAM,MAAM,GAAiB,CAAC,EAAE,EAAE,EAAE;IAChC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,IAAA,sBAAa,EAAC,EAAE,CAAC,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,iBAAS,MAAM,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imageWithSize = void 0;
|
|
4
|
+
const const_1 = require("./const");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const imageWithSize = (md) => {
|
|
7
|
+
// eslint-disable-next-line complexity
|
|
8
|
+
return (state, silent) => {
|
|
9
|
+
if (state.src.charCodeAt(state.pos) !== 0x21 /* ! */) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (state.src.charCodeAt(state.pos + 1) !== 0x5b /* [ */) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const labelStart = state.pos + 2;
|
|
16
|
+
const labelEnd = md.helpers.parseLinkLabel(state, state.pos + 1, false);
|
|
17
|
+
// parser failed to find ']', so it's not a valid link
|
|
18
|
+
if (labelEnd < 0) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
let href = '';
|
|
22
|
+
let title = '';
|
|
23
|
+
let width = '';
|
|
24
|
+
let height = '';
|
|
25
|
+
const oldPos = state.pos;
|
|
26
|
+
const max = state.posMax;
|
|
27
|
+
let pos = labelEnd + 1;
|
|
28
|
+
if (pos < max && state.src.charCodeAt(pos) === 0x28 /* ( */) {
|
|
29
|
+
//
|
|
30
|
+
// Inline link
|
|
31
|
+
//
|
|
32
|
+
// [link]( <href> "title" )
|
|
33
|
+
// ^^ skipping these spaces
|
|
34
|
+
pos++;
|
|
35
|
+
for (; pos < max; pos++) {
|
|
36
|
+
const code = state.src.charCodeAt(pos);
|
|
37
|
+
if (code !== 0x20 && code !== 0x0a) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (pos >= max) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
// [link]( <href> "title" )
|
|
45
|
+
// ^^^^^^ parsing link destination
|
|
46
|
+
let start = pos;
|
|
47
|
+
const destResult = md.helpers.parseLinkDestination(state.src, pos, state.posMax);
|
|
48
|
+
if (destResult.ok) {
|
|
49
|
+
href = state.md.normalizeLink(destResult.str);
|
|
50
|
+
if (state.md.validateLink(href)) {
|
|
51
|
+
pos = destResult.pos;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
href = '';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// [link]( <href> "title" )
|
|
58
|
+
// ^^ skipping these spaces
|
|
59
|
+
start = pos;
|
|
60
|
+
for (; pos < max; pos++) {
|
|
61
|
+
const code = state.src.charCodeAt(pos);
|
|
62
|
+
if (code !== 0x20 && code !== 0x0a) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// [link]( <href> "title" )
|
|
67
|
+
// ^^^^^^^ parsing link title
|
|
68
|
+
const titleResult = md.helpers.parseLinkTitle(state.src, pos, state.posMax);
|
|
69
|
+
if (pos < max && start !== pos && titleResult.ok) {
|
|
70
|
+
title = titleResult.str;
|
|
71
|
+
pos = titleResult.pos;
|
|
72
|
+
// [link]( <href> "title" )
|
|
73
|
+
// ^^ skipping these spaces
|
|
74
|
+
for (; pos < max; pos++) {
|
|
75
|
+
const code = state.src.charCodeAt(pos);
|
|
76
|
+
if (code !== 0x20 && code !== 0x0a) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
title = '';
|
|
83
|
+
}
|
|
84
|
+
// [link]( <href> "title" =WxH )
|
|
85
|
+
// ^^^^ parsing image size
|
|
86
|
+
if (pos - 1 >= 0) {
|
|
87
|
+
const code = state.src.charCodeAt(pos - 1);
|
|
88
|
+
// there must be at least one white spaces
|
|
89
|
+
// between previous field and the size
|
|
90
|
+
if (code === 0x20) {
|
|
91
|
+
const sizeResult = (0, helpers_1.parseImageSize)(state.src, pos, state.posMax);
|
|
92
|
+
if (sizeResult.ok) {
|
|
93
|
+
width = sizeResult.width;
|
|
94
|
+
height = sizeResult.height;
|
|
95
|
+
pos = sizeResult.pos;
|
|
96
|
+
// [link]( <href> "title" =WxH )
|
|
97
|
+
// ^^ skipping these spaces
|
|
98
|
+
for (; pos < max; pos++) {
|
|
99
|
+
const code = state.src.charCodeAt(pos);
|
|
100
|
+
// eslint-disable-next-line max-depth
|
|
101
|
+
if (code !== 0x20 && code !== 0x0a) {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (pos >= max || state.src.charCodeAt(pos) !== 0x29 /* ) */) {
|
|
109
|
+
state.pos = oldPos;
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
pos++;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
//
|
|
116
|
+
// Link reference
|
|
117
|
+
//
|
|
118
|
+
if (typeof state.env.references === 'undefined') {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
// [foo] [bar]
|
|
122
|
+
// ^^ optional whitespace (can include newlines)
|
|
123
|
+
for (; pos < max; pos++) {
|
|
124
|
+
const code = state.src.charCodeAt(pos);
|
|
125
|
+
if (code !== 0x20 && code !== 0x0a) {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
let label = '';
|
|
130
|
+
if (pos < max && state.src.charCodeAt(pos) === 0x5b /* [ */) {
|
|
131
|
+
const start = pos + 1;
|
|
132
|
+
pos = md.helpers.parseLinkLabel(state, pos);
|
|
133
|
+
if (pos >= 0) {
|
|
134
|
+
label = state.src.slice(start, pos++);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
pos = labelEnd + 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
pos = labelEnd + 1;
|
|
142
|
+
}
|
|
143
|
+
// covers label === '' and label === undefined
|
|
144
|
+
// (collapsed reference link and shortcut reference link respectively)
|
|
145
|
+
if (!label) {
|
|
146
|
+
label = state.src.slice(labelStart, labelEnd);
|
|
147
|
+
}
|
|
148
|
+
const ref = state.env.references[md.utils.normalizeReference(label)];
|
|
149
|
+
if (!ref) {
|
|
150
|
+
state.pos = oldPos;
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
href = ref.href;
|
|
154
|
+
title = ref.title;
|
|
155
|
+
}
|
|
156
|
+
//
|
|
157
|
+
// We found the end of the link, and know for a fact it's a valid link;
|
|
158
|
+
// so all that's left to do is to call tokenizer.
|
|
159
|
+
//
|
|
160
|
+
if (!silent) {
|
|
161
|
+
state.pos = labelStart;
|
|
162
|
+
state.posMax = labelEnd;
|
|
163
|
+
const tokens = [];
|
|
164
|
+
const newState = new state.md.inline.State(state.src.slice(labelStart, labelEnd), state.md, state.env, tokens);
|
|
165
|
+
newState.md.inline.tokenize(newState);
|
|
166
|
+
const token = state.push('image', 'img', 0);
|
|
167
|
+
token.children = tokens;
|
|
168
|
+
token.attrs = [
|
|
169
|
+
[const_1.ImsizeAttr.Src, href],
|
|
170
|
+
[const_1.ImsizeAttr.Alt, ''],
|
|
171
|
+
];
|
|
172
|
+
if (title) {
|
|
173
|
+
token.attrs.push([const_1.ImsizeAttr.Title, title]);
|
|
174
|
+
}
|
|
175
|
+
if (width !== '') {
|
|
176
|
+
token.attrs.push([const_1.ImsizeAttr.Width, width]);
|
|
177
|
+
}
|
|
178
|
+
if (height !== '') {
|
|
179
|
+
token.attrs.push([const_1.ImsizeAttr.Height, height]);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
state.pos = pos;
|
|
183
|
+
state.posMax = max;
|
|
184
|
+
return true;
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
exports.imageWithSize = imageWithSize;
|
|
188
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/transform/plugins/imsize/plugin.ts"],"names":[],"mappings":";;;AAGA,mCAAmC;AACnC,uCAAyC;AAElC,MAAM,aAAa,GAAG,CAAC,EAAc,EAA2B,EAAE;IACrE,sCAAsC;IACtC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QACrB,IAAI,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE;YAClD,OAAO,KAAK,CAAC;SAChB;QAED,IAAI,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE;YACtD,OAAO,KAAK,CAAC;SAChB;QAED,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC;QACjC,MAAM,QAAQ,GAAG,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,EAAE,KAAK,CA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File(path: string, dest: string, opts: Opts): void;
|
|
5
|
+
singlePage: Boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const collect: (input: string, options: Opts) => string | null;
|
|
8
|
+
export = collect;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const path_1 = require("path");
|
|
3
|
+
const chalk_1 = require("chalk");
|
|
4
|
+
const utilsFS_1 = require("../../utilsFS");
|
|
5
|
+
const includesPaths = [];
|
|
6
|
+
const collect = (input, options) => {
|
|
7
|
+
const { root, path, destPath = '', log, copyFile, singlePage } = options;
|
|
8
|
+
const INCLUDE_REGEXP = /{%\s*include\s*(notitle)?\s*\[(.+?)]\((.+?)\)\s*%}/g;
|
|
9
|
+
let match, result = input;
|
|
10
|
+
while ((match = INCLUDE_REGEXP.exec(result)) !== null) {
|
|
11
|
+
let [, , , relativePath] = match;
|
|
12
|
+
const [matchedInclude] = match;
|
|
13
|
+
let includePath = (0, utilsFS_1.resolveRelativePath)(path, relativePath);
|
|
14
|
+
const hashIndex = relativePath.lastIndexOf('#');
|
|
15
|
+
if (hashIndex > -1 && !(0, utilsFS_1.isFileExists)(includePath)) {
|
|
16
|
+
includePath = includePath.slice(0, includePath.lastIndexOf('#'));
|
|
17
|
+
relativePath = relativePath.slice(0, hashIndex);
|
|
18
|
+
}
|
|
19
|
+
const targetDestPath = (0, utilsFS_1.resolveRelativePath)(destPath, relativePath);
|
|
20
|
+
if (includesPaths.includes(includePath)) {
|
|
21
|
+
log.error(`Circular includes: ${(0, chalk_1.bold)(includesPaths.concat(path).join(' ▶ '))}`);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
if (singlePage && !includesPaths.length) {
|
|
25
|
+
const newRelativePath = (0, path_1.relative)(root, includePath);
|
|
26
|
+
const newInclude = matchedInclude.replace(relativePath, newRelativePath);
|
|
27
|
+
result = result.replace(matchedInclude, newInclude);
|
|
28
|
+
const delta = matchedInclude.length - newInclude.length;
|
|
29
|
+
INCLUDE_REGEXP.lastIndex = INCLUDE_REGEXP.lastIndex - delta;
|
|
30
|
+
}
|
|
31
|
+
includesPaths.push(includePath);
|
|
32
|
+
const includeOptions = Object.assign(Object.assign({}, options), { path: includePath, destPath: targetDestPath });
|
|
33
|
+
try {
|
|
34
|
+
copyFile(includePath, targetDestPath, includeOptions);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
log.error(`No such file or has no access to ${(0, chalk_1.bold)(includePath)} in ${(0, chalk_1.bold)(path)}`);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
includesPaths.pop();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (singlePage) {
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
48
|
+
module.exports = collect;
|
|
49
|
+
//# sourceMappingURL=collect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect.js","sourceRoot":"","sources":["../../../src/transform/plugins/includes/collect.ts"],"names":[],"mappings":";AAAA,+BAA8B;AAC9B,iCAA2B;AAE3B,2CAAgE;AAGhE,MAAM,aAAa,GAAa,EAAE,CAAC;AAQnC,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,OAAa,EAAE,EAAE;IAC7C,MAAM,EAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAC,GAAG,OAAO,CAAC;IACvE,MAAM,cAAc,GAAG,qDAAqD,CAAC;IAE7E,IAAI,KAAK,EACL,MAAM,GAAG,KAAK,CAAC;IAEnB,OAAO,CAAC,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE;QACnD,IAAI,CAAC,EAAE,AAAD,EAAG,AAAD,EAAG,YAAY,CAAC,GAAG,KAAK,CAAC;QACjC,MAAM,CAAC,cAAc,CAAC,GAAG,KAAK,CAAC;QAE/B,IA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,EAAE,cAAc,GAC3B,CAAC;QAEF,IAAI;YACA,QAAQ,CAAC,WAAW,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;SACzD;QAAC,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,KAAK,CAAC,oCAAoC,IAAA,YAAI,EAAC,WAAW,CAAC,OAAO,IAAA,YAAI,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SACvF;gBAAS;YACN,aAAa,CAAC,GAAG,EAAE,CAAC;SACvB;KACJ;IAED,IAAI,UAAU,EAAE;QACZ,OAAO,MAAM,CAAC;KACjB;IAED,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,iBAAS,OAAO,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GetFileTokensOpts } from '../../utilsFS';
|
|
2
|
+
import { MarkdownItPluginCb, MarkdownItPluginOpts } from '../typings';
|
|
3
|
+
declare type Options = MarkdownItPluginOpts & GetFileTokensOpts & {
|
|
4
|
+
notFoundCb: (v: string) => void;
|
|
5
|
+
noReplaceInclude: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const index: MarkdownItPluginCb<Options>;
|
|
8
|
+
export = index;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const chalk_1 = require("chalk");
|
|
3
|
+
const utilsFS_1 = require("../../utilsFS");
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const INCLUDE_REGEXP = /^{%\s*include\s*(notitle)?\s*\[(.+?)]\((.+?)\)\s*%}$/;
|
|
6
|
+
function stripTitleTokens(tokens) {
|
|
7
|
+
if (tokens[0].type === 'heading_open' && tokens[2].type === 'heading_close') {
|
|
8
|
+
tokens.splice(0, 3);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function unfoldIncludes(state, path, options) {
|
|
12
|
+
const { root, notFoundCb, log, noReplaceInclude = false } = options;
|
|
13
|
+
const { tokens } = state;
|
|
14
|
+
let i = 0;
|
|
15
|
+
while (i < tokens.length) {
|
|
16
|
+
const openToken = tokens[i];
|
|
17
|
+
const contentToken = tokens[i + 1];
|
|
18
|
+
const closeToken = tokens[i + 2];
|
|
19
|
+
let match;
|
|
20
|
+
if (openToken.type === 'paragraph_open' &&
|
|
21
|
+
contentToken.type === 'inline' &&
|
|
22
|
+
(match = contentToken.content.match(INCLUDE_REGEXP)) &&
|
|
23
|
+
closeToken.type === 'paragraph_close') {
|
|
24
|
+
try {
|
|
25
|
+
const [, keyword /* description */, , includePath] = match;
|
|
26
|
+
const fullIncludePath = (0, utilsFS_1.getFullIncludePath)(includePath, root, path);
|
|
27
|
+
let pathname = fullIncludePath;
|
|
28
|
+
let hash = '';
|
|
29
|
+
const hashIndex = fullIncludePath.lastIndexOf('#');
|
|
30
|
+
if (hashIndex > -1 && !(0, utilsFS_1.isFileExists)(pathname)) {
|
|
31
|
+
pathname = fullIncludePath.slice(0, hashIndex);
|
|
32
|
+
hash = fullIncludePath.slice(hashIndex + 1);
|
|
33
|
+
}
|
|
34
|
+
if (!pathname.startsWith(root)) {
|
|
35
|
+
i++;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const fileTokens = (0, utilsFS_1.getFileTokens)(pathname, state, options);
|
|
39
|
+
let includedTokens;
|
|
40
|
+
if (hash) {
|
|
41
|
+
includedTokens = (0, utils_1.findBlockTokens)(fileTokens, hash);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
includedTokens = fileTokens;
|
|
45
|
+
}
|
|
46
|
+
if (keyword === 'notitle') {
|
|
47
|
+
stripTitleTokens(includedTokens);
|
|
48
|
+
}
|
|
49
|
+
if (noReplaceInclude) {
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
tokens.splice(i, 3, ...includedTokens);
|
|
54
|
+
i += includedTokens.length;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
// @ts-ignore for some reason typescript fails here
|
|
59
|
+
const errPath = e.path.replace(root, '');
|
|
60
|
+
if (notFoundCb) {
|
|
61
|
+
notFoundCb(errPath);
|
|
62
|
+
}
|
|
63
|
+
log.error(`Skip error: ${e} in ${errPath}`);
|
|
64
|
+
i++;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
i++;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const index = (md, options) => {
|
|
73
|
+
const { path: optPath, log } = options;
|
|
74
|
+
const plugin = (state) => {
|
|
75
|
+
const { env } = state;
|
|
76
|
+
const path = env.path || optPath;
|
|
77
|
+
env.includes = env.includes || [];
|
|
78
|
+
const isCircularInclude = env.includes.includes(path);
|
|
79
|
+
if (isCircularInclude && state.env.disableCircularError) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (isCircularInclude) {
|
|
83
|
+
log.error(`Circular includes: ${(0, chalk_1.bold)(env.includes.concat(path).join(' ▶ '))}`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
env.includes.push(path);
|
|
87
|
+
unfoldIncludes(state, path, options);
|
|
88
|
+
env.includes.pop();
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
md.core.ruler.before('curly_attributes', 'includes', plugin);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
md.core.ruler.push('includes', plugin);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
module.exports = index;
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/includes/index.ts"],"names":[],"mappings":";AAAA,iCAA2B;AAE3B,2CAAiG;AACjG,uCAA4C;AAK5C,MAAM,cAAc,GAAG,sDAAsD,CAAC;AAE9E,SAAS,gBAAgB,CAAC,MAAe;IACrC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAA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