@azerion/bunosaurus-mdx-loader 0.0.0-stage → 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.
Files changed (130) hide show
  1. package/README.md +57 -2
  2. package/lib/createMDXLoader.d.ts +14 -0
  3. package/lib/createMDXLoader.d.ts.map +1 -0
  4. package/lib/createMDXLoader.js +52 -0
  5. package/lib/createMDXLoader.js.map +1 -0
  6. package/lib/format.d.ts +14 -0
  7. package/lib/format.d.ts.map +1 -0
  8. package/lib/format.js +41 -0
  9. package/lib/format.js.map +1 -0
  10. package/lib/frontMatter.d.ts +13 -0
  11. package/lib/frontMatter.d.ts.map +1 -0
  12. package/lib/frontMatter.js +23 -0
  13. package/lib/frontMatter.js.map +1 -0
  14. package/lib/index.d.ts +35 -0
  15. package/lib/index.d.ts.map +1 -0
  16. package/lib/index.js +15 -0
  17. package/lib/index.js.map +1 -0
  18. package/lib/loader.d.ts +11 -0
  19. package/lib/loader.d.ts.map +1 -0
  20. package/lib/loader.js +170 -0
  21. package/lib/loader.js.map +1 -0
  22. package/lib/options.d.ts +35 -0
  23. package/lib/options.d.ts.map +1 -0
  24. package/lib/options.js +9 -0
  25. package/lib/options.js.map +1 -0
  26. package/lib/preprocessor.d.ts +18 -0
  27. package/lib/preprocessor.d.ts.map +1 -0
  28. package/lib/preprocessor.js +34 -0
  29. package/lib/preprocessor.js.map +1 -0
  30. package/lib/processor.d.ts +49 -0
  31. package/lib/processor.d.ts.map +1 -0
  32. package/lib/processor.js +209 -0
  33. package/lib/processor.js.map +1 -0
  34. package/lib/remark/admonitions/index.d.ts +11 -0
  35. package/lib/remark/admonitions/index.d.ts.map +1 -0
  36. package/lib/remark/admonitions/index.js +107 -0
  37. package/lib/remark/admonitions/index.js.map +1 -0
  38. package/lib/remark/contentTitle/index.d.ts +13 -0
  39. package/lib/remark/contentTitle/index.d.ts.map +1 -0
  40. package/lib/remark/contentTitle/index.js +62 -0
  41. package/lib/remark/contentTitle/index.js.map +1 -0
  42. package/lib/remark/details/index.d.ts +10 -0
  43. package/lib/remark/details/index.d.ts.map +1 -0
  44. package/lib/remark/details/index.js +22 -0
  45. package/lib/remark/details/index.js.map +1 -0
  46. package/lib/remark/head/index.d.ts +10 -0
  47. package/lib/remark/head/index.d.ts.map +1 -0
  48. package/lib/remark/head/index.js +22 -0
  49. package/lib/remark/head/index.js.map +1 -0
  50. package/lib/remark/headings/index.d.ts +14 -0
  51. package/lib/remark/headings/index.d.ts.map +1 -0
  52. package/lib/remark/headings/index.js +126 -0
  53. package/lib/remark/headings/index.js.map +1 -0
  54. package/lib/remark/mdx1Compat/codeCompatPlugin.d.ts +11 -0
  55. package/lib/remark/mdx1Compat/codeCompatPlugin.d.ts.map +1 -0
  56. package/lib/remark/mdx1Compat/codeCompatPlugin.js +30 -0
  57. package/lib/remark/mdx1Compat/codeCompatPlugin.js.map +1 -0
  58. package/lib/remark/mermaid/index.d.ts +10 -0
  59. package/lib/remark/mermaid/index.d.ts.map +1 -0
  60. package/lib/remark/mermaid/index.js +34 -0
  61. package/lib/remark/mermaid/index.js.map +1 -0
  62. package/lib/remark/resolveMarkdownLinks/index.d.ts +33 -0
  63. package/lib/remark/resolveMarkdownLinks/index.d.ts.map +1 -0
  64. package/lib/remark/resolveMarkdownLinks/index.js +87 -0
  65. package/lib/remark/resolveMarkdownLinks/index.js.map +1 -0
  66. package/lib/remark/toc/index.d.ts +14 -0
  67. package/lib/remark/toc/index.d.ts.map +1 -0
  68. package/lib/remark/toc/index.js +115 -0
  69. package/lib/remark/toc/index.js.map +1 -0
  70. package/lib/remark/toc/types.d.ts +22 -0
  71. package/lib/remark/toc/types.d.ts.map +1 -0
  72. package/lib/remark/toc/types.js +9 -0
  73. package/lib/remark/toc/types.js.map +1 -0
  74. package/lib/remark/toc/utils.d.ts +26 -0
  75. package/lib/remark/toc/utils.d.ts.map +1 -0
  76. package/lib/remark/toc/utils.js +184 -0
  77. package/lib/remark/toc/utils.js.map +1 -0
  78. package/lib/remark/transformImage/index.d.ts +17 -0
  79. package/lib/remark/transformImage/index.d.ts.map +1 -0
  80. package/lib/remark/transformImage/index.js +187 -0
  81. package/lib/remark/transformImage/index.js.map +1 -0
  82. package/lib/remark/transformLinks/index.d.ts +17 -0
  83. package/lib/remark/transformLinks/index.d.ts.map +1 -0
  84. package/lib/remark/transformLinks/index.js +205 -0
  85. package/lib/remark/transformLinks/index.js.map +1 -0
  86. package/lib/remark/unusedDirectives/index.d.ts +9 -0
  87. package/lib/remark/unusedDirectives/index.d.ts.map +1 -0
  88. package/lib/remark/unusedDirectives/index.js +125 -0
  89. package/lib/remark/unusedDirectives/index.js.map +1 -0
  90. package/lib/remark/utils/index.d.ts +18 -0
  91. package/lib/remark/utils/index.d.ts.map +1 -0
  92. package/lib/remark/utils/index.js +93 -0
  93. package/lib/remark/utils/index.js.map +1 -0
  94. package/lib/serializeJS.d.ts +17 -0
  95. package/lib/serializeJS.d.ts.map +1 -0
  96. package/lib/serializeJS.js +24 -0
  97. package/lib/serializeJS.js.map +1 -0
  98. package/lib/utils.d.ts +35 -0
  99. package/lib/utils.d.ts.map +1 -0
  100. package/lib/utils.js +97 -0
  101. package/lib/utils.js.map +1 -0
  102. package/package.json +65 -4
  103. package/src/createMDXLoader.ts +65 -0
  104. package/src/format.ts +50 -0
  105. package/src/frontMatter.ts +31 -0
  106. package/src/index.ts +44 -0
  107. package/src/loader.ts +227 -0
  108. package/src/options.ts +37 -0
  109. package/src/preprocessor.ts +47 -0
  110. package/src/processor.ts +306 -0
  111. package/src/remark/admonitions/LICENSE +45 -0
  112. package/src/remark/admonitions/README.md +3 -0
  113. package/src/remark/admonitions/index.ts +138 -0
  114. package/src/remark/contentTitle/index.ts +76 -0
  115. package/src/remark/details/index.ts +23 -0
  116. package/src/remark/head/index.ts +23 -0
  117. package/src/remark/headings/index.ts +158 -0
  118. package/src/remark/mdx1Compat/codeCompatPlugin.ts +35 -0
  119. package/src/remark/mermaid/index.ts +35 -0
  120. package/src/remark/resolveMarkdownLinks/index.ts +137 -0
  121. package/src/remark/toc/index.ts +183 -0
  122. package/src/remark/toc/types.ts +29 -0
  123. package/src/remark/toc/utils.ts +243 -0
  124. package/src/remark/transformImage/index.ts +268 -0
  125. package/src/remark/transformLinks/index.ts +291 -0
  126. package/src/remark/unusedDirectives/index.ts +171 -0
  127. package/src/remark/utils/index.ts +99 -0
  128. package/src/serializeJS.ts +22 -0
  129. package/src/types.d.mts +40 -0
  130. package/src/utils.ts +134 -0
