@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,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const markdown_it_1 = __importDefault(require("markdown-it"));
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const url_1 = __importDefault(require("url"));
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const utilsFS_1 = require("../../utilsFS");
|
|
10
|
+
const index_1 = __importDefault(require("./index"));
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
const replaceLinkHref = (input, href, newHref) => {
|
|
13
|
+
/* Try not replace include syntax */
|
|
14
|
+
return input.replace(`](${href})`, `](${newHref})`);
|
|
15
|
+
};
|
|
16
|
+
/* Replace the links to the markdown and yaml files if the singlePage option is passed in the options
|
|
17
|
+
* Example: replace [Text](../../path/to/file.md#anchor) with [Text](#_path_to_file_anchor)
|
|
18
|
+
* */
|
|
19
|
+
const collect = (input, options) => {
|
|
20
|
+
const { root, path: startPath, singlePage } = options;
|
|
21
|
+
if (!singlePage) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
let result = input;
|
|
25
|
+
/* Syntax "{% include [Text](_includes/file.md) %}" is parsed as link. Need to ignore errors */
|
|
26
|
+
const needSkipLinkFn = (href) => href.includes(`_includes${path_1.sep}`);
|
|
27
|
+
const transformLink = (href) => href;
|
|
28
|
+
const md = new markdown_it_1.default().use(index_1.default, Object.assign(Object.assign({}, options), { transformLink, needSkipLinkFn }));
|
|
29
|
+
const tokens = md.parse(result, {});
|
|
30
|
+
let i = 0;
|
|
31
|
+
while (i < tokens.length) {
|
|
32
|
+
if (tokens[i].type === 'inline') {
|
|
33
|
+
const childrenTokens = tokens[i].children || [];
|
|
34
|
+
let j = 0;
|
|
35
|
+
while (j < childrenTokens.length) {
|
|
36
|
+
const isLinkOpenToken = childrenTokens[j].type === 'link_open';
|
|
37
|
+
if (!isLinkOpenToken) {
|
|
38
|
+
j++;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const linkToken = childrenTokens[j];
|
|
42
|
+
const href = (0, utils_1.getHrefTokenAttr)(linkToken);
|
|
43
|
+
const isIncludeLink = (0, utilsFS_1.resolveRelativePath)(startPath, href).includes(`_includes${path_1.sep}`);
|
|
44
|
+
if (!href || !(0, utils_1.isLocalUrl)(href) || isIncludeLink) {
|
|
45
|
+
j++;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const { pathname, hash } = url_1.default.parse(href);
|
|
49
|
+
if (pathname) {
|
|
50
|
+
const isPageFile = constants_1.PAGE_LINK_REGEXP.test(pathname);
|
|
51
|
+
if (isPageFile) {
|
|
52
|
+
const newHref = (0, utilsFS_1.getSinglePageAnchorId)({
|
|
53
|
+
root,
|
|
54
|
+
currentPath: startPath,
|
|
55
|
+
pathname,
|
|
56
|
+
hash,
|
|
57
|
+
});
|
|
58
|
+
result = replaceLinkHref(result, href, newHref);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (hash) {
|
|
62
|
+
const newHref = (0, utilsFS_1.getSinglePageAnchorId)({ root, currentPath: startPath, hash });
|
|
63
|
+
result = replaceLinkHref(result, href, newHref);
|
|
64
|
+
}
|
|
65
|
+
j++;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
i++;
|
|
69
|
+
}
|
|
70
|
+
// eslint-disable-next-line consistent-return
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
module.exports = collect;
|
|
74
|
+
//# sourceMappingURL=collect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect.js","sourceRoot":"","sources":["../../../src/transform/plugins/links/collect.ts"],"names":[],"mappings":";;;;AAAA,8DAAqC;AACrC,+BAAyB;AACzB,8CAAsB;AACtB,uCAAyD;AACzD,2CAAyE;AACzE,oDAA4B;AAC5B,2CAA6C;AAE7C,MAAM,eAAe,GAAG,CAAC,KAAa,EAAE,IAAY,EAAE,OAAe,EAAE,EAAE;IACrE,oCAAoC;IACpC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,GAAG,EAAE,KAAK,OAAO,GAAG,CAAC,CAAC;AACxD,CAAC,CAAC;AAQF;;KAEK;AACL,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,OAAgB,EAAE,EAAE;IAChD,MAAM,EAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAC,GAAG,OAAO,CAAC;IAEpD,IAAI,CAAC,UAAU,EAAE;QACb,OAAO;KACV;IAED,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,+FAA+F;IAC/F,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,UAAG,EAAE,CAAC,CAAC;IAC1E,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC;IAC7C,MAAM,EAAE,GAAG,IAAI,qBAAU,EAAE,CAA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G,IAAA,+BAAqB,EAAC;4BAClC,IAAI;4BACJ,WAAW,EAAE,SAAS;4BACtB,QAAQ;4BACR,IAAI;yBACP,CAAC,CAAC;wBACH,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;qBACnD;iBACJ;qBAAM,IAAI,IAAI,EAAE;oBACb,MAAM,OAAO,GAAG,IAAA,+BAAqB,EAAC,EAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;oBAC5E,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;iBACnD;gBAED,CAAC,EAAE,CAAC;aACP;SACJ;QAED,CAAC,EAAE,CAAC;KACP;IAED,6CAA6C;IAC7C,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,iBAAS,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PAGE_LINK_REGEXP: RegExp;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/transform/plugins/links/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Token from 'markdown-it/lib/token';
|
|
2
|
+
import { Logger } from 'src/transform/log';
|
|
3
|
+
import { MarkdownItPluginCb, MarkdownItPluginOpts } from '../typings';
|
|
4
|
+
import { StateCore } from 'src/transform/typings';
|
|
5
|
+
declare type Options = {
|
|
6
|
+
hash: string | null;
|
|
7
|
+
file: string;
|
|
8
|
+
state: StateCore;
|
|
9
|
+
opts: object;
|
|
10
|
+
isEmptyLink: boolean;
|
|
11
|
+
tokens: Token[];
|
|
12
|
+
idx: number;
|
|
13
|
+
nextToken: Token;
|
|
14
|
+
href: string;
|
|
15
|
+
currentPath: string;
|
|
16
|
+
log: Logger;
|
|
17
|
+
};
|
|
18
|
+
interface ProcOpts extends MarkdownItPluginOpts {
|
|
19
|
+
transformLink: (v: string) => string;
|
|
20
|
+
notFoundCb: (v: string) => void;
|
|
21
|
+
needSkipLinkFn: (v: string) => boolean;
|
|
22
|
+
}
|
|
23
|
+
declare const index: MarkdownItPluginCb<ProcOpts & Options>;
|
|
24
|
+
export = index;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
const url_1 = __importDefault(require("url"));
|
|
29
|
+
const chalk_1 = require("chalk");
|
|
30
|
+
const utils_1 = require("../../utils");
|
|
31
|
+
const utilsFS_1 = require("../../utilsFS");
|
|
32
|
+
const constants_1 = require("./constants");
|
|
33
|
+
const path_1 = __importStar(require("path"));
|
|
34
|
+
function defaultTransformLink(href) {
|
|
35
|
+
var _a;
|
|
36
|
+
const parsed = url_1.default.parse(href);
|
|
37
|
+
return url_1.default.format(Object.assign(Object.assign({}, parsed), { pathname: (_a = parsed.pathname) === null || _a === void 0 ? void 0 : _a.replace(constants_1.PAGE_LINK_REGEXP, '.html') }));
|
|
38
|
+
}
|
|
39
|
+
function getTitleFromTokens(tokens) {
|
|
40
|
+
let title = '';
|
|
41
|
+
let i = 0;
|
|
42
|
+
while (i < tokens.length) {
|
|
43
|
+
const token = tokens[i];
|
|
44
|
+
if (token.type === 'heading_open') {
|
|
45
|
+
({ title = '' } = (0, utils_1.headingInfo)(tokens, i));
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
i += 2;
|
|
49
|
+
}
|
|
50
|
+
return title;
|
|
51
|
+
}
|
|
52
|
+
const addTitle = (options) => {
|
|
53
|
+
const { hash, file, state, opts, isEmptyLink, tokens, idx, nextToken, href, currentPath, log } = options;
|
|
54
|
+
const id = hash && hash.slice(1);
|
|
55
|
+
const fileTokens = (0, utilsFS_1.getFileTokens)(file, state, Object.assign(Object.assign({}, opts), { disableLint: true, disableTitleRefSubstitution: true, disableCircularError: true, inheritVars: false }));
|
|
56
|
+
const sourceTokens = id ? (0, utils_1.findBlockTokens)(fileTokens, id) : fileTokens;
|
|
57
|
+
const title = getTitleFromTokens(sourceTokens);
|
|
58
|
+
if (title) {
|
|
59
|
+
let textToken;
|
|
60
|
+
if (isEmptyLink) {
|
|
61
|
+
textToken = new state.Token('text', '', 0);
|
|
62
|
+
tokens.splice(idx + 1, 0, textToken);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
textToken = nextToken;
|
|
66
|
+
}
|
|
67
|
+
textToken.content = title;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
log.warn(`Title not found: ${(0, chalk_1.bold)(href)} in ${(0, chalk_1.bold)(currentPath)}`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
// eslint-disable-next-line complexity
|
|
74
|
+
function processLink(state, tokens, idx, opts) {
|
|
75
|
+
const { path: startPath, root, transformLink, notFoundCb, needSkipLinkFn, log } = opts;
|
|
76
|
+
const currentPath = state.env.path || startPath;
|
|
77
|
+
const linkToken = tokens[idx];
|
|
78
|
+
const nextToken = tokens[idx + 1];
|
|
79
|
+
let href = (0, utils_1.getHrefTokenAttr)(linkToken);
|
|
80
|
+
if (!href) {
|
|
81
|
+
log.error(`Empty link in ${(0, chalk_1.bold)(startPath)}`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const { pathname, hash } = url_1.default.parse(href);
|
|
85
|
+
let file;
|
|
86
|
+
let fileExists;
|
|
87
|
+
let isPageFile;
|
|
88
|
+
if (!(0, utils_1.isLocalUrl)(href)) {
|
|
89
|
+
linkToken.attrSet('target', '_blank');
|
|
90
|
+
linkToken.attrSet('rel', 'noreferrer noopener');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (pathname) {
|
|
94
|
+
file = (0, path_1.resolve)(path_1.default.parse(currentPath).dir, pathname);
|
|
95
|
+
fileExists = (0, utilsFS_1.isFileExists)(file);
|
|
96
|
+
isPageFile = constants_1.PAGE_LINK_REGEXP.test(pathname);
|
|
97
|
+
if (isPageFile && !fileExists) {
|
|
98
|
+
let needShowError = true;
|
|
99
|
+
if (needSkipLinkFn) {
|
|
100
|
+
needShowError = !needSkipLinkFn(href);
|
|
101
|
+
}
|
|
102
|
+
if (notFoundCb && needShowError) {
|
|
103
|
+
notFoundCb(file.replace(root, ''));
|
|
104
|
+
}
|
|
105
|
+
if (needShowError) {
|
|
106
|
+
log.error(`Link is unreachable: ${(0, chalk_1.bold)(href)} in ${(0, chalk_1.bold)(currentPath)}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (hash) {
|
|
111
|
+
file = startPath;
|
|
112
|
+
fileExists = true;
|
|
113
|
+
isPageFile = true;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const isEmptyLink = nextToken.type === 'link_close';
|
|
119
|
+
const isTitleRefLink = nextToken.type === 'text' && nextToken.content === '{#T}';
|
|
120
|
+
if ((isEmptyLink || isTitleRefLink) &&
|
|
121
|
+
fileExists &&
|
|
122
|
+
isPageFile &&
|
|
123
|
+
!state.env.disableTitleRefSubstitution) {
|
|
124
|
+
addTitle({
|
|
125
|
+
hash,
|
|
126
|
+
file,
|
|
127
|
+
state,
|
|
128
|
+
opts,
|
|
129
|
+
isEmptyLink,
|
|
130
|
+
tokens,
|
|
131
|
+
idx,
|
|
132
|
+
nextToken,
|
|
133
|
+
href,
|
|
134
|
+
currentPath,
|
|
135
|
+
log,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
let newPathname = '';
|
|
139
|
+
if (!(0, path_1.isAbsolute)(href) && currentPath !== startPath) {
|
|
140
|
+
newPathname = (0, path_1.relative)((0, path_1.parse)(startPath).dir, file);
|
|
141
|
+
href = url_1.default.format(Object.assign(Object.assign({}, url_1.default.parse(href)), { pathname: newPathname }));
|
|
142
|
+
}
|
|
143
|
+
if (pathname || newPathname) {
|
|
144
|
+
const transformer = transformLink || defaultTransformLink;
|
|
145
|
+
linkToken.attrSet('href', transformer(href));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const index = (md, opts) => {
|
|
149
|
+
const plugin = (state) => {
|
|
150
|
+
const tokens = state.tokens;
|
|
151
|
+
let i = 0;
|
|
152
|
+
while (i < tokens.length) {
|
|
153
|
+
if (tokens[i].type === 'inline') {
|
|
154
|
+
const childrenTokens = tokens[i].children || [];
|
|
155
|
+
let j = 0;
|
|
156
|
+
while (j < childrenTokens.length) {
|
|
157
|
+
const isLinkOpenToken = childrenTokens[j].type === 'link_open';
|
|
158
|
+
const tokenClass = childrenTokens[j].attrGet('class');
|
|
159
|
+
/* Don't process anchor links */
|
|
160
|
+
const isYfmAnchor = tokenClass ? tokenClass.includes('yfm-anchor') : false;
|
|
161
|
+
if (isLinkOpenToken && !isYfmAnchor) {
|
|
162
|
+
processLink(state, childrenTokens, j, opts);
|
|
163
|
+
}
|
|
164
|
+
j++;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
i++;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
try {
|
|
171
|
+
md.core.ruler.before('includes', 'links', plugin);
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
md.core.ruler.push('links', plugin);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
module.exports = index;
|
|
178
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/links/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAsB;AACtB,iCAA2B;AAC3B,uCAAuF;AACvF,2CAA0D;AAC1D,2CAA6C;AAI7C,6CAAgE;AAGhE,SAAS,oBAAoB,CAAC,IAAY;;IACtC,MAAM,MAAM,GAAG,aAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/B,OAAO,aAAG,CAAC,MAAM,iCACV,MAAM,KACT,QAAQ,EAAE,MAAA,MAAM,CAAC,QAAQ,0CAAE,OAAO,CAAC,4BAAgB,EAAE,OAAO,CAAC,IAC/D,CAAC;AACP,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAe;IACvC,IAAI,KAAK,GAAG,EAAE,CAAC;IAEf,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE;QACtB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAExB,IAA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AI,eAAe,IAAI,CAAC,WAAW,EAAE;wBACjC,WAAW,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;qBAC/C;oBAED,CAAC,EAAE,CAAC;iBACP;aACJ;YAED,CAAC,EAAE,CAAC;SACP;IACL,CAAC,CAAC;IAEF,IAAI;QACA,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;KACrD;IAAC,OAAO,CAAC,EAAE;QACR,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KACvC;AACL,CAAC,CAAC;AAEF,iBAAS,KAAK,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
// @ts-expect-error
|
|
6
|
+
const markdown_it_meta_1 = __importDefault(require("markdown-it-meta"));
|
|
7
|
+
module.exports = markdown_it_meta_1.default;
|
|
8
|
+
//# sourceMappingURL=meta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../../src/transform/plugins/meta.ts"],"names":[],"mappings":";;;;AAAA,mBAAmB;AACnB,wEAAoC;AAGpC,iBAAS,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const monospace = (md) => {
|
|
3
|
+
function postProcess(state, delimiters) {
|
|
4
|
+
let token;
|
|
5
|
+
const loneMarkers = [];
|
|
6
|
+
for (let i = 0; i < delimiters.length; i++) {
|
|
7
|
+
const startDelim = delimiters[i];
|
|
8
|
+
if (startDelim.marker !== 0x23 /* # */) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (startDelim.end === -1) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const endDelim = delimiters[startDelim.end];
|
|
15
|
+
token = state.tokens[startDelim.token];
|
|
16
|
+
token.type = 'monospace_open';
|
|
17
|
+
token.tag = 'samp';
|
|
18
|
+
token.nesting = 1;
|
|
19
|
+
token.markup = '##';
|
|
20
|
+
token.content = '';
|
|
21
|
+
token = state.tokens[endDelim.token];
|
|
22
|
+
token.type = 'monospace_close';
|
|
23
|
+
token.tag = 'samp';
|
|
24
|
+
token.nesting = -1;
|
|
25
|
+
token.markup = '##';
|
|
26
|
+
token.content = '';
|
|
27
|
+
if (state.tokens[endDelim.token - 1].type === 'text' &&
|
|
28
|
+
state.tokens[endDelim.token - 1].content === '#') {
|
|
29
|
+
loneMarkers.push(endDelim.token - 1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// If a marker sequence has an odd number of characters, it's splitted
|
|
33
|
+
// like this: `#####` -> `#` + `##` + `##`, leaving one marker at the
|
|
34
|
+
// start of the sequence.
|
|
35
|
+
//
|
|
36
|
+
// So, we have to move all those markers after subsequent s_close tags.
|
|
37
|
+
//
|
|
38
|
+
while (loneMarkers.length) {
|
|
39
|
+
const currentMarker = loneMarkers.pop();
|
|
40
|
+
if (typeof currentMarker === 'number') {
|
|
41
|
+
let nextMarker = currentMarker + 1;
|
|
42
|
+
while (nextMarker < state.tokens.length &&
|
|
43
|
+
state.tokens[nextMarker].type === 'monospace_close') {
|
|
44
|
+
nextMarker++;
|
|
45
|
+
}
|
|
46
|
+
nextMarker--;
|
|
47
|
+
if (currentMarker !== nextMarker) {
|
|
48
|
+
token = state.tokens[nextMarker];
|
|
49
|
+
state.tokens[nextMarker] = state.tokens[currentMarker];
|
|
50
|
+
state.tokens[currentMarker] = token;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
md.inline.ruler.before('emphasis', 'monospace', (state, silent) => {
|
|
56
|
+
let token;
|
|
57
|
+
const start = state.pos;
|
|
58
|
+
const marker = state.src.charCodeAt(start);
|
|
59
|
+
if (silent) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (marker !== 0x23 /* # */) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const scanned = state.scanDelims(state.pos, true);
|
|
66
|
+
let len = scanned.length;
|
|
67
|
+
const ch = String.fromCharCode(marker);
|
|
68
|
+
if (len < 2) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (len % 2) {
|
|
72
|
+
token = state.push('text', '', 0);
|
|
73
|
+
token.content = ch;
|
|
74
|
+
len--;
|
|
75
|
+
}
|
|
76
|
+
for (let i = 0; i < len; i += 2) {
|
|
77
|
+
token = state.push('text', '', 0);
|
|
78
|
+
token.content = ch + ch;
|
|
79
|
+
if (!scanned.can_open && !scanned.can_close) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
state.delimiters.push({
|
|
83
|
+
marker: marker,
|
|
84
|
+
length: 0,
|
|
85
|
+
jump: i / 2,
|
|
86
|
+
token: state.tokens.length - 1,
|
|
87
|
+
end: -1,
|
|
88
|
+
open: scanned.can_open,
|
|
89
|
+
close: scanned.can_close,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
state.pos += scanned.length;
|
|
93
|
+
return true;
|
|
94
|
+
});
|
|
95
|
+
md.inline.ruler2.before('emphasis', 'monospace', (state) => {
|
|
96
|
+
const tokensMeta = state.tokens_meta;
|
|
97
|
+
const max = (state.tokens_meta || []).length;
|
|
98
|
+
postProcess(state, state.delimiters);
|
|
99
|
+
for (let curr = 0; curr < max; curr++) {
|
|
100
|
+
const currentToken = tokensMeta[curr];
|
|
101
|
+
if (currentToken && currentToken.delimiters) {
|
|
102
|
+
postProcess(state, currentToken.delimiters);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
module.exports = monospace;
|
|
109
|
+
//# sourceMappingURL=monospace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monospace.js","sourceRoot":"","sources":["../../src/transform/plugins/monospace.ts"],"names":[],"mappings":";AAGA,MAAM,SAAS,GAAuB,CAAC,EAAE,EAAE,EAAE;IACzC,SAAS,WAAW,CAAC,KAAkB,EAAE,UAAuB;QAC5D,IAAI,KAAK,CAAC;QACV,MAAM,WAAW,GAAG,EAAE,CAAC;QAEvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACxC,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YAEjC,IAAI,UAAU,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO,EAAE;gBACpC,SAAS;aACZ;YAED,IAAI,UAAU,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE;gBACvB,SAAS;aACZ;YAED,MAAM,QAAQ,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YAE5C,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACvC,KAAK,CAAC,IAAI,GAAG,gBAAgB,CAAC;YAC9B,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC;YACnB,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC;YAClB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;YACpB,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;YAEnB,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrC,KAAK,CAAC,IAAI,GAAG,iBAAiB,CAAC;YAC/B,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC;YACnB,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;YACnB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;YACpB,KAAK,CAAC,OAAO,GAAG,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AK,EAAE,OAAO,CAAC,SAAS;aAC3B,CAAC,CAAC;SACN;QAED,KAAK,CAAC,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;QAE5B,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;QACvD,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC;QACrC,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QAE7C,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAErC,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,GAAG,EAAE,IAAI,EAAE,EAAE;YACnC,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;YACtC,IAAI,YAAY,IAAI,YAAY,CAAC,UAAU,EAAE;gBACzC,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;aAC/C;SACJ;QAED,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,iBAAS,SAAS,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const chalk_1 = require("chalk");
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
const ALERT_RE = /^{% note (alert|info|tip|warning)\s*(?:"(.*?)")? %}$/;
|
|
5
|
+
const WRONG_NOTES = /^{% note (.*)%}/;
|
|
6
|
+
const titles = {
|
|
7
|
+
ru: {
|
|
8
|
+
info: 'Примечание',
|
|
9
|
+
tip: 'Совет',
|
|
10
|
+
alert: 'Внимание',
|
|
11
|
+
warning: 'Важно',
|
|
12
|
+
},
|
|
13
|
+
en: {
|
|
14
|
+
info: 'Note',
|
|
15
|
+
tip: 'Tip',
|
|
16
|
+
alert: 'Alert',
|
|
17
|
+
warning: 'Warning',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
function getTitle(type, originLang) {
|
|
21
|
+
let lang = originLang;
|
|
22
|
+
if (!lang || !Object.keys(titles).includes(lang)) {
|
|
23
|
+
lang = 'ru';
|
|
24
|
+
}
|
|
25
|
+
return titles[lang][type];
|
|
26
|
+
}
|
|
27
|
+
const matchCloseToken = (tokens, i) => {
|
|
28
|
+
return (tokens[i].type === 'paragraph_open' &&
|
|
29
|
+
tokens[i + 1].type === 'inline' &&
|
|
30
|
+
tokens[i + 1].content.trim() === '{% endnote %}');
|
|
31
|
+
};
|
|
32
|
+
function matchOpenToken(tokens, i) {
|
|
33
|
+
return (tokens[i].type === 'paragraph_open' &&
|
|
34
|
+
tokens[i + 1].type === 'inline' &&
|
|
35
|
+
tokens[i + 1].content.match(ALERT_RE));
|
|
36
|
+
}
|
|
37
|
+
function matchWrongNotes(tokens, i) {
|
|
38
|
+
return (tokens[i].type === 'paragraph_open' &&
|
|
39
|
+
tokens[i + 1].type === 'inline' &&
|
|
40
|
+
tokens[i + 1].content.match(WRONG_NOTES));
|
|
41
|
+
}
|
|
42
|
+
const findCloseTokenIdx = (0, utils_1.nestedCloseTokenIdxFactory)('Note', matchOpenToken, matchCloseToken);
|
|
43
|
+
const notes = (md, { lang, path: optPath, log }) => {
|
|
44
|
+
const plugin = (state) => {
|
|
45
|
+
const { tokens, env } = state;
|
|
46
|
+
const path = env.path || optPath;
|
|
47
|
+
let i = 0;
|
|
48
|
+
while (i < tokens.length) {
|
|
49
|
+
const match = matchOpenToken(tokens, i);
|
|
50
|
+
if (match) {
|
|
51
|
+
const closeTokenIdx = findCloseTokenIdx(tokens, i + 4, path, log);
|
|
52
|
+
if (!closeTokenIdx) {
|
|
53
|
+
i += 3;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const type = match[1].toLowerCase();
|
|
57
|
+
const newOpenToken = new state.Token('yfm_note_open', 'div', 1);
|
|
58
|
+
newOpenToken.attrSet('class', `yfm-note yfm-accent-${type}`);
|
|
59
|
+
newOpenToken.attrSet('note-type', type);
|
|
60
|
+
newOpenToken.map = tokens[i].map;
|
|
61
|
+
const newCloseToken = new state.Token('yfm_note_close', 'div', -1);
|
|
62
|
+
newCloseToken.map = tokens[closeTokenIdx].map;
|
|
63
|
+
// Add extra paragraph
|
|
64
|
+
const titleOpen = new state.Token('yfm_note_title_open', 'p', 1);
|
|
65
|
+
titleOpen.attrSet('class', 'yfm-note-title');
|
|
66
|
+
const titleInline = new state.Token('inline', '', 0);
|
|
67
|
+
const titleClose = new state.Token('yfm_note_title_close', 'p', -1);
|
|
68
|
+
if (match[2])
|
|
69
|
+
titleOpen.attrSet('yfm2xliff-explicit', 'true');
|
|
70
|
+
titleOpen.block = true;
|
|
71
|
+
titleClose.block = true;
|
|
72
|
+
titleInline.content = match[2] === undefined ? getTitle(type, lang) : match[2];
|
|
73
|
+
titleInline.children = [];
|
|
74
|
+
state.md.inline.parse(titleInline.content, state.md, state.env, titleInline.children);
|
|
75
|
+
const insideTokens = [
|
|
76
|
+
newOpenToken,
|
|
77
|
+
titleOpen,
|
|
78
|
+
titleInline,
|
|
79
|
+
titleClose,
|
|
80
|
+
...tokens.slice(i + 3, closeTokenIdx),
|
|
81
|
+
newCloseToken,
|
|
82
|
+
];
|
|
83
|
+
tokens.splice(i, closeTokenIdx - i + 3, ...insideTokens);
|
|
84
|
+
i++;
|
|
85
|
+
}
|
|
86
|
+
else if (matchWrongNotes(tokens, i) && tokens[i + 1].content !== '{% endnote %}') {
|
|
87
|
+
log.warn(`Incorrect syntax for notes${path ? `, file ${(0, chalk_1.bold)(path)}` : ''}`);
|
|
88
|
+
i += 3;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
i++;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
try {
|
|
96
|
+
md.core.ruler.before('curly_attributes', 'notes', plugin);
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
md.core.ruler.push('notes', plugin);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
module.exports = notes;
|
|
103
|
+
//# sourceMappingURL=notes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notes.js","sourceRoot":"","sources":["../../src/transform/plugins/notes.ts"],"names":[],"mappings":";AAAA,iCAA2B;AAK3B,mCAA4F;AAE5F,MAAM,QAAQ,GAAG,sDAAsD,CAAC;AACxE,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,MAAM,GAA2C;IACnD,EAAE,EAAE;QACA,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,OAAO;KACnB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,SAAS;KACrB;CACJ,CAAC;AAEF,SAAS,QAAQ,CAAC,IAAY,EAAE,UAA+B;IAC3D,IAAI,IAAI,GAAG,UAAU,CAAC;IAEtB,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QAC9C,IAAI,GAAG,IAAI,CAAC;KACf;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AACD,MAAM,eAAe,GAAuB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IACtD,OAAO,CACH,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,gBAAgB;QACnC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ;QAC/B,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,eAAe,CACnD,CAAC;AACN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OAAO,EAAE,MAAM,CAAC,CAAC;KACvC;AACL,CAAC,CAAC;AAEF,iBAAS,KAAK,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
// @ts-expect-error
|
|
6
|
+
const markdown_it_sup_1 = __importDefault(require("markdown-it-sup"));
|
|
7
|
+
module.exports = markdown_it_sup_1.default;
|
|
8
|
+
//# sourceMappingURL=sup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sup.js","sourceRoot":"","sources":["../../src/transform/plugins/sup.ts"],"names":[],"mappings":";;;;AAAA,mBAAmB;AACnB,sEAAkC;AAGlC,iBAAS,yBAAyB,CAAC"}
|