@diplodoc/transform 4.35.0 → 4.37.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/README.md +61 -0
- package/README.ru.md +61 -0
- package/dist/css/_yfm-only.css +7 -7
- package/dist/css/_yfm-only.css.map +3 -3
- package/dist/css/_yfm-only.min.css +1 -1
- package/dist/css/_yfm-only.min.css.map +3 -3
- package/dist/css/base.css.map +1 -1
- package/dist/css/base.min.css.map +1 -1
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css +7 -7
- package/dist/css/yfm.css.map +3 -3
- package/dist/css/yfm.min.css +1 -1
- package/dist/css/yfm.min.css.map +3 -3
- package/lib/md.d.ts +1 -0
- package/lib/md.js +7 -7
- package/lib/md.js.map +1 -1
- package/lib/plugins/anchors/index.d.ts +1 -0
- package/lib/plugins/anchors/index.js +5 -3
- package/lib/plugins/anchors/index.js.map +1 -1
- package/lib/plugins/imsize/const.d.ts +2 -1
- package/lib/plugins/imsize/const.js +1 -0
- package/lib/plugins/imsize/const.js.map +1 -1
- package/lib/plugins/imsize/index.d.ts +3 -2
- package/lib/plugins/imsize/index.js +2 -2
- package/lib/plugins/imsize/index.js.map +1 -1
- package/lib/plugins/imsize/plugin.d.ts +4 -1
- package/lib/plugins/imsize/plugin.js +26 -1
- package/lib/plugins/imsize/plugin.js.map +1 -1
- package/lib/plugins/includes/collect.js +8 -7
- package/lib/plugins/includes/collect.js.map +1 -1
- package/lib/plugins/includes/index.js +3 -4
- package/lib/plugins/includes/index.js.map +1 -1
- package/lib/plugins/includes/types.d.ts +1 -1
- package/lib/plugins/links/index.js +10 -7
- package/lib/plugins/links/index.js.map +1 -1
- package/lib/plugins/notes/index.js +5 -10
- package/lib/plugins/notes/index.js.map +1 -1
- package/lib/preprocessors/included/index.js +8 -3
- package/lib/preprocessors/included/index.js.map +1 -1
- package/lib/preprocessors/index.d.ts +7 -0
- package/lib/preprocessors/index.js +18 -0
- package/lib/preprocessors/index.js.map +1 -0
- package/lib/sanitize.d.ts +2 -4
- package/lib/sanitize.js +4 -1
- package/lib/sanitize.js.map +1 -1
- package/lib/typings.d.ts +4 -0
- package/lib/utilsFS.d.ts +1 -1
- package/lib/utilsFS.js +4 -2
- package/lib/utilsFS.js.map +1 -1
- package/lib/yfmlint/index.js +4 -5
- package/lib/yfmlint/index.js.map +1 -1
- package/package.json +1 -1
- package/src/scss/_note.scss +2 -3
- package/src/transform/md.ts +6 -7
- package/src/transform/plugins/anchors/index.ts +13 -4
- package/src/transform/plugins/file/README.md +0 -54
- package/src/transform/plugins/imsize/const.ts +1 -0
- package/src/transform/plugins/imsize/index.ts +4 -4
- package/src/transform/plugins/imsize/plugin.ts +32 -1
- package/src/transform/plugins/includes/collect.ts +10 -8
- package/src/transform/plugins/includes/index.ts +5 -15
- package/src/transform/plugins/includes/types.ts +1 -1
- package/src/transform/plugins/links/index.ts +29 -14
- package/src/transform/plugins/notes/index.ts +8 -6
- package/src/transform/preprocessors/included/index.ts +9 -3
- package/src/transform/preprocessors/index.ts +25 -0
- package/src/transform/sanitize.ts +14 -3
- package/src/transform/typings.ts +3 -0
- package/src/transform/utilsFS.ts +10 -2
- package/src/transform/yfmlint/index.ts +4 -11
- package/lib/preprocessors.d.ts +0 -3
- package/lib/preprocessors.js +0 -8
- package/lib/preprocessors.js.map +0 -1
- package/src/scss/_cut.scss +0 -55
- package/src/transform/preprocessors.ts +0 -7
|
@@ -26,13 +26,15 @@ const preprocessLine = (
|
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const
|
|
29
|
+
const includePathKey = match[1];
|
|
30
30
|
|
|
31
31
|
// Protect from empty path
|
|
32
|
-
if (!
|
|
32
|
+
if (!includePathKey) {
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const includePaths = includePathKey.split(':');
|
|
37
|
+
|
|
36
38
|
// Read all content from top to bottom(!) char of the included block
|
|
37
39
|
const data = [];
|
|
38
40
|
let line = start;
|
|
@@ -55,7 +57,11 @@ const preprocessLine = (
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
// Normalize the path to absolute
|
|
58
|
-
|
|
60
|
+
let includePath = getFullIncludePath(includePaths[0], root, path);
|
|
61
|
+
for (let index = 1; index < includePaths.length; index++) {
|
|
62
|
+
const pathname = includePaths[index];
|
|
63
|
+
includePath = getFullIncludePath(pathname, root, includePath);
|
|
64
|
+
}
|
|
59
65
|
|
|
60
66
|
// Store the included content
|
|
61
67
|
md.included[includePath] = data.join('\n');
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {MarkdownIt, MarkdownItPluginOpts, MarkdownItPreprocessorCb} from '../plugins/typings';
|
|
2
|
+
import type {PluginOptions} from '../yfmlint';
|
|
3
|
+
|
|
4
|
+
import included from './included';
|
|
5
|
+
|
|
6
|
+
const defaultPreprocessors = [included] as MarkdownItPreprocessorCb[];
|
|
7
|
+
|
|
8
|
+
export default defaultPreprocessors;
|
|
9
|
+
|
|
10
|
+
export function preprocess(
|
|
11
|
+
content: string,
|
|
12
|
+
pluginOptions: MarkdownItPluginOpts | PluginOptions | unknown,
|
|
13
|
+
options?: Partial<MarkdownItPluginOpts> & {
|
|
14
|
+
preprocessors?: MarkdownItPreprocessorCb[];
|
|
15
|
+
},
|
|
16
|
+
md?: MarkdownIt,
|
|
17
|
+
) {
|
|
18
|
+
const {preprocessors = defaultPreprocessors} = options ?? {};
|
|
19
|
+
|
|
20
|
+
for (const preprocessor of preprocessors) {
|
|
21
|
+
content = preprocessor(content, pluginOptions as MarkdownItPluginOpts, md);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return content;
|
|
25
|
+
}
|
|
@@ -4,6 +4,8 @@ import cssfilter from 'cssfilter';
|
|
|
4
4
|
import * as cheerio from 'cheerio';
|
|
5
5
|
import css from 'css';
|
|
6
6
|
|
|
7
|
+
import {CssWhiteList} from './typings';
|
|
8
|
+
|
|
7
9
|
const htmlTags = [
|
|
8
10
|
'a',
|
|
9
11
|
'abbr',
|
|
@@ -492,8 +494,6 @@ const allowedTags = Array.from(
|
|
|
492
494
|
);
|
|
493
495
|
const allowedAttributes = Array.from(new Set([...htmlAttrs, ...svgAttrs, ...yfmHtmlAttrs]));
|
|
494
496
|
|
|
495
|
-
export type CssWhiteList = {[property: string]: boolean};
|
|
496
|
-
|
|
497
497
|
export interface SanitizeOptions extends sanitizeHtml.IOptions {
|
|
498
498
|
cssWhiteList?: CssWhiteList;
|
|
499
499
|
disableStyleSanitizer?: boolean;
|
|
@@ -598,9 +598,20 @@ function sanitizeStyles(html: string, options: SanitizeOptions) {
|
|
|
598
598
|
return styles + content;
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
-
export default function sanitize(
|
|
601
|
+
export default function sanitize(
|
|
602
|
+
html: string,
|
|
603
|
+
options?: SanitizeOptions,
|
|
604
|
+
additionalOptions?: SanitizeOptions,
|
|
605
|
+
) {
|
|
602
606
|
const sanitizeOptions = options || defaultOptions;
|
|
603
607
|
|
|
608
|
+
if (additionalOptions?.cssWhiteList) {
|
|
609
|
+
sanitizeOptions.cssWhiteList = {
|
|
610
|
+
...sanitizeOptions.cssWhiteList,
|
|
611
|
+
...additionalOptions.cssWhiteList,
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
|
|
604
615
|
const needToSanitizeStyles = !(sanitizeOptions.disableStyleSanitizer ?? false);
|
|
605
616
|
|
|
606
617
|
const modifiedHtml = needToSanitizeStyles ? sanitizeStyles(html, sanitizeOptions) : html;
|
package/src/transform/typings.ts
CHANGED
|
@@ -74,6 +74,7 @@ export type EnvType<Extras extends {} = {}> = {
|
|
|
74
74
|
assets?: unknown[];
|
|
75
75
|
meta?: object;
|
|
76
76
|
changelogs?: ChangelogItem[];
|
|
77
|
+
additionalOptionsCssWhiteList?: CssWhiteList;
|
|
77
78
|
} & Extras;
|
|
78
79
|
|
|
79
80
|
export interface MarkdownItPluginOpts {
|
|
@@ -98,3 +99,5 @@ export type MarkdownItPluginCb<T extends {} = {}> = {
|
|
|
98
99
|
export type MarkdownItPreprocessorCb<T extends unknown = {}> = {
|
|
99
100
|
(input: string, opts: T & Partial<MarkdownItPluginOpts>, md?: MarkdownIt): string;
|
|
100
101
|
};
|
|
102
|
+
|
|
103
|
+
export type CssWhiteList = {[property: string]: boolean};
|
package/src/transform/utilsFS.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {join, parse, relative, resolve, sep} from 'path';
|
|
|
7
7
|
import liquidSnippet from './liquid';
|
|
8
8
|
import {StateCore} from './typings';
|
|
9
9
|
import {defaultTransformLink} from './utils';
|
|
10
|
+
import {preprocess} from './preprocessors';
|
|
10
11
|
|
|
11
12
|
const filesCache: Record<string, string> = {};
|
|
12
13
|
|
|
@@ -39,7 +40,12 @@ export type GetFileTokensOpts = {
|
|
|
39
40
|
content?: string;
|
|
40
41
|
};
|
|
41
42
|
|
|
42
|
-
export function getFileTokens(
|
|
43
|
+
export function getFileTokens(
|
|
44
|
+
path: string,
|
|
45
|
+
state: StateCore,
|
|
46
|
+
options: GetFileTokensOpts,
|
|
47
|
+
content?: string,
|
|
48
|
+
) {
|
|
43
49
|
const {
|
|
44
50
|
getVarsPerFile,
|
|
45
51
|
vars,
|
|
@@ -51,7 +57,6 @@ export function getFileTokens(path: string, state: StateCore, options: GetFileTo
|
|
|
51
57
|
inheritVars = true,
|
|
52
58
|
conditionsInCode,
|
|
53
59
|
} = options;
|
|
54
|
-
let {content} = options;
|
|
55
60
|
|
|
56
61
|
const builtVars = (getVarsPerFile && !inheritVars ? getVarsPerFile(path) : vars) || {};
|
|
57
62
|
|
|
@@ -77,6 +82,9 @@ export function getFileTokens(path: string, state: StateCore, options: GetFileTo
|
|
|
77
82
|
sourceMap = liquidResult.sourceMap;
|
|
78
83
|
}
|
|
79
84
|
|
|
85
|
+
// Run preprocessor
|
|
86
|
+
content = preprocess(content, options);
|
|
87
|
+
|
|
80
88
|
if (!disableLint && lintMarkdown) {
|
|
81
89
|
lintMarkdown({
|
|
82
90
|
input: content,
|
|
@@ -6,7 +6,7 @@ import union from 'lodash/union';
|
|
|
6
6
|
import attrs from 'markdown-it-attrs';
|
|
7
7
|
|
|
8
8
|
import {LogLevels, Logger} from '../log';
|
|
9
|
-
import
|
|
9
|
+
import {preprocess} from '../preprocessors';
|
|
10
10
|
|
|
11
11
|
import baseDefaultLintConfig from './yfmlint';
|
|
12
12
|
import {
|
|
@@ -29,13 +29,7 @@ const lintCache = new Set();
|
|
|
29
29
|
|
|
30
30
|
function yfmlint(opts: Options) {
|
|
31
31
|
let {input} = opts;
|
|
32
|
-
const {
|
|
33
|
-
plugins: customPlugins,
|
|
34
|
-
preprocessors = defaultPreprocessors,
|
|
35
|
-
pluginOptions,
|
|
36
|
-
customLintRules,
|
|
37
|
-
sourceMap,
|
|
38
|
-
} = opts;
|
|
32
|
+
const {plugins: customPlugins, pluginOptions, customLintRules, sourceMap} = opts;
|
|
39
33
|
const {path = 'input', log} = pluginOptions;
|
|
40
34
|
|
|
41
35
|
pluginOptions.isLintRun = true;
|
|
@@ -65,9 +59,8 @@ function yfmlint(opts: Options) {
|
|
|
65
59
|
const plugins = customPlugins && [attrs, ...customPlugins];
|
|
66
60
|
const preparedPlugins = plugins && plugins.map((plugin) => [plugin, pluginOptions]);
|
|
67
61
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
62
|
+
// Run preprocessor
|
|
63
|
+
input = preprocess(input, pluginOptions, opts);
|
|
71
64
|
|
|
72
65
|
let result;
|
|
73
66
|
try {
|
package/lib/preprocessors.d.ts
DELETED
package/lib/preprocessors.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
const included_1 = __importDefault(require("./preprocessors/included"));
|
|
6
|
-
const defaultPreprocessors = [included_1.default];
|
|
7
|
-
module.exports = defaultPreprocessors;
|
|
8
|
-
//# sourceMappingURL=preprocessors.js.map
|
package/lib/preprocessors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preprocessors.js","sourceRoot":"","sources":["../src/transform/preprocessors.ts"],"names":[],"mappings":";;;;AAEA,wEAAgD;AAEhD,MAAM,oBAAoB,GAAG,CAAC,kBAAQ,CAA+B,CAAC;AAEtE,iBAAS,oBAAoB,CAAC"}
|
package/src/scss/_cut.scss
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
.yfm-cut {
|
|
2
|
-
$class: &;
|
|
3
|
-
margin-bottom: 15px;
|
|
4
|
-
|
|
5
|
-
&-title {
|
|
6
|
-
list-style: none;
|
|
7
|
-
cursor: pointer;
|
|
8
|
-
position: relative;
|
|
9
|
-
user-select: none;
|
|
10
|
-
padding: 5px 0 5px 30px;
|
|
11
|
-
|
|
12
|
-
&::-webkit-details-marker {
|
|
13
|
-
display: none;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
&:focus {
|
|
17
|
-
outline-color: var(--yfm-color-accent);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
&:before {
|
|
21
|
-
content: '';
|
|
22
|
-
z-index: 1;
|
|
23
|
-
left: 0;
|
|
24
|
-
top: 50%;
|
|
25
|
-
background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiI+CiAgICA8cGF0aCBzdHJva2U9ImN1cnJlbnRDb2xvciIgZmlsbD0ibm9uZSIgZD0iTTMgNmw1IDUgNS01Ii8+Cjwvc3ZnPgo=');
|
|
26
|
-
transform: translateY(-50%) rotate(-90deg);
|
|
27
|
-
transition: transform 0.3s ease;
|
|
28
|
-
height: 20px;
|
|
29
|
-
width: 20px;
|
|
30
|
-
position: absolute;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
&-content {
|
|
35
|
-
padding: 5px 0 15px 30px;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
&.open {
|
|
39
|
-
> #{$class}-title:before {
|
|
40
|
-
transform: translateY(-50%);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
.yfm:not(.yfm_no-list-reset) & ol {
|
|
45
|
-
counter-reset: cut-list;
|
|
46
|
-
|
|
47
|
-
& > li {
|
|
48
|
-
counter-increment: cut-list;
|
|
49
|
-
|
|
50
|
-
&::before {
|
|
51
|
-
content: counters(cut-list, '.') '. ';
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|