@@ -0,0 +1,49 @@
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 { WebpackCompilerName } from '@docusaurus/utils';
8
+ import type { MDXFrontMatter } from './frontMatter';
9
+ import type { Options } from './options';
10
+ import type { AdmonitionOptions } from './remark/admonitions';
11
+ import type { Pluggable } from 'unified';
12
+ export type SimpleProcessorResult = {
13
+ content: string;
14
+ data: {
15
+ [key: string]: unknown;
16
+ };
17
+ };
18
+ export type SimpleProcessor = {
19
+ process: ({ content, filePath, frontMatter, compilerName, }: {
20
+ content: string;
21
+ filePath: string;
22
+ frontMatter: {
23
+ [key: string]: unknown;
24
+ };
25
+ compilerName: WebpackCompilerName;
26
+ }) => Promise<SimpleProcessorResult>;
27
+ };
28
+ export type MDXPlugin = Pluggable;
29
+ export type MDXOptions = {
30
+ admonitions: boolean | Partial<AdmonitionOptions>;
31
+ remarkPlugins: MDXPlugin[];
32
+ rehypePlugins: MDXPlugin[];
33
+ recmaPlugins: MDXPlugin[];
34
+ beforeDefaultRemarkPlugins: MDXPlugin[];
35
+ beforeDefaultRehypePlugins: MDXPlugin[];
36
+ };
37
+ export type SimpleProcessors = {
38
+ mdProcessor: SimpleProcessor;
39
+ mdxProcessor: SimpleProcessor;
40
+ };
41
+ export declare function createProcessors({ options, }: {
42
+ options: Options;
43
+ }): SimpleProcessors;
44
+ export declare function getProcessor({ filePath, mdxFrontMatter, options, }: {
45
+ filePath: string;
46
+ mdxFrontMatter: MDXFrontMatter;
47
+ options: Options;
48
+ }): SimpleProcessor;
49
+ //# sourceMappingURL=processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyBH,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAO5D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAEvC,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,CAAC,EACR,OAAO,EACP,QAAQ,EACR,WAAW,EACX,YAAY,GACb,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;QACtC,YAAY,EAAE,mBAAmB,CAAC;KACnC,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAOlC,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClD,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,YAAY,EAAE,SAAS,EAAE,CAAC;IAC1B,0BAA0B,EAAE,SAAS,EAAE,CAAC;IACxC,0BAA0B,EAAE,SAAS,EAAE,CAAC;CACzC,CAAC;AA2KF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,eAAe,CAAC;IAC7B,YAAY,EAAE,eAAe,CAAC;CAC/B,CAAC;AAMF,wBAAgB,gBAAgB,CAAC,EAC/B,OAAO,GACR,EAAE;IACD,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,gBAAgB,CAWnB;AAgBD,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,cAAc,EACd,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,eAAe,CAWlB"}
@@ -0,0 +1,209 @@
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.createProcessors = createProcessors;
10
+ exports.getProcessor = getProcessor;
11
+ const tslib_1 = require("tslib");
12
+ const mdx_1 = require("@mdx-js/mdx");
13
+ const remark_frontmatter_1 = tslib_1.__importDefault(require("remark-frontmatter"));
14
+ const rehype_raw_1 = tslib_1.__importDefault(require("rehype-raw"));
15
+ const remark_gfm_1 = tslib_1.__importDefault(require("remark-gfm"));
16
+ // TODO using fork until PR merged: https://github.com/leebyron/remark-comment/pull/3
17
+ const remark_comment_1 = tslib_1.__importDefault(require("@slorber/remark-comment"));
18
+ const remark_directive_1 = tslib_1.__importDefault(require("remark-directive"));
19
+ const remark_mdx_1 = tslib_1.__importDefault(require("remark-mdx"));
20
+ const vfile_1 = require("vfile");
21
+ const remark_emoji_1 = tslib_1.__importDefault(require("remark-emoji"));
22
+ const headings_1 = tslib_1.__importDefault(require("./remark/headings"));
23
+ const contentTitle_1 = tslib_1.__importDefault(require("./remark/contentTitle"));
24
+ const toc_1 = tslib_1.__importDefault(require("./remark/toc"));
25
+ const transformImage_1 = tslib_1.__importDefault(require("./remark/transformImage"));
26
+ const transformLinks_1 = tslib_1.__importDefault(require("./remark/transformLinks"));
27
+ const resolveMarkdownLinks_1 = tslib_1.__importDefault(require("./remark/resolveMarkdownLinks"));
28
+ const details_1 = tslib_1.__importDefault(require("./remark/details"));
29
+ const head_1 = tslib_1.__importDefault(require("./remark/head"));
30
+ const mermaid_1 = tslib_1.__importDefault(require("./remark/mermaid"));
31
+ const admonitions_1 = tslib_1.__importDefault(require("./remark/admonitions"));
32
+ const unusedDirectives_1 = tslib_1.__importDefault(require("./remark/unusedDirectives"));
33
+ const codeCompatPlugin_1 = tslib_1.__importDefault(require("./remark/mdx1Compat/codeCompatPlugin"));
34
+ const format_1 = require("./format");
35
+ // MDX defaults to ES2024, we opt-in for ES2025 syntax (import attributes...)
36
+ const DefaultRemarkMdxOptions = {
37
+ acornOptions: { ecmaVersion: 2025, sourceType: 'module' },
38
+ };
39
+ function getAdmonitionsPlugins(admonitionsOption) {
40
+ if (admonitionsOption) {
41
+ const plugin = admonitionsOption === true
42
+ ? admonitions_1.default
43
+ : [admonitions_1.default, admonitionsOption];
44
+ return [plugin];
45
+ }
46
+ return [];
47
+ }
48
+ function getDefaultRemarkPlugins({ options }) {
49
+ return [
50
+ [
51
+ headings_1.default,
52
+ { anchorsMaintainCase: options.markdownConfig.anchors.maintainCase },
53
+ ],
54
+ ...(options.markdownConfig.emoji ? [remark_emoji_1.default] : []),
55
+ toc_1.default,
56
+ ];
57
+ }
58
+ // MDX's createProcessor() registers remark-mdx without options
59
+ // See https://github.com/mdx-js/mdx/issues/2628
60
+ // unified dedupes plugins by reference: using remark-mdx again reconfigures
61
+ // the existing attacher in place, at its original pipeline position
62
+ // This only applies to the 'mdx' format: we must not add remark-mdx for 'md'
63
+ function getRemarkMdxPlugins({ options, format, }) {
64
+ if (format === 'md') {
65
+ return [];
66
+ }
67
+ return [[remark_mdx_1.default, options.remarkMdxOptions ?? DefaultRemarkMdxOptions]];
68
+ }
69
+ // /!\ this method is synchronous on purpose
70
+ // Using async code here can create cache entry race conditions!
71
+ function createProcessorUncached({ options, format, }) {
72
+ const remarkPlugins = [
73
+ ...getRemarkMdxPlugins({ options, format }),
74
+ ...(options.beforeDefaultRemarkPlugins ?? []),
75
+ remark_frontmatter_1.default,
76
+ remark_directive_1.default,
77
+ [contentTitle_1.default, { removeContentTitle: options.removeContentTitle }],
78
+ ...getAdmonitionsPlugins(options.admonitions ?? false),
79
+ ...getDefaultRemarkPlugins({ options }),
80
+ details_1.default,
81
+ head_1.default,
82
+ ...(options.markdownConfig.mermaid ? [mermaid_1.default] : []),
83
+ [
84
+ transformImage_1.default,
85
+ {
86
+ staticDirs: options.staticDirs,
87
+ siteDir: options.siteDir,
88
+ onBrokenMarkdownImages: options.markdownConfig.hooks.onBrokenMarkdownImages,
89
+ },
90
+ ],
91
+ // TODO merge this with transformLinks?
92
+ options.resolveMarkdownLink
93
+ ? [
94
+ resolveMarkdownLinks_1.default,
95
+ {
96
+ resolveMarkdownLink: options.resolveMarkdownLink,
97
+ onBrokenMarkdownLinks: options.markdownConfig.hooks.onBrokenMarkdownLinks,
98
+ },
99
+ ]
100
+ : undefined,
101
+ [
102
+ transformLinks_1.default,
103
+ {
104
+ staticDirs: options.staticDirs,
105
+ siteDir: options.siteDir,
106
+ onBrokenMarkdownLinks: options.markdownConfig.hooks.onBrokenMarkdownLinks,
107
+ },
108
+ ],
109
+ remark_gfm_1.default,
110
+ options.markdownConfig.mdx1Compat.comments ? remark_comment_1.default : null,
111
+ ...(options.remarkPlugins ?? []),
112
+ [
113
+ unusedDirectives_1.default,
114
+ {
115
+ onUnusedMarkdownDirectives: options.markdownConfig.hooks.onUnusedMarkdownDirectives,
116
+ },
117
+ ],
118
+ ].filter((plugin) => Boolean(plugin));
119
+ // codeCompatPlugin needs to be applied last after user-provided plugins
120
+ // (after npm2yarn for example)
121
+ remarkPlugins.push(codeCompatPlugin_1.default);
122
+ const rehypePlugins = [
123
+ ...(options.beforeDefaultRehypePlugins ?? []),
124
+ ...(options.rehypePlugins ?? []),
125
+ ];
126
+ // Maybe we'll want to introduce default recma plugins later?
127
+ // For example https://github.com/domdomegg/recma-mdx-displayname ?
128
+ const recmaPlugins = [...(options.recmaPlugins ?? [])];
129
+ if (format === 'md') {
130
+ // This is what permits to embed HTML elements with format 'md'
131
+ // See https://github.com/facebook/docusaurus/pull/8960
132
+ // See https://github.com/mdx-js/mdx/pull/2295#issuecomment-1540085960
133
+ const rehypeRawPlugin = [
134
+ rehype_raw_1.default,
135
+ {
136
+ passThrough: [
137
+ 'mdxFlowExpression',
138
+ 'mdxJsxFlowElement',
139
+ 'mdxJsxTextElement',
140
+ 'mdxTextExpression',
141
+ 'mdxjsEsm',
142
+ ],
143
+ },
144
+ ];
145
+ rehypePlugins.unshift(rehypeRawPlugin);
146
+ }
147
+ const processorOptions = {
148
+ ...options,
149
+ remarkPlugins,
150
+ rehypePlugins,
151
+ recmaPlugins,
152
+ providerImportSource: '@mdx-js/react',
153
+ };
154
+ const mdxProcessor = (0, mdx_1.createProcessor)({
155
+ ...processorOptions,
156
+ remarkRehypeOptions: options.markdownConfig.remarkRehypeOptions,
157
+ format,
158
+ });
159
+ return {
160
+ process: async ({ content, filePath, frontMatter, compilerName }) => {
161
+ const vfile = new vfile_1.VFile({
162
+ value: content,
163
+ path: filePath,
164
+ data: {
165
+ frontMatter,
166
+ compilerName,
167
+ },
168
+ });
169
+ return mdxProcessor.process(vfile).then((result) => ({
170
+ content: result.toString(),
171
+ data: result.data,
172
+ }));
173
+ },
174
+ };
175
+ }
176
+ // Compilers are cached so that Remark/Rehype plugins can run
177
+ // expensive code during initialization
178
+ const ProcessorsCache = new Map();
179
+ function createProcessors({ options, }) {
180
+ return {
181
+ mdProcessor: createProcessorUncached({
182
+ options,
183
+ format: 'md',
184
+ }),
185
+ mdxProcessor: createProcessorUncached({
186
+ options,
187
+ format: 'mdx',
188
+ }),
189
+ };
190
+ }
191
+ function createProcessorsCacheEntry({ options, }) {
192
+ const compilers = ProcessorsCache.get(options);
193
+ if (compilers) {
194
+ return compilers;
195
+ }
196
+ const processors = createProcessors({ options });
197
+ ProcessorsCache.set(options, processors);
198
+ return processors;
199
+ }
200
+ function getProcessor({ filePath, mdxFrontMatter, options, }) {
201
+ const processors = options.processors ?? createProcessorsCacheEntry({ options });
202
+ const format = (0, format_1.getFormat)({
203
+ filePath,
204
+ frontMatterFormat: mdxFrontMatter.format,
205
+ markdownConfigFormat: options.markdownConfig.format,
206
+ });
207
+ return format === 'md' ? processors.mdProcessor : processors.mdxProcessor;
208
+ }
209
+ //# sourceMappingURL=processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,qCAAkE;AAClE,oFAA6C;AAC7C,oEAAmC;AACnC,oEAA6B;AAC7B,qFAAqF;AACrF,qFAAoD;AACpD,gFAAyC;AACzC,oEAAmC;AACnC,iCAA4B;AAC5B,wEAAiC;AACjC,yEAAyC;AACzC,iFAAiD;AACjD,+DAA+B;AAC/B,qFAAqD;AACrD,qFAAqD;AACrD,iGAAiE;AACjE,uEAAuC;AACvC,iEAAiC;AACjC,uEAAuC;AACvC,+EAAwD;AACxD,yFAAyD;AACzD,oGAAoE;AACpE,qCAAmC;AAkCnC,6EAA6E;AAC7E,MAAM,uBAAuB,GAAqB;IAChD,YAAY,EAAE,EAAC,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAC;CACxD,CAAC;AAWF,SAAS,qBAAqB,CAC5B,iBAA4C;IAE5C,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,MAAM,GACV,iBAAiB,KAAK,IAAI;YACxB,CAAC,CAAC,qBAAoB;YACtB,CAAC,CAAC,CAAC,qBAAo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;AACvC,MAAM,eAAe,GAAG,IAAI,GAAG,EAAsC,CAAC;AAEtE,0BAAiC,EAC/B,OAAO,GAGR;IACC,OAAO;QACL,WAAW,EAAE,uBAAuB,CAAC;YACnC,OAAO;YACP,MAAM,EAAE,IAAI;SACb,CAAC;QACF,YAAY,EAAE,uBAAuB,CAAC;YACpC,OAAO;YACP,MAAM,EAAE,KAAK;SACd,CAAC;KACH,CAAC;AACJ,CAAC;AAED,SAAS,0BAA0B,CAAC,EAClC,OAAO,GAGR;IACC,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/C,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,UAAU,GAAG,gBAAgB,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC;IAC/C,eAAe,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACzC,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,sBAA6B,EAC3B,QAAQ,EACR,cAAc,EACd,OAAO,GAKR;IACC,MAAM,UAAU,GACd,OAAO,CAAC,UAAU,IAAI,0BAA0B,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC;IAE9D,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC;QACvB,QAAQ;QACR,iBAAiB,EAAE,cAAc,CAAC,MAAM;QACxC,oBAAoB,EAAE,OAAO,CAAC,cAAc,CAAC,MAAM;KACpD,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Plugin } from 'unified';
2
+ import type { Root } from 'mdast';
3
+ export type AdmonitionOptions = {
4
+ keywords: string[];
5
+ extendDefaults: boolean;
6
+ };
7
+ export declare const DefaultAdmonitionOptions: AdmonitionOptions;
8
+ export declare function normalizeAdmonitionOptions(providedOptions: Partial<AdmonitionOptions> | true): AdmonitionOptions;
9
+ declare const plugin: Plugin<Partial<AdmonitionOptions>[], Root>;
10
+ export default plugin;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAc,MAAM,EAAC,MAAM,SAAS,CAAC;AAEjD,OAAO,KAAK,EAAS,IAAI,EAAC,MAAM,OAAO,CAAC;AAExC,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;AA6BD,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,EAAE,IAAI,CAwDtD,CAAC;eAEa,MAAM"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultAdmonitionOptions = void 0;
4
+ exports.normalizeAdmonitionOptions = normalizeAdmonitionOptions;
5
+ /**
6
+ * Copyright (c) Facebook, Inc. and its affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ */
11
+ const unist_util_visit_1 = require("unist-util-visit");
12
+ exports.DefaultAdmonitionOptions = {
13
+ keywords: [
14
+ 'secondary',
15
+ 'info',
16
+ 'success',
17
+ 'danger',
18
+ 'note',
19
+ 'tip',
20
+ 'warning',
21
+ 'important',
22
+ 'caution',
23
+ ],
24
+ extendDefaults: true,
25
+ };
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
+ function parseDirective(directive) {
42
+ const hasDirectiveLabel =
43
+ // @ts-expect-error: fine
44
+ directive.children?.[0]?.data?.directiveLabel === true;
45
+ if (hasDirectiveLabel) {
46
+ const [directiveLabel, ...contentNodes] = directive.children;
47
+ return { directiveLabel: directiveLabel, contentNodes };
48
+ }
49
+ return { directiveLabel: undefined, contentNodes: directive.children };
50
+ }
51
+ function getTextOnlyTitle(directiveLabel) {
52
+ const isTextOnlyTitle = directiveLabel?.children?.length === 1 &&
53
+ directiveLabel?.children?.[0]?.type === 'text';
54
+ return isTextOnlyTitle
55
+ ? // @ts-expect-error: todo type
56
+ directiveLabel?.children?.[0].value
57
+ : undefined;
58
+ }
59
+ const plugin = function plugin(optionsInput = {}) {
60
+ const { keywords } = normalizeAdmonitionOptions(optionsInput);
61
+ return (root) => {
62
+ (0, unist_util_visit_1.visit)(root, (node) => {
63
+ if (node.type === 'containerDirective') {
64
+ const isAdmonition = keywords.includes(node.name);
65
+ if (!isAdmonition) {
66
+ return;
67
+ }
68
+ const { directiveLabel, contentNodes } = parseDirective(node);
69
+ const textOnlyTitle = node.attributes?.title ??
70
+ (directiveLabel ? getTextOnlyTitle(directiveLabel) : undefined);
71
+ // Transform the mdast directive node to a hast admonition node
72
+ // See https://github.com/syntax-tree/mdast-util-to-hast#fields-on-nodes
73
+ // TODO in MDX v2 we should transform the whole directive to
74
+ // mdxJsxFlowElement instead of using hast
75
+ node.data = {
76
+ hName: 'admonition',
77
+ hProperties: {
78
+ ...(textOnlyTitle && { title: textOnlyTitle }),
79
+ ...(node.attributes?.class && {
80
+ className: node.attributes.class.split(' '),
81
+ }),
82
+ ...(node.attributes?.id && { id: node.attributes.id }),
83
+ type: node.name,
84
+ },
85
+ };
86
+ node.children = contentNodes;
87
+ // TODO legacy MDX v1 <mdxAdmonitionTitle> workaround
88
+ // v1: not possible to inject complex JSX elements as props
89
+ // v2: now possible: use a mdxJsxFlowElement element
90
+ if (directiveLabel && !textOnlyTitle) {
91
+ const complexTitleNode = {
92
+ type: 'mdxAdmonitionTitle',
93
+ data: {
94
+ hName: 'mdxAdmonitionTitle',
95
+ hProperties: {},
96
+ },
97
+ children: directiveLabel.children,
98
+ };
99
+ // @ts-expect-error: invented node type
100
+ node.children.unshift(complexTitleNode);
101
+ }
102
+ }
103
+ });
104
+ };
105
+ };
106
+ exports.default = plugin;
107
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":";;;;AAAA;;;;;GAKG;AACH,uDAAuC;AAU1B,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,oCACE,eAAkD;IAElD,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;QAC7B,OAAO,QAAA,wBAAwB,CAAC;IAClC,CAAC;IAED,MAAM,OAAO,GAAG,EAAC,GAAG,QAAA,wBAAwB,EAAE,GAAG,eAAe,EAAC,CAAC;IAElE,wEAAwE;IACxE,qEAAqE;IACrE,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC3B,OAAO,CAAC,QAAQ,GAAG;YACjB,GAAG,QAAA,wBAAwB,CAAC,QAAQ;YACpC,GAAG,OAAO,CAAC,QAAQ;SACpB,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAKD,SAA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@@ -0,0 +1,13 @@
1
+ import type { Plugin } from 'unified';
2
+ import type { Root } from 'mdast';
3
+ interface PluginOptions {
4
+ removeContentTitle?: boolean;
5
+ }
6
+ /**
7
+ * A remark plugin to extract the h1 heading found in Markdown files
8
+ * This is exposed as "data.contentTitle" to the processed vfile
9
+ * Also gives the ability to strip that content title (used for the blog plugin)
10
+ */
11
+ declare const plugin: Plugin<PluginOptions[], Root>;
12
+ export default plugin;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAc,MAAM,EAAC,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAkB,IAAI,EAAC,MAAM,OAAO,CAAC;AAGjD,UAAU,aAAa;IACrB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAgBD;;;;GAIG;AACH,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,CAsCzC,CAAC;eAEa,MAAM"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Copyright (c) Facebook, Inc. and its affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ const mdast_util_to_string_1 = require("mdast-util-to-string");
10
+ const unist_util_visit_1 = require("unist-util-visit");
11
+ function wrapHeadingInJsxHeader(headingNode, parent, index) {
12
+ const header = {
13
+ type: 'mdxJsxFlowElement',
14
+ name: 'header',
15
+ attributes: [],
16
+ children: [headingNode],
17
+ };
18
+ parent.children[index] = header;
19
+ }
20
+ /**
21
+ * A remark plugin to extract the h1 heading found in Markdown files
22
+ * This is exposed as "data.contentTitle" to the processed vfile
23
+ * Also gives the ability to strip that content title (used for the blog plugin)
24
+ */
25
+ const plugin = function plugin(options = {}) {
26
+ // content title is
27
+ const removeContentTitle = options.removeContentTitle ?? false;
28
+ return (root, vfile) => {
29
+ (0, unist_util_visit_1.visit)(root, ['heading', 'thematicBreak'], (node, index, parent) => {
30
+ if (!parent || index === undefined) {
31
+ return undefined;
32
+ }
33
+ if (node.type === 'heading') {
34
+ // console.log('headingNode:', headingNode);
35
+ if (node.depth === 1) {
36
+ vfile.data.contentTitle = (0, mdast_util_to_string_1.toString)(node);
37
+ if (removeContentTitle) {
38
+ parent.children.splice(index, 1);
39
+ }
40
+ else {
41
+ // TODO in the future it might be better to export contentTitle as
42
+ // as JSX node to keep this logic a theme concern?
43
+ // See https://github.com/facebook/docusaurus/pull/10335#issuecomment-2250187371
44
+ wrapHeadingInJsxHeader(node, parent, index);
45
+ }
46
+ return unist_util_visit_1.EXIT; // We only handle the very first heading
47
+ }
48
+ // We only handle contentTitle if it's the very first heading found
49
+ if (node.depth >= 1) {
50
+ return unist_util_visit_1.EXIT;
51
+ }
52
+ }
53
+ // We only handle contentTitle when it's above the first thematic break
54
+ if (node.type === 'thematicBreak') {
55
+ return unist_util_visit_1.EXIT;
56
+ }
57
+ return undefined;
58
+ });
59
+ };
60
+ };
61
+ exports.default = plugin;
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,+DAA8C;AAC9C,uDAA6C;AAS7C,SAAS,sBAAsB,CAC7B,WAAoB,EACpB,MAAc,EACd,KAAa;IAEb,MAAM,MAAM,GAAsB;QAChC,IAAI,EAAE,mBAAmB;QACzB,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,CAAC,WAAW,CAAC;KACxB,CAAC;IACF,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,MAAM,GAAkC,SAAS,MAAM,CA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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
+ import type { Root } from 'mdast';
9
+ export default function plugin(): Transformer<Root>;
10
+ //# 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;AAGH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAEzC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC;AAIhC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,CAQlD"}
@@ -0,0 +1,22 @@
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.default = plugin;
10
+ const unist_util_visit_1 = 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.visit)(root, 'mdxJsxFlowElement', (node) => {
16
+ if (node.name === 'details') {
17
+ node.name = 'Details';
18
+ }
19
+ });
20
+ };
21
+ }
22
+ //# 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,uDAAuC;AAKvC,mCAAmC;AACnC,4EAA4E;AAC5E;IACE,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAA,wBAAK,EAAC,IAAI,EAAE,mBAAmB,EAAE,CAAC,IAAI,EAAE,EAAE;YACxC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC5B,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;YACxB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +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 { Transformer } from 'unified';
8
+ import type { Root } from 'mdast';
9
+ export default function plugin(): Transformer<Root>;
10
+ //# 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;AAGH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAEzC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC;AAIhC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,CAQlD"}
@@ -0,0 +1,22 @@
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.default = plugin;
10
+ const unist_util_visit_1 = 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.visit)(root, 'mdxJsxFlowElement', (node) => {
16
+ if (node.name === 'head') {
17
+ node.name = 'Head';
18
+ }
19
+ });
20
+ };
21
+ }
22
+ //# 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,uDAAuC;AAKvC,6BAA6B;AAC7B,4EAA4E;AAC5E;IACE,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAA,wBAAK,EAAC,IAAI,EAAE,mBAAmB,EAAE,CAAC,IAAI,EAAE,EAAE;YACxC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBACzB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;YACrB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
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
+ import type { Root } from 'mdast';
9
+ export interface PluginOptions {
10
+ anchorsMaintainCase: boolean;
11
+ }
12
+ declare const plugin: Plugin<PluginOptions[], Root>;
13
+ export default plugin;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAC,MAAM,EAAc,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAU,IAAI,EAAO,MAAM,OAAO,CAAC;AAE/C,MAAM,WAAW,aAAa;IAC5B,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AA6FD,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,CA6CzC,CAAC;eAEa,MAAM"}