@docusaurus/mdx-loader 2.4.1 → 3.0.0-beta.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.
Files changed (85) hide show
  1. package/README.md +13 -0
  2. package/lib/format.d.ts +14 -0
  3. package/lib/format.d.ts.map +1 -0
  4. package/lib/format.js +42 -0
  5. package/lib/format.js.map +1 -0
  6. package/lib/frontMatter.d.ts +13 -0
  7. package/lib/frontMatter.d.ts.map +1 -0
  8. package/lib/frontMatter.js +23 -0
  9. package/lib/frontMatter.js.map +1 -0
  10. package/lib/index.d.ts +7 -7
  11. package/lib/index.d.ts.map +1 -1
  12. package/lib/index.js.map +1 -1
  13. package/lib/loader.d.ts +5 -14
  14. package/lib/loader.d.ts.map +1 -1
  15. package/lib/loader.js +45 -81
  16. package/lib/loader.js.map +1 -1
  17. package/lib/preprocessor.d.ts +18 -0
  18. package/lib/preprocessor.d.ts.map +1 -0
  19. package/lib/preprocessor.js +34 -0
  20. package/lib/preprocessor.js.map +1 -0
  21. package/lib/processor.d.ts +36 -0
  22. package/lib/processor.d.ts.map +1 -0
  23. package/lib/processor.js +160 -0
  24. package/lib/processor.js.map +1 -0
  25. package/lib/remark/admonitions/index.d.ts +4 -9
  26. package/lib/remark/admonitions/index.d.ts.map +1 -1
  27. package/lib/remark/admonitions/index.js +70 -128
  28. package/lib/remark/admonitions/index.js.map +1 -1
  29. package/lib/remark/details/index.d.ts +9 -0
  30. package/lib/remark/details/index.d.ts.map +1 -0
  31. package/lib/remark/details/index.js +23 -0
  32. package/lib/remark/details/index.js.map +1 -0
  33. package/lib/remark/head/index.d.ts +9 -0
  34. package/lib/remark/head/index.d.ts.map +1 -0
  35. package/lib/remark/head/index.js +23 -0
  36. package/lib/remark/head/index.js.map +1 -0
  37. package/lib/remark/headings/index.d.ts.map +1 -1
  38. package/lib/remark/headings/index.js +3 -3
  39. package/lib/remark/headings/index.js.map +1 -1
  40. package/lib/remark/{unwrapMdxCodeBlocks/index.d.ts → mdx1Compat/codeCompatPlugin.d.ts} +2 -2
  41. package/lib/remark/mdx1Compat/codeCompatPlugin.d.ts.map +1 -0
  42. package/lib/remark/mdx1Compat/codeCompatPlugin.js +34 -0
  43. package/lib/remark/mdx1Compat/codeCompatPlugin.js.map +1 -0
  44. package/lib/remark/mermaid/index.d.ts.map +1 -1
  45. package/lib/remark/mermaid/index.js +1 -0
  46. package/lib/remark/mermaid/index.js.map +1 -1
  47. package/lib/remark/toc/index.d.ts +8 -2
  48. package/lib/remark/toc/index.d.ts.map +1 -1
  49. package/lib/remark/toc/index.js +53 -23
  50. package/lib/remark/toc/index.js.map +1 -1
  51. package/lib/remark/transformImage/index.d.ts +2 -1
  52. package/lib/remark/transformImage/index.d.ts.map +1 -1
  53. package/lib/remark/transformImage/index.js +42 -15
  54. package/lib/remark/transformImage/index.js.map +1 -1
  55. package/lib/remark/transformLinks/index.d.ts +2 -1
  56. package/lib/remark/transformLinks/index.d.ts.map +1 -1
  57. package/lib/remark/transformLinks/index.js +30 -11
  58. package/lib/remark/transformLinks/index.js.map +1 -1
  59. package/lib/remark/utils/index.d.ts +4 -2
  60. package/lib/remark/utils/index.d.ts.map +1 -1
  61. package/lib/remark/utils/index.js +82 -11
  62. package/lib/remark/utils/index.js.map +1 -1
  63. package/package.json +28 -20
  64. package/src/format.ts +50 -0
  65. package/src/frontMatter.ts +31 -0
  66. package/src/index.ts +10 -6
  67. package/src/loader.ts +72 -107
  68. package/src/preprocessor.ts +47 -0
  69. package/src/processor.ts +243 -0
  70. package/src/remark/admonitions/README.md +1 -1
  71. package/src/remark/admonitions/index.ts +92 -171
  72. package/src/remark/details/index.ts +25 -0
  73. package/src/remark/head/index.ts +25 -0
  74. package/src/remark/headings/index.ts +5 -3
  75. package/src/remark/mdx1Compat/codeCompatPlugin.ts +36 -0
  76. package/src/remark/mermaid/index.ts +2 -0
  77. package/src/remark/toc/index.ts +80 -26
  78. package/src/remark/transformImage/index.ts +54 -19
  79. package/src/remark/transformLinks/index.ts +44 -17
  80. package/src/remark/utils/index.ts +108 -9
  81. package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +0 -1
  82. package/lib/remark/unwrapMdxCodeBlocks/index.js +0 -29
  83. package/lib/remark/unwrapMdxCodeBlocks/index.js.map +0 -1
  84. package/src/deps.d.ts +0 -31
  85. package/src/remark/unwrapMdxCodeBlocks/index.ts +0 -33
