@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,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.yfm008 = void 0;
|
|
4
|
+
exports.yfm008 = {
|
|
5
|
+
names: ['YFM008', 'term-inside-definition-not-allowed'],
|
|
6
|
+
description: 'Term inside definition not allowed',
|
|
7
|
+
tags: ['term'],
|
|
8
|
+
function: function YFM008(params, onError) {
|
|
9
|
+
const { config } = params;
|
|
10
|
+
if (!config) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
params.tokens
|
|
14
|
+
.filter((token) => {
|
|
15
|
+
return token.type === '__yfm_lint';
|
|
16
|
+
})
|
|
17
|
+
.forEach((term) => {
|
|
18
|
+
// @ts-expect-error bad markdownlint typings
|
|
19
|
+
if (term.attrGet('YFM008')) {
|
|
20
|
+
onError({
|
|
21
|
+
lineNumber: term.lineNumber,
|
|
22
|
+
context: term.line,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=yfm008.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yfm008.js","sourceRoot":"","sources":["../../../src/transform/yfmlint/markdownlint-custom-rule/yfm008.ts"],"names":[],"mappings":";;;AAEa,QAAA,MAAM,GAAS;IACxB,KAAK,EAAE,CAAC,QAAQ,EAAE,oCAAoC,CAAC;IACvD,WAAW,EAAE,oCAAoC;IACjD,IAAI,EAAE,CAAC,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO;QACrC,MAAM,EAAC,MAAM,EAAC,GAAG,MAAM,CAAC;QACxB,IAAI,CAAC,MAAM,EAAE;YACT,OAAO;SACV;QACD,MAAM,CAAC,MAAM;aACR,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACd,OAAO,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC;QACvC,CAAC,CAAC;aACD,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACd,4CAA4C;YAC5C,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBACxB,OAAO,CAAC;oBACJ,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,OAAO,EAAE,IAAI,CAAC,IAAI;iBACrB,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACX,CAAC;CACJ,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.yfm009 = void 0;
|
|
4
|
+
exports.yfm009 = {
|
|
5
|
+
names: ['YFM009', 'no-term-definition-in-content'],
|
|
6
|
+
description: 'Term definition should be placed at the end of file',
|
|
7
|
+
tags: ['term'],
|
|
8
|
+
function: function YFM009(params, onError) {
|
|
9
|
+
const { config } = params;
|
|
10
|
+
if (!config) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
let lastCloseIndex = -1;
|
|
14
|
+
const size = params.tokens.length;
|
|
15
|
+
for (let i = 0; i < size; i++) {
|
|
16
|
+
if (params.tokens[i].type === 'template_close') {
|
|
17
|
+
lastCloseIndex = i;
|
|
18
|
+
}
|
|
19
|
+
if (params.tokens[i].type !== 'template_close') {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (i === size - 1) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (params.tokens[i + 1].type === 'template_open') {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (i < size - 2 && params.tokens[i + 2].type === 'template_open') {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
onError({
|
|
32
|
+
lineNumber: params.tokens[i + 1].lineNumber,
|
|
33
|
+
detail: 'There is a content between term definition. All term defitions should be placed at the end of file.',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (lastCloseIndex === -1) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (lastCloseIndex !== size - 1) {
|
|
40
|
+
onError({
|
|
41
|
+
lineNumber: params.tokens[lastCloseIndex + 1].lineNumber,
|
|
42
|
+
detail: 'The file must end with term only.',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=yfm009.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yfm009.js","sourceRoot":"","sources":["../../../src/transform/yfmlint/markdownlint-custom-rule/yfm009.ts"],"names":[],"mappings":";;;AAEa,QAAA,MAAM,GAAS;IACxB,KAAK,EAAE,CAAC,QAAQ,EAAE,+BAA+B,CAAC;IAClD,WAAW,EAAE,qDAAqD;IAClE,IAAI,EAAE,CAAC,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO;QACrC,MAAM,EAAC,MAAM,EAAC,GAAG,MAAM,CAAC;QACxB,IAAI,CAAC,MAAM,EAAE;YACT,OAAO;SACV;QAED,IAAI,cAAc,GAAG,CAAC,CAAC,CAAC;QACxB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;QAElC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE;YAC3B,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,gBAAgB,EAAE;gBAC5C,cAAc,GAAG,CAAC,CAAC;aACtB;YAED,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,gBAAgB,EAAE;gBAC5C,SAAS;aACZ;YAED,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,EAAE;gBAChB,SAAS;aACZ;YAED,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,EAAE;gBAC/C,SAAS;aACZ;YAED,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,EAAE;gBAC/D,SAAS;aACZ;YAED,OAAO,CAAC;gBACJ,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU;gBAC3C,MAAM,EAAE,qGAAqG;aAChH,CAAC,CAAC;SACN;QAED,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE;YACvB,OAAO;SACV;QAED,IAAI,cAAc,KAAK,IAAI,GAAG,CAAC,EAAE;YAC7B,OAAO,CAAC;gBACJ,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,UAAU;gBACxD,MAAM,EAAE,mCAAmC;aAC9C,CAAC,CAAC;SACN;IACL,CAAC;CACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Dictionary } from 'lodash';
|
|
2
|
+
import { Plugin, Rule } from 'markdownlint';
|
|
3
|
+
import { LintConfig, PluginOptions } from '.';
|
|
4
|
+
export interface Options {
|
|
5
|
+
input: string;
|
|
6
|
+
plugins?: Function[] | Plugin;
|
|
7
|
+
pluginOptions: PluginOptions;
|
|
8
|
+
defaultLintConfig?: LintConfig;
|
|
9
|
+
lintConfig?: LintConfig;
|
|
10
|
+
customLintRules?: Rule[];
|
|
11
|
+
sourceMap?: Dictionary<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typings.js","sourceRoot":"","sources":["../../src/transform/yfmlint/typings.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LogLevels } from '../log';
|
|
2
|
+
import { LintError } from 'markdownlint';
|
|
3
|
+
import { Dictionary } from 'lodash';
|
|
4
|
+
export declare function errorToString(path: string, error: LintError, sourceMap?: Dictionary<string>): string;
|
|
5
|
+
export declare function getLogLevel(opts: {
|
|
6
|
+
ruleNames: string[];
|
|
7
|
+
logLevelsConfig: Record<string, LogLevels>;
|
|
8
|
+
defaultLevel: LogLevels;
|
|
9
|
+
}): LogLevels;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogLevel = exports.errorToString = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
function errorToString(path, error, sourceMap) {
|
|
6
|
+
const ruleMoniker = error.ruleNames
|
|
7
|
+
? error.ruleNames.join(path_1.sep)
|
|
8
|
+
: // @ts-expect-error bad markdownlint typings
|
|
9
|
+
error.ruleName + path_1.sep + error.ruleAlias;
|
|
10
|
+
const lineNumber = sourceMap ? sourceMap[error.lineNumber] : error.lineNumber;
|
|
11
|
+
return (`${path}${lineNumber ? `: ${lineNumber}:` : ':'} ${ruleMoniker} ${error.ruleDescription}` +
|
|
12
|
+
(error.errorDetail ? ` [${error.errorDetail}]` : '') +
|
|
13
|
+
(error.errorContext ? ` [Context: "${error.errorContext}"]` : ''));
|
|
14
|
+
}
|
|
15
|
+
exports.errorToString = errorToString;
|
|
16
|
+
function getLogLevel(opts) {
|
|
17
|
+
const { ruleNames, logLevelsConfig, defaultLevel } = opts;
|
|
18
|
+
const ruleName = ruleNames.filter((ruleName) => ruleName in logLevelsConfig)[0];
|
|
19
|
+
return logLevelsConfig[ruleName] || defaultLevel;
|
|
20
|
+
}
|
|
21
|
+
exports.getLogLevel = getLogLevel;
|
|
22
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/transform/yfmlint/utils.ts"],"names":[],"mappings":";;;AAGA,+BAAyB;AAEzB,SAAgB,aAAa,CAAC,IAAY,EAAE,KAAgB,EAAE,SAA8B;IACxF,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS;QAC/B,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,UAAG,CAAC;QAC3B,CAAC,CAAC,4CAA4C;YAC5C,KAAK,CAAC,QAAQ,GAAG,UAAG,GAAG,KAAK,CAAC,SAAS,CAAC;IAC7C,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC;IAE9E,OAAO,CACH,GAAG,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,WAAW,IAAI,KAAK,CAAC,eAAe,EAAE;QACzF,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACpD,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,eAAe,KAAK,CAAC,YAAY,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CACpE,CAAC;AACN,CAAC;AAZD,sCAYC;AAED,SAAgB,WAAW,CAAC,IAI3B;IACG,MAAM,EAAC,SAAS,EAAE,eAAe,EAAE,YAAY,EAAC,GAAG,IAAI,CAAC;IACxD,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAC7B,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,IAAI,eAAe,CAC5C,CAAC,CAAC,CAAiC,CAAC;IAErC,OAAO,eAAe,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC;AACrD,CAAC;AAXD,kCAWC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const log_1 = require("../log");
|
|
3
|
+
const index = {
|
|
4
|
+
// Default state for all rules
|
|
5
|
+
default: true,
|
|
6
|
+
'log-levels': {
|
|
7
|
+
MD001: log_1.LogLevels.DISABLED,
|
|
8
|
+
MD002: log_1.LogLevels.DISABLED,
|
|
9
|
+
MD003: log_1.LogLevels.DISABLED,
|
|
10
|
+
MD004: log_1.LogLevels.DISABLED,
|
|
11
|
+
MD005: log_1.LogLevels.DISABLED,
|
|
12
|
+
MD006: log_1.LogLevels.DISABLED,
|
|
13
|
+
MD007: log_1.LogLevels.DISABLED,
|
|
14
|
+
MD009: log_1.LogLevels.DISABLED,
|
|
15
|
+
MD010: log_1.LogLevels.DISABLED,
|
|
16
|
+
MD011: log_1.LogLevels.DISABLED,
|
|
17
|
+
MD012: log_1.LogLevels.DISABLED,
|
|
18
|
+
MD013: log_1.LogLevels.DISABLED,
|
|
19
|
+
MD014: log_1.LogLevels.DISABLED,
|
|
20
|
+
MD018: log_1.LogLevels.DISABLED,
|
|
21
|
+
MD019: log_1.LogLevels.DISABLED,
|
|
22
|
+
MD020: log_1.LogLevels.DISABLED,
|
|
23
|
+
MD021: log_1.LogLevels.DISABLED,
|
|
24
|
+
MD022: log_1.LogLevels.DISABLED,
|
|
25
|
+
MD023: log_1.LogLevels.DISABLED,
|
|
26
|
+
MD024: log_1.LogLevels.DISABLED,
|
|
27
|
+
MD025: log_1.LogLevels.DISABLED,
|
|
28
|
+
MD026: log_1.LogLevels.DISABLED,
|
|
29
|
+
MD027: log_1.LogLevels.DISABLED,
|
|
30
|
+
MD028: log_1.LogLevels.DISABLED,
|
|
31
|
+
MD029: log_1.LogLevels.DISABLED,
|
|
32
|
+
MD030: log_1.LogLevels.DISABLED,
|
|
33
|
+
MD031: log_1.LogLevels.DISABLED,
|
|
34
|
+
MD032: log_1.LogLevels.DISABLED,
|
|
35
|
+
MD033: log_1.LogLevels.DISABLED,
|
|
36
|
+
MD034: log_1.LogLevels.DISABLED,
|
|
37
|
+
MD035: log_1.LogLevels.DISABLED,
|
|
38
|
+
MD036: log_1.LogLevels.DISABLED,
|
|
39
|
+
MD037: log_1.LogLevels.DISABLED,
|
|
40
|
+
MD038: log_1.LogLevels.DISABLED,
|
|
41
|
+
MD039: log_1.LogLevels.DISABLED,
|
|
42
|
+
MD040: log_1.LogLevels.DISABLED,
|
|
43
|
+
MD041: log_1.LogLevels.DISABLED,
|
|
44
|
+
MD042: log_1.LogLevels.DISABLED,
|
|
45
|
+
MD043: log_1.LogLevels.DISABLED,
|
|
46
|
+
MD044: log_1.LogLevels.DISABLED,
|
|
47
|
+
MD045: log_1.LogLevels.DISABLED,
|
|
48
|
+
MD046: log_1.LogLevels.DISABLED,
|
|
49
|
+
MD047: log_1.LogLevels.DISABLED,
|
|
50
|
+
MD048: log_1.LogLevels.DISABLED,
|
|
51
|
+
MD049: log_1.LogLevels.DISABLED,
|
|
52
|
+
MD050: log_1.LogLevels.DISABLED,
|
|
53
|
+
YFM001: log_1.LogLevels.WARN,
|
|
54
|
+
YFM002: log_1.LogLevels.WARN,
|
|
55
|
+
YFM003: log_1.LogLevels.ERROR,
|
|
56
|
+
YFM004: log_1.LogLevels.ERROR,
|
|
57
|
+
YFM005: log_1.LogLevels.ERROR,
|
|
58
|
+
YFM006: log_1.LogLevels.WARN,
|
|
59
|
+
YFM007: log_1.LogLevels.WARN,
|
|
60
|
+
YFM008: log_1.LogLevels.WARN,
|
|
61
|
+
YFM009: log_1.LogLevels.ERROR, // Term definition used not at the end of file
|
|
62
|
+
},
|
|
63
|
+
// Inline code length
|
|
64
|
+
YFM001: {
|
|
65
|
+
maximum: 100,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
module.exports = index;
|
|
69
|
+
//# sourceMappingURL=yfmlint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yfmlint.js","sourceRoot":"","sources":["../../src/transform/yfmlint/yfmlint.ts"],"names":[],"mappings":";AACA,gCAAiC;AAEjC,MAAM,KAAK,GAAe;IACtB,8BAA8B;IAC9B,OAAO,EAAE,IAAI;IAEb,YAAY,EAAE;QACV,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QACzB,KAAK,EAAE,eAAS,CAAC,QAAQ;QAEzB,MAAM,EAAE,eAAS,CAAC,IAAI;QACtB,MAAM,EAAE,eAAS,CAAC,IAAI;QACtB,MAAM,EAAE,eAAS,CAAC,KAAK;QACvB,MAAM,EAAE,eAAS,CAAC,KAAK;QACvB,MAAM,EAAE,eAAS,CAAC,KAAK;QACvB,MAAM,EAAE,eAAS,CAAC,IAAI;QACtB,MAAM,EAAE,eAAS,CAAC,IAAI;QACtB,MAAM,EAAE,eAAS,CAAC,IAAI;QACtB,MAAM,EAAE,eAAS,CAAC,KAAK,EAAE,8CAA8C;KAC1E;IAED,qBAAqB;IACrB,MAAM,EAAE;QACJ,OAAO,EAAE,GAAG;KACf;CACJ,CAAC;AAEF,iBAAS,KAAK,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@diplodoc/transform",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "A simple transformer of text in YFM (Yandex Flavored Markdown) to HTML",
|
|
5
|
+
"author": "YFM Team <yfm-team@yandex.ru>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/yandex-cloud/yfm-transform.git"
|
|
10
|
+
},
|
|
11
|
+
"main": "lib/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"lib",
|
|
15
|
+
"src"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "npm run build:lib && npm run build:dist",
|
|
19
|
+
"build:lib": "tsc -p tsconfig.transform.json",
|
|
20
|
+
"build:dist": "./esbuild/build.js",
|
|
21
|
+
"test": "jest --coverage",
|
|
22
|
+
"lint": "npx eslint --max-warnings=0 \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
23
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
24
|
+
"precommit": "npm run lint && npm run test",
|
|
25
|
+
"prepublishOnly": "npm run lint && npm run test && npm run build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@diplodoc/tabs-extension": "^2.0.11",
|
|
29
|
+
"chalk": "4.1.2",
|
|
30
|
+
"cheerio": "^1.0.0-rc.12",
|
|
31
|
+
"css": "^3.0.0",
|
|
32
|
+
"cssfilter": "0.0.10",
|
|
33
|
+
"get-root-node-polyfill": "1.0.0",
|
|
34
|
+
"github-slugger": "1.4.0",
|
|
35
|
+
"js-yaml": "^4.1.0",
|
|
36
|
+
"lodash": "4.17.21",
|
|
37
|
+
"markdown-it": "13.0.1",
|
|
38
|
+
"markdown-it-attrs": "4.1.4",
|
|
39
|
+
"markdown-it-deflist": "2.1.0",
|
|
40
|
+
"markdown-it-meta": "0.0.1",
|
|
41
|
+
"markdown-it-sup": "1.0.0",
|
|
42
|
+
"markdownlint": "^0.25.1",
|
|
43
|
+
"markdownlint-rule-helpers": "0.17.2",
|
|
44
|
+
"sanitize-html": "2.7.3",
|
|
45
|
+
"slugify": "1.6.5"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@babel/core": "7.18.10",
|
|
49
|
+
"@babel/plugin-transform-modules-commonjs": "7.18.6",
|
|
50
|
+
"@babel/preset-env": "7.18.10",
|
|
51
|
+
"@types/css": "0.0.34",
|
|
52
|
+
"@types/github-slugger": "1.3.0",
|
|
53
|
+
"@types/jest": "28.1.7",
|
|
54
|
+
"@types/js-yaml": "^4.0.5",
|
|
55
|
+
"@types/lodash": "4.14.183",
|
|
56
|
+
"@types/markdown-it": "12.2.3",
|
|
57
|
+
"@types/markdown-it-attrs": "4.1.0",
|
|
58
|
+
"@types/markdownlint": "0.18.0",
|
|
59
|
+
"@types/node": "17.0.10",
|
|
60
|
+
"@types/sanitize-html": "2.6.2",
|
|
61
|
+
"@yandex-cloud/eslint-config": "^1.1.0",
|
|
62
|
+
"@yandex-cloud/prettier-config": "^1.0.0",
|
|
63
|
+
"@yandex-cloud/tsconfig": "^1.0.0",
|
|
64
|
+
"autoprefixer": "^10.4.15",
|
|
65
|
+
"babel-eslint": "10.1.0",
|
|
66
|
+
"esbuild": "^0.19.2",
|
|
67
|
+
"esbuild-sass-plugin": "^2.12.0",
|
|
68
|
+
"eslint": "8.22.0",
|
|
69
|
+
"eslint-plugin-security": "1.5.0",
|
|
70
|
+
"highlight.js": "^11.8.0",
|
|
71
|
+
"jest": "28.1.3",
|
|
72
|
+
"markdown-it-testgen": "^0.1.6",
|
|
73
|
+
"postcss": "^8.4.27",
|
|
74
|
+
"postcss-preset-env": "^9.1.1",
|
|
75
|
+
"prettier": "2.7.1",
|
|
76
|
+
"regenerator-runtime": "0.13.9",
|
|
77
|
+
"ts-jest": "28.0.8",
|
|
78
|
+
"typescript": "4.7.4"
|
|
79
|
+
},
|
|
80
|
+
"peerDependencies": {
|
|
81
|
+
"highlight.js": "^10.0.3 || ^11"
|
|
82
|
+
},
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"highlight.js": {
|
|
85
|
+
"optional": true
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"bugs": {
|
|
89
|
+
"url": "https://github.com/yandex-cloud/yfm-transform/issues"
|
|
90
|
+
},
|
|
91
|
+
"homepage": "https://github.com/yandex-cloud/yfm-transform#readme",
|
|
92
|
+
"keywords": [
|
|
93
|
+
"markdown",
|
|
94
|
+
"yandex",
|
|
95
|
+
"docs",
|
|
96
|
+
"yfm",
|
|
97
|
+
"documentation",
|
|
98
|
+
"tool",
|
|
99
|
+
"tools",
|
|
100
|
+
"generator"
|
|
101
|
+
],
|
|
102
|
+
"moduleDirectories": [
|
|
103
|
+
"node_modules",
|
|
104
|
+
"src"
|
|
105
|
+
]
|
|
106
|
+
}
|
package/src/.eslintrc
ADDED
package/src/js/code.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {getEventTarget, isCustom} from './utils';
|
|
2
|
+
|
|
3
|
+
const BUTTON_SELECTOR = '.yfm-clipboard-button';
|
|
4
|
+
|
|
5
|
+
function copyToClipboard(text: string) {
|
|
6
|
+
if (!text) {
|
|
7
|
+
return Promise.resolve();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (navigator.clipboard && typeof navigator.clipboard.writeText) {
|
|
11
|
+
return navigator.clipboard.writeText(text);
|
|
12
|
+
}
|
|
13
|
+
const textarea = document.createElement('textarea');
|
|
14
|
+
textarea.setAttribute('style', 'position: absolute; left: 1000%');
|
|
15
|
+
textarea.textContent = text;
|
|
16
|
+
document.body.append(textarea);
|
|
17
|
+
|
|
18
|
+
textarea.select();
|
|
19
|
+
document.execCommand('copy');
|
|
20
|
+
|
|
21
|
+
document.body.removeChild(textarea);
|
|
22
|
+
|
|
23
|
+
return Promise.resolve();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function notifySuccess(svgButton: HTMLElement | null) {
|
|
27
|
+
if (!svgButton) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const id = svgButton.getAttribute('data-animation');
|
|
32
|
+
// @ts-expect-error
|
|
33
|
+
const icon = svgButton.getRootNode().getElementById(`visibileAnimation-${id}`);
|
|
34
|
+
|
|
35
|
+
if (!icon) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
icon.beginElement();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof document !== 'undefined') {
|
|
43
|
+
document.addEventListener('click', (event) => {
|
|
44
|
+
const target = getEventTarget(event) as HTMLElement;
|
|
45
|
+
|
|
46
|
+
if (isCustom(event) || !target.matches(BUTTON_SELECTOR)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const parent = target.parentNode;
|
|
51
|
+
|
|
52
|
+
if (!parent) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const code = parent.querySelector<HTMLElement>('pre code');
|
|
57
|
+
if (!code) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
copyToClipboard(code.innerText).then(() => {
|
|
62
|
+
notifySuccess(parent.querySelector('.yfm-clipboard-button'));
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
package/src/js/cut.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {getEventTarget, isCustom} from './utils';
|
|
2
|
+
|
|
3
|
+
const Selector = {
|
|
4
|
+
CUT: '.yfm .yfm-cut',
|
|
5
|
+
TITLE: '.yfm .yfm-cut-title',
|
|
6
|
+
CONTENT: '.yfm .yfm-cut-content',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const ClassName = {
|
|
10
|
+
OPEN: 'open',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function toggleCut(element: HTMLElement) {
|
|
14
|
+
const cutNode = element.parentNode;
|
|
15
|
+
|
|
16
|
+
if (!(cutNode instanceof HTMLElement)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
cutNode.classList.toggle(ClassName.OPEN);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function matchTitle(target: EventTarget | null) {
|
|
24
|
+
if (!(target instanceof HTMLElement)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return target?.matches?.(Selector.TITLE);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function findTitleInPath(event: MouseEvent): HTMLElement | undefined {
|
|
32
|
+
const target = getEventTarget(event);
|
|
33
|
+
|
|
34
|
+
if (matchTitle(target)) {
|
|
35
|
+
return target as HTMLElement;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const path = event.composedPath?.();
|
|
39
|
+
|
|
40
|
+
return path?.find(matchTitle) as HTMLElement | undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (typeof document !== 'undefined') {
|
|
44
|
+
document.addEventListener('click', (event) => {
|
|
45
|
+
if (isCustom(event)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const title = findTitleInPath(event);
|
|
50
|
+
|
|
51
|
+
if (!title) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
toggleCut(title);
|
|
56
|
+
});
|
|
57
|
+
}
|
package/src/js/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import getRootNode from 'get-root-node-polyfill';
|
|
2
|
+
|
|
3
|
+
if (typeof document !== 'undefined') {
|
|
4
|
+
// matches polyfill for old edge
|
|
5
|
+
(function (e) {
|
|
6
|
+
const matches =
|
|
7
|
+
e.matches ||
|
|
8
|
+
e.matchesSelector ||
|
|
9
|
+
e.webkitMatchesSelector ||
|
|
10
|
+
e.mozMatchesSelector ||
|
|
11
|
+
e.msMatchesSelector ||
|
|
12
|
+
e.oMatchesSelector;
|
|
13
|
+
|
|
14
|
+
if (matches) {
|
|
15
|
+
e.matches = e.matchesSelector = matches;
|
|
16
|
+
} else {
|
|
17
|
+
e.matches = e.matchesSelector = function matches(selector) {
|
|
18
|
+
const rootNode = e.getRootNode ? e.getRootNode() : getRootNode.call(e);
|
|
19
|
+
const matches = rootNode.querySelectorAll(selector);
|
|
20
|
+
const th = this;
|
|
21
|
+
return Array.prototype.some.call(matches, (e) => {
|
|
22
|
+
return e === th;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
})(Element.prototype);
|
|
27
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Selector,
|
|
3
|
+
openClass,
|
|
4
|
+
openDefinitionClass,
|
|
5
|
+
createDefinitionElement,
|
|
6
|
+
setDefinitionId,
|
|
7
|
+
setDefinitionPosition,
|
|
8
|
+
closeDefinition,
|
|
9
|
+
} from './utils';
|
|
10
|
+
import {getEventTarget, isCustom} from '../utils';
|
|
11
|
+
|
|
12
|
+
if (typeof document !== 'undefined') {
|
|
13
|
+
document.addEventListener('click', (event) => {
|
|
14
|
+
const openDefinition = document.getElementsByClassName(
|
|
15
|
+
openDefinitionClass,
|
|
16
|
+
)[0] as HTMLElement;
|
|
17
|
+
const target = getEventTarget(event) as HTMLElement;
|
|
18
|
+
|
|
19
|
+
const termId = target.getAttribute('id');
|
|
20
|
+
const termKey = target.getAttribute('term-key');
|
|
21
|
+
let definitionElement = document.getElementById(termKey + '_element');
|
|
22
|
+
|
|
23
|
+
if (termKey && !definitionElement) {
|
|
24
|
+
definitionElement = createDefinitionElement(target);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isSameTerm = openDefinition && termId === openDefinition.getAttribute('term-id');
|
|
28
|
+
if (isSameTerm) {
|
|
29
|
+
closeDefinition(openDefinition);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const isTargetDefinitionContent = target.closest(
|
|
34
|
+
[Selector.CONTENT.replace(' ', ''), openClass].join('.'),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (openDefinition && !isTargetDefinitionContent) {
|
|
38
|
+
closeDefinition(openDefinition);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (isCustom(event) || !target.matches(Selector.TITLE) || !definitionElement) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setDefinitionId(definitionElement, target);
|
|
46
|
+
setDefinitionPosition(definitionElement, target);
|
|
47
|
+
|
|
48
|
+
definitionElement.classList.toggle(openClass);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
document.addEventListener('keydown', (event) => {
|
|
52
|
+
const openDefinition = document.getElementsByClassName(
|
|
53
|
+
openDefinitionClass,
|
|
54
|
+
)[0] as HTMLElement;
|
|
55
|
+
if (event.key === 'Escape' && openDefinition) {
|
|
56
|
+
closeDefinition(openDefinition);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
window.addEventListener('resize', () => {
|
|
61
|
+
const openDefinition = document.getElementsByClassName(
|
|
62
|
+
openDefinitionClass,
|
|
63
|
+
)[0] as HTMLElement;
|
|
64
|
+
|
|
65
|
+
if (!openDefinition) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const termId = openDefinition.getAttribute('term-id') || '';
|
|
70
|
+
const termElement = document.getElementById(termId);
|
|
71
|
+
|
|
72
|
+
if (!termElement) {
|
|
73
|
+
openDefinition.classList.toggle(openClass);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
setDefinitionPosition(openDefinition, termElement);
|
|
78
|
+
});
|
|
79
|
+
}
|