@docusaurus/mdx-loader 2.4.0 → 3.0.0-alpha.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 +13 -0
- package/lib/format.d.ts +12 -0
- package/lib/format.d.ts.map +1 -0
- package/lib/format.js +35 -0
- package/lib/format.js.map +1 -0
- package/lib/frontMatter.d.ts +12 -0
- package/lib/frontMatter.d.ts.map +1 -0
- package/lib/frontMatter.js +25 -0
- package/lib/frontMatter.js.map +1 -0
- package/lib/index.d.ts +5 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/loader.d.ts +5 -14
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js +38 -81
- package/lib/loader.js.map +1 -1
- package/lib/preprocessor.d.ts +18 -0
- package/lib/preprocessor.d.ts.map +1 -0
- package/lib/preprocessor.js +34 -0
- package/lib/preprocessor.js.map +1 -0
- package/lib/processor.d.ts +36 -0
- package/lib/processor.d.ts.map +1 -0
- package/lib/processor.js +158 -0
- package/lib/processor.js.map +1 -0
- package/lib/remark/admonitions/index.d.ts +4 -9
- package/lib/remark/admonitions/index.d.ts.map +1 -1
- package/lib/remark/admonitions/index.js +70 -128
- package/lib/remark/admonitions/index.js.map +1 -1
- package/lib/remark/details/index.d.ts +9 -0
- package/lib/remark/details/index.d.ts.map +1 -0
- package/lib/remark/details/index.js +23 -0
- package/lib/remark/details/index.js.map +1 -0
- package/lib/remark/head/index.d.ts +9 -0
- package/lib/remark/head/index.d.ts.map +1 -0
- package/lib/remark/head/index.js +23 -0
- package/lib/remark/head/index.js.map +1 -0
- package/lib/remark/headings/index.d.ts.map +1 -1
- package/lib/remark/headings/index.js +3 -3
- package/lib/remark/headings/index.js.map +1 -1
- package/lib/remark/{unwrapMdxCodeBlocks/index.d.ts → mdx1Compat/codeCompatPlugin.d.ts} +2 -2
- package/lib/remark/mdx1Compat/codeCompatPlugin.d.ts.map +1 -0
- package/lib/remark/mdx1Compat/codeCompatPlugin.js +34 -0
- package/lib/remark/mdx1Compat/codeCompatPlugin.js.map +1 -0
- package/lib/remark/mermaid/index.d.ts.map +1 -1
- package/lib/remark/mermaid/index.js +1 -0
- package/lib/remark/mermaid/index.js.map +1 -1
- package/lib/remark/toc/index.d.ts +8 -2
- package/lib/remark/toc/index.d.ts.map +1 -1
- package/lib/remark/toc/index.js +53 -23
- package/lib/remark/toc/index.js.map +1 -1
- package/lib/remark/transformImage/index.d.ts +2 -1
- package/lib/remark/transformImage/index.d.ts.map +1 -1
- package/lib/remark/transformImage/index.js +42 -15
- package/lib/remark/transformImage/index.js.map +1 -1
- package/lib/remark/transformLinks/index.d.ts +2 -1
- package/lib/remark/transformLinks/index.d.ts.map +1 -1
- package/lib/remark/transformLinks/index.js +30 -11
- package/lib/remark/transformLinks/index.js.map +1 -1
- package/lib/remark/utils/index.d.ts +4 -2
- package/lib/remark/utils/index.d.ts.map +1 -1
- package/lib/remark/utils/index.js +68 -11
- package/lib/remark/utils/index.js.map +1 -1
- package/package.json +26 -18
- package/src/format.ts +40 -0
- package/src/frontMatter.ts +31 -0
- package/src/index.ts +6 -6
- package/src/loader.ts +62 -107
- package/src/preprocessor.ts +47 -0
- package/src/processor.ts +241 -0
- package/src/remark/admonitions/README.md +1 -1
- package/src/remark/admonitions/index.ts +92 -171
- package/src/remark/details/index.ts +25 -0
- package/src/remark/head/index.ts +25 -0
- package/src/remark/headings/index.ts +5 -3
- package/src/remark/mdx1Compat/codeCompatPlugin.ts +36 -0
- package/src/remark/mermaid/index.ts +2 -0
- package/src/remark/toc/index.ts +80 -26
- package/src/remark/transformImage/index.ts +54 -19
- package/src/remark/transformLinks/index.ts +44 -17
- package/src/remark/utils/index.ts +77 -9
- package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +0 -1
- package/lib/remark/unwrapMdxCodeBlocks/index.js +0 -29
- package/lib/remark/unwrapMdxCodeBlocks/index.js.map +0 -1
- package/src/deps.d.ts +0 -31
- package/src/remark/unwrapMdxCodeBlocks/index.ts +0 -33
package/lib/processor.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createProcessorCached = exports.createProcessorUncached = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const remark_emoji_1 = tslib_1.__importDefault(require("remark-emoji"));
|
|
12
|
+
const headings_1 = tslib_1.__importDefault(require("./remark/headings"));
|
|
13
|
+
const toc_1 = tslib_1.__importDefault(require("./remark/toc"));
|
|
14
|
+
const transformImage_1 = tslib_1.__importDefault(require("./remark/transformImage"));
|
|
15
|
+
const transformLinks_1 = tslib_1.__importDefault(require("./remark/transformLinks"));
|
|
16
|
+
const details_1 = tslib_1.__importDefault(require("./remark/details"));
|
|
17
|
+
const head_1 = tslib_1.__importDefault(require("./remark/head"));
|
|
18
|
+
const mermaid_1 = tslib_1.__importDefault(require("./remark/mermaid"));
|
|
19
|
+
const admonitions_1 = tslib_1.__importDefault(require("./remark/admonitions"));
|
|
20
|
+
const codeCompatPlugin_1 = tslib_1.__importDefault(require("./remark/mdx1Compat/codeCompatPlugin"));
|
|
21
|
+
const format_1 = require("./format");
|
|
22
|
+
const DEFAULT_OPTIONS = {
|
|
23
|
+
admonitions: true,
|
|
24
|
+
rehypePlugins: [],
|
|
25
|
+
remarkPlugins: [remark_emoji_1.default, headings_1.default, toc_1.default],
|
|
26
|
+
beforeDefaultRemarkPlugins: [],
|
|
27
|
+
beforeDefaultRehypePlugins: [],
|
|
28
|
+
};
|
|
29
|
+
function getAdmonitionsPlugins(admonitionsOption) {
|
|
30
|
+
if (admonitionsOption) {
|
|
31
|
+
const plugin = admonitionsOption === true
|
|
32
|
+
? admonitions_1.default
|
|
33
|
+
: [admonitions_1.default, admonitionsOption];
|
|
34
|
+
return [plugin];
|
|
35
|
+
}
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
// Need to be async due to ESM dynamic imports...
|
|
39
|
+
async function createProcessorFactory() {
|
|
40
|
+
const { createProcessor: createMdxProcessor } = await import('@mdx-js/mdx');
|
|
41
|
+
const { default: rehypeRaw } = await import('rehype-raw');
|
|
42
|
+
const { default: gfm } = await import('remark-gfm');
|
|
43
|
+
const { default: comment } = await import('remark-comment');
|
|
44
|
+
const { default: directive } = await import('remark-directive');
|
|
45
|
+
// /!\ this method is synchronous on purpose
|
|
46
|
+
// Using async code here can create cache entry race conditions!
|
|
47
|
+
function createProcessorSync({ options, format, }) {
|
|
48
|
+
const remarkPlugins = [
|
|
49
|
+
...(options.beforeDefaultRemarkPlugins ?? []),
|
|
50
|
+
directive,
|
|
51
|
+
...getAdmonitionsPlugins(options.admonitions ?? false),
|
|
52
|
+
...DEFAULT_OPTIONS.remarkPlugins,
|
|
53
|
+
details_1.default,
|
|
54
|
+
head_1.default,
|
|
55
|
+
...(options.markdownConfig.mermaid ? [mermaid_1.default] : []),
|
|
56
|
+
[
|
|
57
|
+
transformImage_1.default,
|
|
58
|
+
{
|
|
59
|
+
staticDirs: options.staticDirs,
|
|
60
|
+
siteDir: options.siteDir,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
transformLinks_1.default,
|
|
65
|
+
{
|
|
66
|
+
staticDirs: options.staticDirs,
|
|
67
|
+
siteDir: options.siteDir,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
gfm,
|
|
71
|
+
options.markdownConfig.mdx1Compat.comments ? comment : null,
|
|
72
|
+
...(options.remarkPlugins ?? []),
|
|
73
|
+
].filter((plugin) => Boolean(plugin));
|
|
74
|
+
// codeCompatPlugin needs to be applied last after user-provided plugins
|
|
75
|
+
// (after npm2yarn for example)
|
|
76
|
+
remarkPlugins.push(codeCompatPlugin_1.default);
|
|
77
|
+
const rehypePlugins = [
|
|
78
|
+
...(options.beforeDefaultRehypePlugins ?? []),
|
|
79
|
+
...DEFAULT_OPTIONS.rehypePlugins,
|
|
80
|
+
...(options.rehypePlugins ?? []),
|
|
81
|
+
];
|
|
82
|
+
if (format === 'md') {
|
|
83
|
+
// This is what permits to embed HTML elements with format 'md'
|
|
84
|
+
// See https://github.com/facebook/docusaurus/pull/8960
|
|
85
|
+
// See https://github.com/mdx-js/mdx/pull/2295#issuecomment-1540085960
|
|
86
|
+
const rehypeRawPlugin = [
|
|
87
|
+
rehypeRaw,
|
|
88
|
+
{
|
|
89
|
+
passThrough: [
|
|
90
|
+
'mdxFlowExpression',
|
|
91
|
+
'mdxJsxFlowElement',
|
|
92
|
+
'mdxJsxTextElement',
|
|
93
|
+
'mdxTextExpression',
|
|
94
|
+
'mdxjsEsm',
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
rehypePlugins.unshift(rehypeRawPlugin);
|
|
99
|
+
}
|
|
100
|
+
const processorOptions = {
|
|
101
|
+
...options,
|
|
102
|
+
remarkPlugins,
|
|
103
|
+
rehypePlugins,
|
|
104
|
+
providerImportSource: '@mdx-js/react',
|
|
105
|
+
};
|
|
106
|
+
const mdxProcessor = createMdxProcessor({
|
|
107
|
+
...processorOptions,
|
|
108
|
+
format,
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
process: async ({ content, filePath }) => mdxProcessor
|
|
112
|
+
.process({
|
|
113
|
+
value: content,
|
|
114
|
+
path: filePath,
|
|
115
|
+
})
|
|
116
|
+
.then((res) => res.toString()),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return { createProcessorSync };
|
|
120
|
+
}
|
|
121
|
+
// Will be useful for tests
|
|
122
|
+
async function createProcessorUncached(parameters) {
|
|
123
|
+
const { createProcessorSync } = await createProcessorFactory();
|
|
124
|
+
return createProcessorSync(parameters);
|
|
125
|
+
}
|
|
126
|
+
exports.createProcessorUncached = createProcessorUncached;
|
|
127
|
+
// Compilers are cached so that Remark/Rehype plugins can run
|
|
128
|
+
// expensive code during initialization
|
|
129
|
+
const ProcessorsCache = new Map();
|
|
130
|
+
async function createProcessorsCacheEntry({ query, reqOptions, }) {
|
|
131
|
+
const { createProcessorSync } = await createProcessorFactory();
|
|
132
|
+
const compilers = ProcessorsCache.get(query);
|
|
133
|
+
if (compilers) {
|
|
134
|
+
return compilers;
|
|
135
|
+
}
|
|
136
|
+
const compilerCacheEntry = {
|
|
137
|
+
mdProcessor: createProcessorSync({
|
|
138
|
+
options: reqOptions,
|
|
139
|
+
format: 'md',
|
|
140
|
+
}),
|
|
141
|
+
mdxProcessor: createProcessorSync({
|
|
142
|
+
options: reqOptions,
|
|
143
|
+
format: 'mdx',
|
|
144
|
+
}),
|
|
145
|
+
};
|
|
146
|
+
ProcessorsCache.set(query, compilerCacheEntry);
|
|
147
|
+
return compilerCacheEntry;
|
|
148
|
+
}
|
|
149
|
+
async function createProcessorCached({ filePath, mdxFrontMatter, query, reqOptions, }) {
|
|
150
|
+
const compilers = await createProcessorsCacheEntry({ query, reqOptions });
|
|
151
|
+
const format = (0, format_1.getFormat)({
|
|
152
|
+
filePath,
|
|
153
|
+
frontMatterFormat: mdxFrontMatter.format,
|
|
154
|
+
});
|
|
155
|
+
return format === 'md' ? compilers.mdProcessor : compilers.mdxProcessor;
|
|
156
|
+
}
|
|
157
|
+
exports.createProcessorCached = createProcessorCached;
|
|
158
|
+
//# sourceMappingURL=processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wEAAiC;AACjC,yEAAyC;AACzC,+DAA+B;AAC/B,qFAAqD;AACrD,qFAAqD;AACrD,uEAAuC;AACvC,iEAAiC;AACjC,uEAAuC;AACvC,+EAAwD;AACxD,oGAA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,EAAE,kBAAkB,CAAC,CAAC;IAE/C,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAEM,KAAK,UAAU,qBAAqB,CAAC,EAC1C,QAAQ,EACR,cAAc,EACd,KAAK,EACL,UAAU,GAMX;IACC,MAAM,SAAS,GAAG,MAAM,0BAA0B,CAAC,EAAC,KAAK,EAAE,UAAU,EAAC,CAAC,CAAC;IAExE,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC;QACvB,QAAQ;QACR,iBAAiB,EAAE,cAAc,CAAC,MAAM;KACzC,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC;AAC1E,CAAC;AAnBD,sDAmBC"}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import type { Plugin } from 'unified';
|
|
8
|
-
export declare type AdmonitionOptions = {
|
|
9
|
-
tag: string;
|
|
1
|
+
type Plugin = any;
|
|
2
|
+
export type AdmonitionOptions = {
|
|
10
3
|
keywords: string[];
|
|
4
|
+
extendDefaults: boolean;
|
|
11
5
|
};
|
|
12
6
|
export declare const DefaultAdmonitionOptions: AdmonitionOptions;
|
|
7
|
+
export declare function normalizeAdmonitionOptions(providedOptions: Partial<AdmonitionOptions> | true): AdmonitionOptions;
|
|
13
8
|
declare const plugin: Plugin;
|
|
14
9
|
export default plugin;
|
|
15
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":"AAkBA,KAAK,MAAM,GAAG,GAAG,CAAC;AAElB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,iBAatC,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,GACjD,iBAAiB,CAiBnB;AA4BD,QAAA,MAAM,MAAM,EAAE,MAqDb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeAdmonitionOptions = exports.DefaultAdmonitionOptions = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
2
5
|
/**
|
|
3
6
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
7
|
*
|
|
5
8
|
* This source code is licensed under the MIT license found in the
|
|
6
9
|
* LICENSE file in the root directory of this source tree.
|
|
7
10
|
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.DefaultAdmonitionOptions = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
11
|
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
12
|
-
const NEWLINE = '\n';
|
|
13
12
|
exports.DefaultAdmonitionOptions = {
|
|
14
|
-
tag: ':::',
|
|
15
13
|
keywords: [
|
|
16
14
|
'secondary',
|
|
17
15
|
'info',
|
|
@@ -23,136 +21,80 @@ exports.DefaultAdmonitionOptions = {
|
|
|
23
21
|
'important',
|
|
24
22
|
'caution',
|
|
25
23
|
],
|
|
24
|
+
extendDefaults: true,
|
|
26
25
|
};
|
|
27
|
-
function
|
|
28
|
-
|
|
26
|
+
function normalizeAdmonitionOptions(providedOptions) {
|
|
27
|
+
if (providedOptions === true) {
|
|
28
|
+
return exports.DefaultAdmonitionOptions;
|
|
29
|
+
}
|
|
30
|
+
const options = { ...exports.DefaultAdmonitionOptions, ...providedOptions };
|
|
31
|
+
// By default it makes more sense to append keywords to the default ones
|
|
32
|
+
// Adding custom keywords is more common than disabling existing ones
|
|
33
|
+
if (options.extendDefaults) {
|
|
34
|
+
options.keywords = [
|
|
35
|
+
...exports.DefaultAdmonitionOptions.keywords,
|
|
36
|
+
...options.keywords,
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
return options;
|
|
40
|
+
}
|
|
41
|
+
exports.normalizeAdmonitionOptions = normalizeAdmonitionOptions;
|
|
42
|
+
function parseDirective(directive) {
|
|
43
|
+
const hasDirectiveLabel = directive.children?.[0]?.data?.directiveLabel === true;
|
|
44
|
+
if (hasDirectiveLabel) {
|
|
45
|
+
const [directiveLabel, ...contentNodes] = directive.children;
|
|
46
|
+
return { directiveLabel: directiveLabel, contentNodes };
|
|
47
|
+
}
|
|
48
|
+
return { directiveLabel: undefined, contentNodes: directive.children };
|
|
29
49
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
50
|
+
function getTextOnlyTitle(directiveLabel) {
|
|
51
|
+
const isTextOnlyTitle = directiveLabel?.children?.length === 1 &&
|
|
52
|
+
directiveLabel?.children?.[0]?.type === 'text';
|
|
53
|
+
return isTextOnlyTitle
|
|
54
|
+
? // @ts-expect-error: todo type
|
|
55
|
+
directiveLabel?.children?.[0].value
|
|
56
|
+
: undefined;
|
|
32
57
|
}
|
|
33
|
-
// This string value does not matter much
|
|
34
|
-
// It is ignored because nodes are using hName/hProperties coming from HAST
|
|
35
|
-
const admonitionNodeType = 'admonitionHTML';
|
|
36
58
|
const plugin = function plugin(optionsInput = {}) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const escapeTag = new RegExp(escapeRegExp(`\\${options.tag}${options.tag.slice(0, 1)}*`), 'g');
|
|
46
|
-
// The tokenizer is called on blocks to determine if there is an admonition
|
|
47
|
-
// present and create tags for it
|
|
48
|
-
function blockTokenizer(eat, value, silent) {
|
|
49
|
-
// Stop if no match or match does not start at beginning of line
|
|
50
|
-
const match = regex.exec(value);
|
|
51
|
-
if (!match || match.index !== 0) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
// If silent return the match
|
|
55
|
-
if (silent) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
const now = eat.now();
|
|
59
|
-
const [opening, keyword, title] = match;
|
|
60
|
-
const food = [];
|
|
61
|
-
const content = [];
|
|
62
|
-
// get the nesting level of the opening tag
|
|
63
|
-
const openingLevel = nestingLevelRegex.exec(opening).groups.nestingLevel.length;
|
|
64
|
-
// used as a stack to keep track of nested admonitions
|
|
65
|
-
const nestingLevels = [openingLevel];
|
|
66
|
-
let newValue = value;
|
|
67
|
-
// consume lines until a closing tag
|
|
68
|
-
let idx = newValue.indexOf(NEWLINE);
|
|
69
|
-
while (idx !== -1) {
|
|
70
|
-
// grab this line and eat it
|
|
71
|
-
const next = newValue.indexOf(NEWLINE, idx + 1);
|
|
72
|
-
const line = next !== -1 ? newValue.slice(idx + 1, next) : newValue.slice(idx + 1);
|
|
73
|
-
food.push(line);
|
|
74
|
-
newValue = newValue.slice(idx + 1);
|
|
75
|
-
const nesting = nestingLevelRegex.exec(line);
|
|
76
|
-
idx = newValue.indexOf(NEWLINE);
|
|
77
|
-
if (!nesting) {
|
|
78
|
-
content.push(line);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
const tagLevel = nesting.groups.nestingLevel.length;
|
|
82
|
-
// first level
|
|
83
|
-
if (nestingLevels.length === 0) {
|
|
84
|
-
nestingLevels.push(tagLevel);
|
|
85
|
-
content.push(line);
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const currentLevel = nestingLevels[nestingLevels.length - 1];
|
|
89
|
-
if (tagLevel < currentLevel) {
|
|
90
|
-
// entering a nested admonition block
|
|
91
|
-
nestingLevels.push(tagLevel);
|
|
92
|
-
}
|
|
93
|
-
else if (tagLevel === currentLevel) {
|
|
94
|
-
// closing a nested admonition block
|
|
95
|
-
nestingLevels.pop();
|
|
96
|
-
// the closing tag is NOT part of the content
|
|
97
|
-
if (nestingLevels.length === 0) {
|
|
98
|
-
break;
|
|
59
|
+
const { keywords } = normalizeAdmonitionOptions(optionsInput);
|
|
60
|
+
return async (root) => {
|
|
61
|
+
(0, unist_util_visit_1.default)(root, (node) => {
|
|
62
|
+
if (node.type === 'containerDirective') {
|
|
63
|
+
const directive = node;
|
|
64
|
+
const isAdmonition = keywords.includes(directive.name);
|
|
65
|
+
if (!isAdmonition) {
|
|
66
|
+
return;
|
|
99
67
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const contentString = content.join(NEWLINE).replace(escapeTag, options.tag);
|
|
105
|
-
const add = eat(opening + food.join(NEWLINE));
|
|
106
|
-
// parse the content in block mode
|
|
107
|
-
const exit = this.enterBlock();
|
|
108
|
-
const contentNodes = this.tokenizeBlock(contentString, now);
|
|
109
|
-
exit();
|
|
110
|
-
const titleNodes = this.tokenizeInline(title, now);
|
|
111
|
-
const isSimpleTextTitle = titleNodes.length === 1 && titleNodes[0].type === 'text';
|
|
112
|
-
const element = {
|
|
113
|
-
type: admonitionNodeType,
|
|
114
|
-
data: {
|
|
115
|
-
// hName/hProperties come from HAST
|
|
68
|
+
const { directiveLabel, contentNodes } = parseDirective(directive);
|
|
69
|
+
const textOnlyTitle = directive.attributes?.title ??
|
|
70
|
+
(directiveLabel ? getTextOnlyTitle(directiveLabel) : undefined);
|
|
71
|
+
// Transform the mdast directive node to a hast admonition node
|
|
116
72
|
// See https://github.com/syntax-tree/mdast-util-to-hast#fields-on-nodes
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// For titles containing MDX syntax: create a custom element. The theme
|
|
125
|
-
// component will extract it and render it nicely.
|
|
126
|
-
//
|
|
127
|
-
// Temporary workaround, because it's complex in MDX v1 to emit
|
|
128
|
-
// interpolated JSX prop syntax (title={<>my <code>title</code></>}).
|
|
129
|
-
// For this reason, we use children instead of the title prop.
|
|
130
|
-
title &&
|
|
131
|
-
!isSimpleTextTitle && {
|
|
132
|
-
type: admonitionNodeType,
|
|
133
|
-
data: {
|
|
134
|
-
hName: 'mdxAdmonitionTitle',
|
|
135
|
-
hProperties: {},
|
|
73
|
+
// TODO in MDX v2 we should transform the whole directive to
|
|
74
|
+
// mdxJsxFlowElement instead of using hast
|
|
75
|
+
directive.data = {
|
|
76
|
+
hName: 'admonition',
|
|
77
|
+
hProperties: {
|
|
78
|
+
...(textOnlyTitle && { title: textOnlyTitle }),
|
|
79
|
+
type: directive.name,
|
|
136
80
|
},
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (node.value) {
|
|
155
|
-
node.value = node.value.replace(escapeTag, options.tag);
|
|
81
|
+
};
|
|
82
|
+
directive.children = contentNodes;
|
|
83
|
+
// TODO legacy MDX v1 <mdxAdmonitionTitle> workaround
|
|
84
|
+
// v1: not possible to inject complex JSX elements as props
|
|
85
|
+
// v2: now possible: use a mdxJsxFlowElement element
|
|
86
|
+
if (directiveLabel && !textOnlyTitle) {
|
|
87
|
+
const complexTitleNode = {
|
|
88
|
+
type: 'mdxAdmonitionTitle',
|
|
89
|
+
data: {
|
|
90
|
+
hName: 'mdxAdmonitionTitle',
|
|
91
|
+
hProperties: {},
|
|
92
|
+
},
|
|
93
|
+
children: directiveLabel.children,
|
|
94
|
+
};
|
|
95
|
+
// @ts-expect-error: invented node type
|
|
96
|
+
directive.children.unshift(complexTitleNode);
|
|
97
|
+
}
|
|
156
98
|
}
|
|
157
99
|
});
|
|
158
100
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":";;;;AAAA;;;;;GAKG;AACH,gFAAqC;AAmBxB,QAAA,wBAAwB,GAAsB;IACzD,QAAQ,EAAE;QACR,WAAW;QACX,MAAM;QACN,SAAS;QACT,QAAQ;QACR,MAAM;QACN,KAAK;QACL,SAAS;QACT,WAAW;QACX,SAAS;KACV;IACD,cAAc,EAAE,IAAI;CACrB,CAAC;AAEF,SAAgB,0BAA0B,CACxC,eAAkD;IAElD,IAAI,eAAe,KAAK,IAAI,EAAE;QAC5B,OAAO,gCAAwB,CAAC;KACjC;IAED,MAAM,OAAO,GAAG,EAAC,GAAG,gCAAwB,EAAE,GAAG,eAAe,EAAC,CAAC;IAElE,wEAAwE;IACxE,qEAAqE;IACrE,IAAI,OAAO,CAAC,cAAc,EAAE;QAC1B,OAAO,CAAC,QAAQ,GAAG;YACjB,GAAG,gCAAwB,CAAC,QAAQ;YACpC,GAAG,OAAO,CAAC,QAAQ;SACpB,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAnBD,gEAmBC;AAKD,SAAS,cAAc,CAAC,SAA6B;IAInD,MAAM,iBAAiB,GACrB,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;IACzD,IAAI,iBAAiB,EAAE;QACrB,MAAM,CAAC,cAAc,EAAE,GAAG,YAAY,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC;QAC7D,OAAO,EAAC,cAAc,EAAE,cAAgC,EAAE,YA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AG;oBACf,KAAK,EAAE,YAAY;oBACnB,WAAW,EAAE;wBACX,GAAG,CAAC,aAAa,IAAI,EAAC,KAAK,EAAE,aAAa,EAAC,CAAC;wBAC5C,IAAI,EAAE,SAAS,CAAC,IAAI;qBACrB;iBACF,CAAC;gBACF,SAAS,CAAC,QAAQ,GAAG,YAAY,CAAC;gBAElC,qDAAqD;gBACrD,2DAA2D;gBAC3D,oDAAoD;gBACpD,IAAI,cAAc,IAAI,CAAC,aAAa,EAAE;oBACpC,MAAM,gBAAgB,GAAG;wBACvB,IAAI,EAAE,oBAAoB;wBAC1B,IAAI,EAAE;4BACJ,KAAK,EAAE,oBAAoB;4BAC3B,WAAW,EAAE,EAAE;yBAChB;wBACD,QAAQ,EAAE,cAAc,CAAC,QAAQ;qBAClC,CAAC;oBACF,uCAAuC;oBACvC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;iBAC9C;aACF;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Transformer } from 'unified';
|
|
8
|
+
export default function plugin(): Transformer;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/details/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAOzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAQ5C"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
11
|
+
// Transform <details> to <Details>
|
|
12
|
+
// MDX 2 doesn't allow to substitute html elements with the provider anymore
|
|
13
|
+
function plugin() {
|
|
14
|
+
return (root) => {
|
|
15
|
+
(0, unist_util_visit_1.default)(root, 'mdxJsxFlowElement', (node) => {
|
|
16
|
+
if (node.name === 'details') {
|
|
17
|
+
node.name = 'Details';
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.default = plugin;
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/details/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gFAAqC;AAOrC,mCAAmC;AACnC,4EAA4E;AAC5E,SAAwB,MAAM;IAC5B,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAA,0BAAK,EAAC,IAAI,EAAE,mBAAmB,EAAE,CAAC,IAAuB,EAAE,EAAE;YAC3D,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;gBAC3B,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;aACvB;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AARD,yBAQC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Transformer } from 'unified';
|
|
8
|
+
export default function plugin(): Transformer;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/head/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAOzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAQ5C"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
11
|
+
// Transform <head> to <Head>
|
|
12
|
+
// MDX 2 doesn't allow to substitute html elements with the provider anymore
|
|
13
|
+
function plugin() {
|
|
14
|
+
return (root) => {
|
|
15
|
+
(0, unist_util_visit_1.default)(root, 'mdxJsxFlowElement', (node) => {
|
|
16
|
+
if (node.name === 'head') {
|
|
17
|
+
node.name = 'Head';
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.default = plugin;
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/head/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gFAAqC;AAOrC,6BAA6B;AAC7B,4EAA4E;AAC5E,SAAwB,MAAM;IAC5B,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAA,0BAAK,EAAC,IAAI,EAAE,mBAAmB,EAAE,CAAC,IAAuB,EAAE,EAAE;YAC3D,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;gBACxB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;aACpB;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AARD,yBAQC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAGzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAGzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAwD5C"}
|
|
@@ -10,9 +10,9 @@ const tslib_1 = require("tslib");
|
|
|
10
10
|
/* Based on remark-slug (https://github.com/remarkjs/remark-slug) and gatsby-remark-autolink-headers (https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-autolink-headers) */
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
12
|
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
13
|
-
const mdast_util_to_string_1 = tslib_1.__importDefault(require("mdast-util-to-string"));
|
|
14
13
|
function plugin() {
|
|
15
|
-
return (root) => {
|
|
14
|
+
return async (root) => {
|
|
15
|
+
const { toString } = await import('mdast-util-to-string');
|
|
16
16
|
const slugs = (0, utils_1.createSlugger)();
|
|
17
17
|
(0, unist_util_visit_1.default)(root, 'heading', (headingNode) => {
|
|
18
18
|
const data = headingNode.data ?? (headingNode.data = {});
|
|
@@ -23,7 +23,7 @@ function plugin() {
|
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
const headingTextNodes = headingNode.children.filter(({ type }) => !['html', 'jsx'].includes(type));
|
|
26
|
-
const heading = (
|
|
26
|
+
const heading = toString(headingTextNodes.length > 0 ? headingTextNodes : headingNode);
|
|
27
27
|
// Support explicit heading IDs
|
|
28
28
|
const parsedHeading = (0, utils_1.parseMarkdownHeadingId)(heading);
|
|
29
29
|
id = parsedHeading.id ?? slugs.slug(heading);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gMAAgM;AAEhM,6CAAwE;AACxE,gFAAqC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gMAAgM;AAEhM,6CAAwE;AACxE,gFAAqC;AAKrC,SAAwB,MAAM;IAC5B,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,MAAM,EAAC,QAAQ,EAAC,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;QAExD,MAAM,KAAK,GAAG,IAAA,qBAAa,GAAE,CAAC;QAC9B,IAAA,0BAAK,EAAC,IAAI,EAAE,SAAS,EAAE,CAAC,WAAoB,EAAE,EAAE;YAC9C,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;YACzD,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,CAE9D,CAAC;YACF,IAAI,EAAC,EAAE,EAAC,GAAG,UAAU,CAAC;YAEtB,IAAI,EAAE,EAAE;gBACN,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,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,GAAG,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAxDD,yBAwDC"}
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Transformer, Processor } from 'unified';
|
|
8
|
-
export default function
|
|
9
|
-
//# sourceMappingURL=
|
|
8
|
+
export default function codeCompatPlugin(this: Processor): Transformer;
|
|
9
|
+
//# sourceMappingURL=codeCompatPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeCompatPlugin.d.ts","sourceRoot":"","sources":["../../../src/remark/mdx1Compat/codeCompatPlugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,WAAW,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AAUpD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,CAgBrE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
11
|
+
// Solution inspired by https://github.com/pomber/docusaurus-mdx-2/blob/main/packages/mdx-loader/src/remark/codeCompat/index.ts
|
|
12
|
+
// TODO after MDX 2 we probably don't need this - remove soon?
|
|
13
|
+
// Only fenced code blocks are swapped by pre/code MDX components
|
|
14
|
+
// Using <pre><code> in JSX shouldn't use our MDX components anymore
|
|
15
|
+
// To make theme-classic/src/theme/MDXComponents/Pre work
|
|
16
|
+
// we need to fill two properties that mdx v2 doesn't provide anymore
|
|
17
|
+
function codeCompatPlugin() {
|
|
18
|
+
return (root) => {
|
|
19
|
+
(0, unist_util_visit_1.default)(root, 'code', (node) => {
|
|
20
|
+
node.data = node.data || {};
|
|
21
|
+
node.data.hProperties = node.data.hProperties || {};
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
node.data.hProperties.metastring = node.meta;
|
|
24
|
+
// Retrocompatible support for live codeblock metastring
|
|
25
|
+
// Not really the appropriate place to handle that :s
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
node.data.hProperties.live = node.meta
|
|
28
|
+
?.split(' ')
|
|
29
|
+
.includes('live');
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.default = codeCompatPlugin;
|
|
34
|
+
//# sourceMappingURL=codeCompatPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeCompatPlugin.js","sourceRoot":"","sources":["../../../src/remark/mdx1Compat/codeCompatPlugin.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gFAAqC;AAKrC,+HAA+H;AAC/H,8DAA8D;AAC9D,iEAAiE;AACjE,oEAAoE;AAEpE,yDAAyD;AACzD,qEAAqE;AACrE,SAAwB,gBAAgB;IACtC,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAA,0BAAK,EAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAU,EAAE,EAAE;YACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;YACpD,8DAA8D;YAC7D,IAAI,CAAC,IAAI,CAAC,WAAmB,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;YAEtD,wDAAwD;YACxD,qDAAqD;YACrD,8DAA8D;YAC7D,IAAI,CAAC,IAAI,CAAC,WAAmB,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI;gBAC7C,EAAE,KAAK,CAAC,GAAG,CAAC;iBACX,QAAQ,CAAC,MAAM,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAhBD,mCAgBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/mermaid/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/mermaid/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAOzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAiB5C"}
|