@@ -0,0 +1,160 @@
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: [headings_1.default, remark_emoji_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
+ // TODO using fork until PR merged: https://github.com/leebyron/remark-comment/pull/3
44
+ const { default: comment } = await import('@slorber/remark-comment');
45
+ const { default: directive } = await import('remark-directive');
46
+ // /!\ this method is synchronous on purpose
47
+ // Using async code here can create cache entry race conditions!
48
+ function createProcessorSync({ options, format, }) {
49
+ const remarkPlugins = [
50
+ ...(options.beforeDefaultRemarkPlugins ?? []),
51
+ directive,
52
+ ...getAdmonitionsPlugins(options.admonitions ?? false),
53
+ ...DEFAULT_OPTIONS.remarkPlugins,
54
+ details_1.default,
55
+ head_1.default,
56
+ ...(options.markdownConfig.mermaid ? [mermaid_1.default] : []),
57
+ [
58
+ transformImage_1.default,
59
+ {
60
+ staticDirs: options.staticDirs,
61
+ siteDir: options.siteDir,
62
+ },
63
+ ],
64
+ [
65
+ transformLinks_1.default,
66
+ {
67
+ staticDirs: options.staticDirs,
68
+ siteDir: options.siteDir,
69
+ },
70
+ ],
71
+ gfm,
72
+ options.markdownConfig.mdx1Compat.comments ? comment : null,
73
+ ...(options.remarkPlugins ?? []),
74
+ ].filter((plugin) => Boolean(plugin));
75
+ // codeCompatPlugin needs to be applied last after user-provided plugins
76
+ // (after npm2yarn for example)
77
+ remarkPlugins.push(codeCompatPlugin_1.default);
78
+ const rehypePlugins = [
79
+ ...(options.beforeDefaultRehypePlugins ?? []),
80
+ ...DEFAULT_OPTIONS.rehypePlugins,
81
+ ...(options.rehypePlugins ?? []),
82
+ ];
83
+ if (format === 'md') {
84
+ // This is what permits to embed HTML elements with format 'md'
85
+ // See https://github.com/facebook/docusaurus/pull/8960
86
+ // See https://github.com/mdx-js/mdx/pull/2295#issuecomment-1540085960
87
+ const rehypeRawPlugin = [
88
+ rehypeRaw,
89
+ {
90
+ passThrough: [
91
+ 'mdxFlowExpression',
92
+ 'mdxJsxFlowElement',
93
+ 'mdxJsxTextElement',
94
+ 'mdxTextExpression',
95
+ 'mdxjsEsm',
96
+ ],
97
+ },
98
+ ];
99
+ rehypePlugins.unshift(rehypeRawPlugin);
100
+ }
101
+ const processorOptions = {
102
+ ...options,
103
+ remarkPlugins,
104
+ rehypePlugins,
105
+ providerImportSource: '@mdx-js/react',
106
+ };
107
+ const mdxProcessor = createMdxProcessor({
108
+ ...processorOptions,
109
+ format,
110
+ });
111
+ return {
112
+ process: async ({ content, filePath }) => mdxProcessor
113
+ .process({
114
+ value: content,
115
+ path: filePath,
116
+ })
117
+ .then((res) => res.toString()),
118
+ };
119
+ }
120
+ return { createProcessorSync };
121
+ }
122
+ // Will be useful for tests
123
+ async function createProcessorUncached(parameters) {
124
+ const { createProcessorSync } = await createProcessorFactory();
125
+ return createProcessorSync(parameters);
126
+ }
127
+ exports.createProcessorUncached = createProcessorUncached;
128
+ // Compilers are cached so that Remark/Rehype plugins can run
129
+ // expensive code during initialization
130
+ const ProcessorsCache = new Map();
131
+ async function createProcessorsCacheEntry({ query, reqOptions, }) {
132
+ const { createProcessorSync } = await createProcessorFactory();
133
+ const compilers = ProcessorsCache.get(query);
134
+ if (compilers) {
135
+ return compilers;
136
+ }
137
+ const compilerCacheEntry = {
138
+ mdProcessor: createProcessorSync({
139
+ options: reqOptions,
140
+ format: 'md',
141
+ }),
142
+ mdxProcessor: createProcessorSync({
143
+ options: reqOptions,
144
+ format: 'mdx',
145
+ }),
146
+ };
147
+ ProcessorsCache.set(query, compilerCacheEntry);
148
+ return compilerCacheEntry;
149
+ }
150
+ async function createProcessorCached({ filePath, mdxFrontMatter, query, reqOptions, }) {
151
+ const compilers = await createProcessorsCacheEntry({ query, reqOptions });
152
+ const format = (0, format_1.getFormat)({
153
+ filePath,
154
+ frontMatterFormat: mdxFrontMatter.format,
155
+ markdownConfigFormat: reqOptions.markdownConfig.format,
156
+ });
157
+ return format === 'md' ? compilers.mdProcessor : compilers.mdxProcessor;
158
+ }
159
+ exports.createProcessorCached = createProcessorCached;
160
+ //# 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,oGAAoE;AACpE,qCAAmC;AAwBnC,MAAM,eAAe,GAAe;IAClC,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,EAAE;IACjB,aAAa,EAAE,CAAC,kBAAQ,EAAE,sBAAK,EAAE,aAAG,CAAC;IACrC,0BAA0B,EAAE,EAAE;IAC9B,0BAA0B,EAAE,EAAE;CAC/B,CAAC;AAYF,SAAS,qBAAqB,CAC5B,iBAA4C;IAE5C,IAAI,iBAAiB,EAAE;QACrB,MAAM,MAAM,GACV,iBAAiB,KAAK,IAAI;YACxB,CAAC,CAAC,qBAAoB;YACtB,CAAC,CAAC,CAAC,qBAAoB,EAAE,iBAAiB,CAAC,CAAC;QAChD,OAAO,CAAC,MAAM,CAAC,CAAC;KACjB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,iDAAiD;AACjD,KAAK,UAAU,sBAAsB;IACnC,MAAM,EAAC,eAAe,EAAE,kBAAkB,EAAC,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAC1E,MAAM,EAAC,OAAO,EAAE,SAAS,EAAC,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC;IACxD,MAAM,EAAC,OAAO,EAAE,GAAG,EAAC,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC;IAClD,qFAAqF;IACrF,MAAM,EAAC,OAAO,EAAE,OAAO,EAAC,G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sBAAsB,EAAE,CAAC;IAE7D,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC7C,IAAI,SAAS,EAAE;QACb,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,kBAAkB,GAAyB;QAC/C,WAAW,EAAE,mBAAmB,CAAC;YAC/B,OAAO,EAAE,UAAU;YACnB,MAAM,EAAE,IAAI;SACb,CAAC;QACF,YAAY,EAAE,mBAAmB,CAAC;YAChC,OAAO,EAAE,UAAU;YACnB,MAAM,EAAE,KAAK;SACd,CAAC;KACH,CAAC;IAEF,eAAe,CAAC,GAAG,CAAC,KAAK,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;QACxC,oBAAoB,EAAE,UAAU,CAAC,cAAc,CAAC,MAAM;KACvD,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC;AAC1E,CAAC;AApBD,sDAoBC"}
@@ -1,15 +1,10 @@
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 { 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":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAyB,MAAM,EAAC,MAAM,SAAS,CAAC;AAK5D,oBAAY,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,iBAatC,CAAC;AAgBF,QAAA,MAAM,MAAM,EAAE,MA4Kb,CAAC;AAEF,eAAe,MAAM,CAAC"}
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 escapeRegExp(s) {
28
- return s.replace(/[-[\]{}()*+?.\\^$|/]/g, '\\$&');
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 normalizeOptions(options) {
31
- return { ...exports.DefaultAdmonitionOptions, ...options };
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 options = normalizeOptions(optionsInput);
38
- const keywords = Object.values(options.keywords).map(escapeRegExp).join('|');
39
- const nestingChar = escapeRegExp(options.tag.slice(0, 1));
40
- const tag = escapeRegExp(options.tag);
41
- // resolve th nesting level of an opening tag
42
- // ::: -> 0, :::: -> 1, ::::: -> 2 ...
43
- const nestingLevelRegex = new RegExp(`^${tag}(?<nestingLevel>${nestingChar}*)`);
44
- const regex = new RegExp(`${tag}${nestingChar}*(${keywords})(?: *(.*))?\n`);
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
- content.push(line);
102
- }
103
- // consume the processed tag and replace escape sequences
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
- hName: 'admonition',
118
- hProperties: {
119
- ...(title && isSimpleTextTitle && { title }),
120
- type: keyword,
121
- },
122
- },
123
- children: [
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
- children: titleNodes,
138
- },
139
- ...contentNodes,
140
- ].filter(Boolean),
141
- };
142
- return add(element);
143
- }
144
- // add tokenizer to parser after fenced code blocks
145
- const Parser = this.Parser.prototype;
146
- Parser.blockTokenizers.admonition = blockTokenizer;
147
- Parser.blockMethods.splice(Parser.blockMethods.indexOf('fencedCode') + 1, 0, 'admonition');
148
- Parser.interruptParagraph.splice(Parser.interruptParagraph.indexOf('fencedCode') + 1, 0, ['admonition']);
149
- Parser.interruptList.splice(Parser.interruptList.indexOf('fencedCode') + 1, 0, ['admonition']);
150
- Parser.interruptBlockquote.splice(Parser.interruptBlockquote.indexOf('fencedCode') + 1, 0, ['admonition']);
151
- return (root) => {
152
- // escape everything except admonitionHTML nodes
153
- (0, unist_util_visit_1.default)(root, (node) => node?.type !== admonitionNodeType, (node) => {
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":";AAAA;;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BAC3B,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,CAsD5C"}
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 = (0, mdast_util_to_string_1.default)(headingTextNodes.length > 0 ? headingTextNodes : headingNode);
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;AACrC,wFAAiD;AAIjD,SAAwB,MAAM;IAC5B,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,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,EAAE,EAAC,YAAY,EAAE,IAAI,EAAC,CAAC,CAAC;aAC3C;iB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AEtD,EAAE,GAAG,aAAa,CAAC,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAE7C,IAAI,aAAa,CAAC,EAAE,EAAE;oBACpB,0DAA0D;oBAC1D,sEAAsE;oBACtE,SAAS;oBACT,+BAA+B;oBAC/B,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CACnC,WAAW,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CACxB,CAAC;oBAEV,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;wBACnC,MAAM,YAAY,GAAG,IAAA,8BAAsB,EAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;wBACjE,iDAAiD;wBACjD,IAAI,YAAY,EAAE;4BAChB,QAAQ,CAAC,KAAK,GAAG,YAAY,CAAC;yBAC/B;wBACD,mEAAmE;6BAC9D;4BACH,WAAW,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;yBAC5B;qBACF;yBAAM;wBACL,QAAQ,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC;qBACrC;iBACF;aACF;YAED,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;YACb,UAAU,CAAC,EAAE,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 plugin(this: Processor): Transformer;
9
- //# sourceMappingURL=index.d.ts.map
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;AAGH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAOzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAgB5C"}
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"}