@diplodoc/transform 4.48.3 → 4.49.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 +1 -0
- package/README.ru.md +1 -0
- package/dist/css/_yfm-only.css.map +1 -1
- package/dist/css/_yfm-only.min.css.map +1 -1
- package/dist/css/base.css +2 -0
- package/dist/css/base.css.map +3 -3
- package/dist/css/base.min.css +1 -1
- package/dist/css/base.min.css.map +3 -3
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css +2 -0
- 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/index.d.ts +6 -5
- package/lib/index.js +7 -23
- package/lib/index.js.map +1 -1
- package/lib/typings.d.ts +1 -5
- package/package.json +1 -1
- package/src/scss/_common.scss +1 -0
- package/src/transform/index.ts +13 -39
- package/src/transform/typings.ts +1 -7
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type Token from 'markdown-it/lib/token';
|
|
2
|
+
import type { OptionsType, OutputType } from './typings';
|
|
3
|
+
declare type TokensOptionsType = OptionsType & {
|
|
4
|
+
tokens: true;
|
|
5
5
|
};
|
|
6
|
-
declare
|
|
6
|
+
declare function transform(originInput: string, options: TokensOptionsType): Token[];
|
|
7
|
+
declare function transform(originInput: string, options?: OptionsType): OutputType;
|
|
7
8
|
export = transform;
|
|
8
9
|
declare namespace transform {
|
|
9
10
|
type Options = OptionsType;
|
package/lib/index.js
CHANGED
|
@@ -22,35 +22,19 @@ function emitResult(html, env) {
|
|
|
22
22
|
logs: log_1.log.get(),
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
const transform = (originInput, options = {}) => {
|
|
25
|
+
function transform(originInput, options = {}) {
|
|
27
26
|
const input = applyLiquid(originInput, options);
|
|
28
27
|
const { parse, compile, env } = (0, md_1.default)(options);
|
|
29
28
|
try {
|
|
30
|
-
|
|
29
|
+
const tokens = parse(input);
|
|
30
|
+
if (options.tokens === true) {
|
|
31
|
+
return tokens;
|
|
32
|
+
}
|
|
33
|
+
return emitResult(compile(tokens), env);
|
|
31
34
|
}
|
|
32
35
|
catch (error) {
|
|
33
36
|
handleError(error, options.path);
|
|
34
37
|
}
|
|
35
|
-
}
|
|
36
|
-
transform.collect = (input,
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
-
{ mdItInitOptions, pluginCollectOptions, parserPluginsOverride }) => {
|
|
39
|
-
var _a;
|
|
40
|
-
const maybeLiquidedInput = applyLiquid(input, mdItInitOptions);
|
|
41
|
-
const { parse } = (0, md_1.default)(Object.assign(Object.assign({}, mdItInitOptions), { plugins: parserPluginsOverride !== null && parserPluginsOverride !== void 0 ? parserPluginsOverride : mdItInitOptions.plugins }));
|
|
42
|
-
const plugins = (_a = mdItInitOptions.plugins) !== null && _a !== void 0 ? _a : [];
|
|
43
|
-
try {
|
|
44
|
-
const tokenStream = parse(maybeLiquidedInput);
|
|
45
|
-
return plugins.reduce((collected, plugin) => {
|
|
46
|
-
var _a;
|
|
47
|
-
const collectOutput = (_a = plugin.collect) === null || _a === void 0 ? void 0 : _a.call(plugin, collected, Object.assign(Object.assign({}, pluginCollectOptions), { tokenStream }));
|
|
48
|
-
return collectOutput !== null && collectOutput !== void 0 ? collectOutput : collected;
|
|
49
|
-
}, maybeLiquidedInput);
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
handleError(error, mdItInitOptions.path);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
38
|
+
}
|
|
55
39
|
module.exports = transform;
|
|
56
40
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/transform/index.ts"],"names":[],"mappings":";;;;
|
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AC;SACjB;QAED,OAAO,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC;KAC3C;IAAC,OAAO,KAAK,EAAE;QACZ,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;KACpC;AACL,CAAC;AAED,iBAAS,SAAS,CAAC"}
|
package/lib/typings.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare type Heading = {
|
|
|
23
23
|
items?: Heading[];
|
|
24
24
|
};
|
|
25
25
|
export interface OptionsType {
|
|
26
|
+
tokens?: boolean;
|
|
26
27
|
vars?: Record<string, string>;
|
|
27
28
|
path?: string;
|
|
28
29
|
extractTitle?: boolean;
|
|
@@ -89,11 +90,6 @@ export declare type IntrinsicCollectOptions = {
|
|
|
89
90
|
export declare type ExtendedPluginWithCollect<PluginRegularOptions extends {} = {}, PluginCollectOptions = {}> = MarkdownItPluginCb<PluginRegularOptions> & {
|
|
90
91
|
collect?: (input: string, options: PluginCollectOptions & IntrinsicCollectOptions) => string | void;
|
|
91
92
|
};
|
|
92
|
-
export declare type RootCollectorOptions<PluginCollectOptions> = {
|
|
93
|
-
mdItInitOptions: OptionsType;
|
|
94
|
-
pluginCollectOptions: PluginCollectOptions;
|
|
95
|
-
parserPluginsOverride?: ExtendedPluginWithCollect<any, any>[];
|
|
96
|
-
};
|
|
97
93
|
export declare type MarkdownItPreprocessorCb<T extends unknown = {}> = {
|
|
98
94
|
(input: string, opts: T & Partial<MarkdownItPluginOpts>, md?: MarkdownIt): string;
|
|
99
95
|
};
|
package/package.json
CHANGED
package/src/scss/_common.scss
CHANGED
package/src/transform/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type Token from 'markdown-it/lib/token';
|
|
2
|
+
import type {EnvType, OptionsType, OutputType} from './typings';
|
|
2
3
|
|
|
3
4
|
import {bold} from 'chalk';
|
|
4
5
|
|
|
@@ -33,52 +34,25 @@ function emitResult(html: string, env: EnvType): OutputType {
|
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
type
|
|
37
|
-
(originInput: string, options?: OptionsType): OutputType;
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
-
collect: (input: string, options: RootCollectorOptions<any>) => string;
|
|
40
|
-
};
|
|
37
|
+
type TokensOptionsType = OptionsType & {tokens: true};
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
function transform(originInput: string, options: TokensOptionsType): Token[];
|
|
40
|
+
function transform(originInput: string, options?: OptionsType): OutputType;
|
|
41
|
+
function transform(originInput: string, options: OptionsType = {}): OutputType | Token[] {
|
|
44
42
|
const input = applyLiquid(originInput, options);
|
|
45
43
|
const {parse, compile, env} = initMarkdownIt(options);
|
|
46
44
|
|
|
47
45
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
transform.collect = (
|
|
55
|
-
input: string,
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
-
{mdItInitOptions, pluginCollectOptions, parserPluginsOverride}: RootCollectorOptions<any>,
|
|
58
|
-
) => {
|
|
59
|
-
const maybeLiquidedInput = applyLiquid(input, mdItInitOptions);
|
|
60
|
-
const {parse} = initMarkdownIt({
|
|
61
|
-
...mdItInitOptions,
|
|
62
|
-
plugins: parserPluginsOverride ?? mdItInitOptions.plugins,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const plugins = mdItInitOptions.plugins ?? [];
|
|
46
|
+
const tokens = parse(input);
|
|
47
|
+
if (options.tokens === true) {
|
|
48
|
+
return tokens;
|
|
49
|
+
}
|
|
66
50
|
|
|
67
|
-
|
|
68
|
-
const tokenStream = parse(maybeLiquidedInput);
|
|
69
|
-
|
|
70
|
-
return plugins.reduce((collected, plugin) => {
|
|
71
|
-
const collectOutput = plugin.collect?.(collected, {
|
|
72
|
-
...pluginCollectOptions,
|
|
73
|
-
tokenStream,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return collectOutput ?? collected;
|
|
77
|
-
}, maybeLiquidedInput);
|
|
51
|
+
return emitResult(compile(tokens), env);
|
|
78
52
|
} catch (error) {
|
|
79
|
-
handleError(error,
|
|
53
|
+
handleError(error, options.path);
|
|
80
54
|
}
|
|
81
|
-
}
|
|
55
|
+
}
|
|
82
56
|
|
|
83
57
|
export = transform;
|
|
84
58
|
|
package/src/transform/typings.ts
CHANGED
|
@@ -30,6 +30,7 @@ export type Heading = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
export interface OptionsType {
|
|
33
|
+
tokens?: boolean;
|
|
33
34
|
vars?: Record<string, string>;
|
|
34
35
|
path?: string;
|
|
35
36
|
extractTitle?: boolean;
|
|
@@ -111,13 +112,6 @@ export type ExtendedPluginWithCollect<
|
|
|
111
112
|
) => string | void;
|
|
112
113
|
};
|
|
113
114
|
|
|
114
|
-
export type RootCollectorOptions<PluginCollectOptions> = {
|
|
115
|
-
mdItInitOptions: OptionsType;
|
|
116
|
-
pluginCollectOptions: PluginCollectOptions;
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
-
parserPluginsOverride?: ExtendedPluginWithCollect<any, any>[];
|
|
119
|
-
};
|
|
120
|
-
|
|
121
115
|
export type MarkdownItPreprocessorCb<T extends unknown = {}> = {
|
|
122
116
|
(input: string, opts: T & Partial<MarkdownItPluginOpts>, md?: MarkdownIt): string;
|
|
123
117
|
};
|