@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 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/unusedDirectives/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC;AAEhC,OAAO,KAAK,EAAyB,MAAM,EAAC,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAoD3B,MAAM,MAAM,aAAa,GAAG;IAC1B,0BAA0B,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,4BAA4B,CAAC,CAAC;CACnF,CAAC;AA4DF,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,CAmCzC,CAAC;eAEa,MAAM"}
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ /**
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
11
+ const node_process_1 = tslib_1.__importDefault(require("node:process"));
12
+ const unist_util_visit_1 = require("unist-util-visit");
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const utils_1 = require("@docusaurus/utils");
15
+ const utils_2 = require("../utils");
16
+ const directiveTypes = [
17
+ 'containerDirective',
18
+ 'leafDirective',
19
+ 'textDirective',
20
+ ];
21
+ const directivePrefixMap = {
22
+ textDirective: ':',
23
+ leafDirective: '::',
24
+ containerDirective: ':::',
25
+ };
26
+ function formatDirectiveName(directive) {
27
+ const prefix = directivePrefixMap[directive.type];
28
+ if (!prefix) {
29
+ throw new Error(`unexpected, no prefix found for directive of type ${directive.type}`);
30
+ }
31
+ // To simplify we don't display the eventual label/props of directives
32
+ return `${prefix}${directive.name}`;
33
+ }
34
+ function formatUnusedDirectiveMessage(directive) {
35
+ const name = formatDirectiveName(directive);
36
+ return `- ${name}${(0, utils_2.formatNodePositionExtraMessage)(directive)}`;
37
+ }
38
+ function formatUnusedDirectivesMessage({ directives, filePath, }) {
39
+ const supportUrl = 'https://github.com/facebook/docusaurus/pull/9394';
40
+ const customPath = (0, utils_1.posixPath)(node_path_1.default.relative(node_process_1.default.cwd(), filePath));
41
+ const warningTitle = logger_1.default.interpolate `Docusaurus found ${directives.length} unused Markdown directives in file path=${customPath}`;
42
+ const customSupportUrl = logger_1.default.interpolate `url=${supportUrl}`;
43
+ const warningMessages = directives
44
+ .map(formatUnusedDirectiveMessage)
45
+ .join('\n');
46
+ return `${warningTitle}
47
+ ${warningMessages}
48
+ Your content might render in an unexpected way. Visit ${customSupportUrl} to find out why and how to fix it.`;
49
+ }
50
+ function asFunction(onUnusedMarkdownDirectives) {
51
+ if (typeof onUnusedMarkdownDirectives === 'string') {
52
+ const extraHelp = onUnusedMarkdownDirectives === 'throw'
53
+ ? logger_1.default.interpolate `\nTo ignore this error, use the code=${'siteConfig.markdown.hooks.onUnusedMarkdownDirectives'} option.`
54
+ : '';
55
+ return ({ sourceFilePath, directives }) => {
56
+ const relativePath = (0, utils_1.toMessageRelativeFilePath)(sourceFilePath);
57
+ logger_1.default.report(onUnusedMarkdownDirectives) `${formatUnusedDirectivesMessage({
58
+ directives,
59
+ filePath: relativePath,
60
+ })}${extraHelp}`;
61
+ };
62
+ }
63
+ else {
64
+ return (params) => onUnusedMarkdownDirectives({
65
+ ...params,
66
+ sourceFilePath: (0, utils_1.toMessageRelativeFilePath)(params.sourceFilePath),
67
+ });
68
+ }
69
+ }
70
+ function isTextDirective(directive) {
71
+ return directive.type === 'textDirective';
72
+ }
73
+ // A simple text directive is one without any label/props
74
+ function isSimpleTextDirective(directive) {
75
+ if (isTextDirective(directive)) {
76
+ // Attributes in MDAST = Directive props
77
+ const hasAttributes = directive.attributes && Object.keys(directive.attributes).length > 0;
78
+ // Children in MDAST = Directive label
79
+ const hasChildren = directive.children.length > 0;
80
+ return !hasAttributes && !hasChildren;
81
+ }
82
+ return false;
83
+ }
84
+ function transformSimpleTextDirectiveToString(textDirective) {
85
+ (0, utils_2.transformNode)(textDirective, {
86
+ type: 'text',
87
+ value: `:${textDirective.name}`, // We ignore label/props on purpose here
88
+ });
89
+ }
90
+ function isUnusedDirective(directive) {
91
+ // If directive data is set (notably hName/hProperties set by admonitions)
92
+ // this usually means the directive has been handled by another plugin
93
+ return !directive.data;
94
+ }
95
+ const plugin = function plugin(options) {
96
+ const onUnusedMarkdownDirectives = asFunction(options.onUnusedMarkdownDirectives);
97
+ return (tree, file) => {
98
+ const unusedDirectives = [];
99
+ // @ts-expect-error: TODO fix type
100
+ (0, unist_util_visit_1.visit)(tree, directiveTypes, (directive) => {
101
+ // If directive data is set (hName/hProperties set by admonitions)
102
+ // this usually means the directive has been handled by another plugin
103
+ if (isUnusedDirective(directive)) {
104
+ if (isSimpleTextDirective(directive)) {
105
+ transformSimpleTextDirectiveToString(directive);
106
+ }
107
+ else {
108
+ unusedDirectives.push(directive);
109
+ }
110
+ }
111
+ });
112
+ // We only process unused directives for the client compiler
113
+ // This avoids emitting duplicate errors/warnings in prod mode
114
+ // Note: the client compiler is used in both dev/prod modes
115
+ // Also: the client compiler is what gets used when using crossCompilerCache
116
+ if (file.data.compilerName === 'client' && unusedDirectives.length > 0) {
117
+ onUnusedMarkdownDirectives({
118
+ sourceFilePath: file.path,
119
+ directives: unusedDirectives,
120
+ });
121
+ }
122
+ };
123
+ };
124
+ exports.default = plugin;
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/unusedDirectives/index.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,kEAA6B;AAC7B,wEAAmC;AACnC,uDAAuC;AACvC,wEAAwC;AACxC,6CAAuE;AACvE,oCAAuE;AAYvE,MAAM,cAAc,GAAoB;IACtC,oBAAoB;IACpB,eAAe;IACf,eAAe;CAChB,CAAC;AAEF,MAAM,kBAAkB,GAAqC;IAC3D,aAAa,EAAE,GAAG;IAClB,aAAa,EAAE,IAAI;IACnB,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AAEF,SAAS,mBAAmB,CAAC,SAAqB;IAChD,MAAM,MAAM,GAAG,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,qDAAqD,SAAS,CAAC,IAAI,EAAE,CACtE,CAAC;IACJ,CAAC;IACD,sEAAsE;IACtE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;AACtC,CAAC;AAED,SAAS,4BAA4B,CAAC,SAAqB;IACzD,MAAM,IAAI,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC5C,OAAO,KAAK,IAAI,GAAG,IAAA,sCAA8B,EAAC,SAAS,CAAC,EAAE,CAAC;AACjE,CAAC;AAED,SAAS,6BAA6B,CAAC,EACrC,UAAU,EACV,QAAQ,GAIT;IACC,MAAM,UAAU,GAAG,kDAAkD,CAAC;IACtE,MAAM,UAAU,GAAG,IAAA,iBAAS,EAAC,mBAAI,CAAC,QAAQ,CAAC,sBAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;IACrE,MAAM,YAAY,GAAG,gBAAM,CAAC,WAAW,CAAA,oBAAoB,UAAU,CAAC,MA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EAA4E;QAC5E,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,KAAK,QAAQ,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvE,0BAA0B,CAAC;gBACzB,cAAc,EAAE,IAAI,CAAC,IAAK;gBAC1B,UAAU,EAAE,gBAAgB;aAC7B,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;kBAEa,MAAM"}
@@ -0,0 +1,18 @@
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 { Node } from 'unist';
8
+ import type { MdxJsxAttributeValueExpression } from 'mdast-util-mdx';
9
+ /**
10
+ * Util to transform one node type to another node type
11
+ * The input node is mutated in place
12
+ * @param node the node to mutate
13
+ * @param newNode what the original node should become become
14
+ */
15
+ export declare function transformNode<NewNode extends Node>(node: Node, newNode: NewNode): NewNode;
16
+ export declare function assetRequireAttributeValue(requireString: string, hash: string): MdxJsxAttributeValueExpression;
17
+ export declare function formatNodePositionExtraMessage(node: Node): string;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAC,8BAA8B,EAAC,MAAM,gBAAgB,CAAC;AAEnE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,IAAI,EAChD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,GACf,OAAO,CAUT;AAED,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,GACX,8BAA8B,CAkDhC;AAUD,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAGjE"}
@@ -0,0 +1,93 @@
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.transformNode = transformNode;
10
+ exports.assetRequireAttributeValue = assetRequireAttributeValue;
11
+ exports.formatNodePositionExtraMessage = formatNodePositionExtraMessage;
12
+ const tslib_1 = require("tslib");
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ /**
15
+ * Util to transform one node type to another node type
16
+ * The input node is mutated in place
17
+ * @param node the node to mutate
18
+ * @param newNode what the original node should become become
19
+ */
20
+ function transformNode(node, newNode) {
21
+ Object.keys(node).forEach((key) => {
22
+ // @ts-expect-error: unsafe but ok
23
+ delete node[key];
24
+ });
25
+ Object.keys(newNode).forEach((key) => {
26
+ // @ts-expect-error: unsafe but ok
27
+ node[key] = newNode[key];
28
+ });
29
+ return node;
30
+ }
31
+ function assetRequireAttributeValue(requireString, hash) {
32
+ return {
33
+ type: 'mdxJsxAttributeValueExpression',
34
+ value: `require("${requireString}").default${hash && ` + '${hash}'`}`,
35
+ data: {
36
+ estree: {
37
+ type: 'Program',
38
+ body: [
39
+ {
40
+ type: 'ExpressionStatement',
41
+ expression: {
42
+ type: 'BinaryExpression',
43
+ left: {
44
+ type: 'MemberExpression',
45
+ object: {
46
+ type: 'CallExpression',
47
+ callee: {
48
+ type: 'Identifier',
49
+ name: 'require',
50
+ },
51
+ arguments: [
52
+ {
53
+ type: 'Literal',
54
+ value: requireString,
55
+ raw: `"${requireString}"`,
56
+ },
57
+ ],
58
+ optional: false,
59
+ },
60
+ property: {
61
+ type: 'Identifier',
62
+ name: 'default',
63
+ },
64
+ computed: false,
65
+ optional: false,
66
+ },
67
+ operator: '+',
68
+ right: {
69
+ type: 'Literal',
70
+ value: hash,
71
+ raw: `"${hash}"`,
72
+ },
73
+ },
74
+ },
75
+ ],
76
+ sourceType: 'module',
77
+ comments: [],
78
+ },
79
+ },
80
+ };
81
+ }
82
+ function formatNodePosition(node) {
83
+ return node.position?.start
84
+ ? logger_1.default.interpolate `number=${node.position.start.line}:number=${node.position.start.column}`
85
+ : undefined;
86
+ }
87
+ // Returns " (line:column)" when position info is available
88
+ // The initial space is useful to append easily to any existing message
89
+ function formatNodePositionExtraMessage(node) {
90
+ const position = formatNodePosition(node);
91
+ return `${position ? ` (${position})` : ''}`;
92
+ }
93
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,wEAAwC;AAIxC;;;;;GAKG;AACH,uBACE,IAAU,EACV,OAAgB;IAEhB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAChC,kCAAkC;QAClC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACnC,kCAAkC;QAClC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO,IAAe,CAAC;AACzB,CAAC;AAED,oCACE,aAAqB,EACrB,IAAY;IAEZ,OAAO;QACL,IAAI,EAAE,gCAAgC;QACtC,KAAK,EAAE,YAAY,aAAa,aAAa,IAAI,IAAI,OAAO,IAAI,GAAG,EAAE;QACrE,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE;oBACJ;wBACE,IAAI,EAAE,qBAAqB;wBAC3B,UAAU,EAAE;4BACV,IAAI,EAAE,kBAAkB;4BACxB,IAAI,EAA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+ *
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
+ /**
8
+ * Serializes a value to a JS expression string, that can be inlined in the
9
+ * code of a generated JS module, such as the front matter of an MDX file:
10
+ *
11
+ * `export const frontMatter = ${serializeJS(frontMatter)};`
12
+ *
13
+ * Contrary to JSON, the output preserves values such as `undefined`, `NaN`,
14
+ * `Infinity` or `Date` instances.
15
+ */
16
+ export declare function serializeJS(value: unknown): string;
17
+ //# sourceMappingURL=serializeJS.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializeJS.d.ts","sourceRoot":"","sources":["../src/serializeJS.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAElD"}
@@ -0,0 +1,24 @@
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.serializeJS = serializeJS;
10
+ const astring_1 = require("astring");
11
+ const estree_util_value_to_estree_1 = require("estree-util-value-to-estree");
12
+ /**
13
+ * Serializes a value to a JS expression string, that can be inlined in the
14
+ * code of a generated JS module, such as the front matter of an MDX file:
15
+ *
16
+ * `export const frontMatter = ${serializeJS(frontMatter)};`
17
+ *
18
+ * Contrary to JSON, the output preserves values such as `undefined`, `NaN`,
19
+ * `Infinity` or `Date` instances.
20
+ */
21
+ function serializeJS(value) {
22
+ return (0, astring_1.generate)((0, estree_util_value_to_estree_1.valueToEstree)(value, { instanceAsObject: true }));
23
+ }
24
+ //# sourceMappingURL=serializeJS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializeJS.js","sourceRoot":"","sources":["../src/serializeJS.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAAiC;AACjC,6EAA0D;AAE1D;;;;;;;;GAQG;AACH,qBAA4B,KAAc;IACxC,OAAO,IAAA,kBAAQ,EAAC,IAAA,2CAAa,EAAC,KAAK,EAAE,EAAC,gBAAgB,EAAE,IAAI,EAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,35 @@
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 SimpleProcessorResult } from './processor';
9
+ import type { Options } from './options';
10
+ /**
11
+ * Converts assets an object with Webpack require calls code.
12
+ * This is useful for mdx files to reference co-located assets using relative
13
+ * paths. Those assets should enter the Webpack assets pipeline and be hashed.
14
+ * For now, we only handle that for images and paths starting with `./`:
15
+ *
16
+ * `{image: "./myImage.png"}` => `{image: require("./myImage.png")}`
17
+ */
18
+ export declare function createAssetsExportCode({ assets, inlineMarkdownAssetImageFileLoader, }: {
19
+ assets: unknown;
20
+ inlineMarkdownAssetImageFileLoader: string;
21
+ }): string;
22
+ /**
23
+ * data.contentTitle is set by the remark contentTitle plugin
24
+ */
25
+ export declare function extractContentTitleData(data: {
26
+ [key: string]: unknown;
27
+ }): string | undefined;
28
+ export declare function compileToJSX({ filePath, fileContent, frontMatter, options, compilerName, }: {
29
+ filePath: string;
30
+ fileContent: string;
31
+ frontMatter: Record<string, unknown>;
32
+ options: Options;
33
+ compilerName: WebpackCompilerName;
34
+ }): Promise<SimpleProcessorResult>;
35
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAa,KAAK,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAe,KAAK,qBAAqB,EAAC,MAAM,aAAa,CAAC;AAGrE,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAEvC;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,MAAM,EACN,kCAAkC,GACnC,EAAE;IACD,MAAM,EAAE,OAAO,CAAC;IAChB,kCAAkC,EAAE,MAAM,CAAC;CAC5C,GAAG,MAAM,CAuCT;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,GAAG,MAAM,GAAG,SAAS,CAErB;AAED,wBAAsB,YAAY,CAAC,EACjC,QAAQ,EACR,WAAW,EACX,WAAW,EACX,OAAO,EACP,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,mBAAmB,CAAC;CACnC,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA2CjC"}
package/lib/utils.js ADDED
@@ -0,0 +1,97 @@
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.createAssetsExportCode = createAssetsExportCode;
10
+ exports.extractContentTitleData = extractContentTitleData;
11
+ exports.compileToJSX = compileToJSX;
12
+ const tslib_1 = require("tslib");
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const utils_1 = require("@docusaurus/utils");
15
+ const processor_1 = require("./processor");
16
+ const frontMatter_1 = require("./frontMatter");
17
+ const preprocessor_1 = tslib_1.__importDefault(require("./preprocessor"));
18
+ /**
19
+ * Converts assets an object with Webpack require calls code.
20
+ * This is useful for mdx files to reference co-located assets using relative
21
+ * paths. Those assets should enter the Webpack assets pipeline and be hashed.
22
+ * For now, we only handle that for images and paths starting with `./`:
23
+ *
24
+ * `{image: "./myImage.png"}` => `{image: require("./myImage.png")}`
25
+ */
26
+ function createAssetsExportCode({ assets, inlineMarkdownAssetImageFileLoader, }) {
27
+ if (typeof assets !== 'object' ||
28
+ !assets ||
29
+ Object.keys(assets).length === 0) {
30
+ return 'undefined';
31
+ }
32
+ // TODO implementation can be completed/enhanced
33
+ function createAssetValueCode(assetValue) {
34
+ if (Array.isArray(assetValue)) {
35
+ const arrayItemCodes = assetValue.map((item) => createAssetValueCode(item) ?? 'undefined');
36
+ return `[${arrayItemCodes.join(', ')}]`;
37
+ }
38
+ // Only process string values starting with ./
39
+ // We could enhance this logic and check if file exists on disc?
40
+ if (typeof assetValue === 'string' && assetValue.startsWith('./')) {
41
+ // TODO do we have other use-cases than image assets?
42
+ // Probably not worth adding more support, as we want to move to Webpack 5 new asset system (https://github.com/facebook/docusaurus/pull/4708)
43
+ return `require("${inlineMarkdownAssetImageFileLoader}${(0, utils_1.escapePath)(assetValue)}").default`;
44
+ }
45
+ return undefined;
46
+ }
47
+ const assetEntries = Object.entries(assets);
48
+ const codeLines = assetEntries
49
+ .map(([key, value]) => {
50
+ const assetRequireCode = createAssetValueCode(value);
51
+ return assetRequireCode ? `"${key}": ${assetRequireCode},` : undefined;
52
+ })
53
+ .filter(Boolean);
54
+ return `{\n${codeLines.join('\n')}\n}`;
55
+ }
56
+ /**
57
+ * data.contentTitle is set by the remark contentTitle plugin
58
+ */
59
+ function extractContentTitleData(data) {
60
+ return data.contentTitle;
61
+ }
62
+ async function compileToJSX({ filePath, fileContent, frontMatter, options, compilerName, }) {
63
+ const preprocessedFileContent = (0, preprocessor_1.default)({
64
+ fileContent,
65
+ filePath,
66
+ admonitions: options.admonitions,
67
+ markdownConfig: options.markdownConfig,
68
+ });
69
+ const mdxFrontMatter = (0, frontMatter_1.validateMDXFrontMatter)(frontMatter.mdx);
70
+ const processor = (0, processor_1.getProcessor)({
71
+ filePath,
72
+ options,
73
+ mdxFrontMatter,
74
+ });
75
+ try {
76
+ return await processor.process({
77
+ content: preprocessedFileContent,
78
+ filePath,
79
+ frontMatter,
80
+ compilerName,
81
+ });
82
+ }
83
+ catch (errorUnknown) {
84
+ const error = errorUnknown;
85
+ // MDX can emit errors that have useful extra attributes
86
+ const errorJSON = JSON.stringify(error, null, 2);
87
+ const errorDetails = errorJSON === '{}'
88
+ ? // regular JS error case: print stacktrace
89
+ (error.stack ?? 'N/A')
90
+ : // MDX error: print extra attributes + stacktrace
91
+ `${errorJSON}\n${error.stack}`;
92
+ throw new Error(`MDX compilation failed for file ${logger_1.default.path(filePath)}\nCause: ${error.message}\nDetails:\n${errorDetails}`,
93
+ // TODO error cause doesn't seem to be used by Webpack stats.errors :s
94
+ { cause: errorUnknown });
95
+ }
96
+ }
97
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,wEAAwC;AACxC,6CAAuE;AACvE,2CAAqE;AACrE,+CAAqD;AACrD,0EAA0C;AAG1C;;;;;;;GAOG;AACH,gCAAuC,EACrC,MAAM,EACN,kCAAkC,GAInC;IACC,IACE,OAAO,MAAM,KAAK,QAAQ;QAC1B,CAAC,MAAM;QACP,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAChC,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,gDAAgD;IAChD,SAAS,oBAAoB,CAAC,UAAmB;QAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CACnC,CAAC,IAAa,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,WAAW,CAC7D,CAAC;YACF,O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AAY,EAAC;QAC7B,QAAQ;QACR,OAAO;QACP,cAAc;KACf,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,OAAO,MAAM,SAAS,CAAC,OAAO,CAAC;YAC7B,OAAO,EAAE,uBAAuB;YAChC,QAAQ;YACR,WAAW;YACX,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,YAAY,EAAE,CAAC;QACtB,MAAM,KAAK,GAAG,YAAqB,CAAC;QAEpC,wDAAwD;QACxD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACjD,MAAM,YAAY,GAChB,SAAS,KAAK,IAAI;YAChB,CAAC,CAAC,0CAA0C;gBAC1C,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC;YACxB,CAAC,CAAC,iDAAiD;gBACjD,GAAG,SAAS,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;QAErC,MAAM,IAAI,KAAK,CACb,mCAAmC,gBAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,YACtD,KAAK,CAAC,OACR,eAAe,YAAY,EAAE;QAC7B,sEAAsE;QACtE,EAAC,KAAK,EAAE,YAAY,EAAC,CACtB,CAAC;IACJ,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@azerion/bunosaurus-mdx-loader",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.0.0",
4
+ "description": "Docusaurus Loader for MDX",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "watch": "tsc --watch"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/azerion/bunosaurus.git",
17
+ "directory": "packages/docusaurus-mdx-loader"
18
+ },
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@docusaurus/fs": "npm:@azerion/bunosaurus-fs@4.0.0",
22
+ "@docusaurus/logger": "npm:@azerion/bunosaurus-logger@4.0.0",
23
+ "@docusaurus/utils": "npm:@azerion/bunosaurus-utils@4.0.0",
24
+ "@docusaurus/utils-validation": "npm:@azerion/bunosaurus-utils-validation@4.0.0",
25
+ "@mdx-js/mdx": "^3.1.1",
26
+ "@slorber/remark-comment": "^1.0.0",
27
+ "astring": "^1.9.0",
28
+ "escape-html": "^1.0.3",
29
+ "estree-util-value-to-estree": "^3.5.0",
30
+ "image-size": "^2.0.4",
31
+ "mdast-util-mdx": "^3.0.0",
32
+ "mdast-util-to-string": "^4.0.0",
33
+ "rehype-raw": "^7.0.0",
34
+ "remark-directive": "^4.0.0",
35
+ "remark-emoji": "^5.0.2",
36
+ "remark-frontmatter": "^5.0.0",
37
+ "remark-gfm": "^4.0.1",
38
+ "remark-mdx": "^3.1.1",
39
+ "tslib": "^2.8.1",
40
+ "unified": "^11.0.5",
41
+ "unist-util-visit": "^5.1.0",
42
+ "vfile": "^6.0.3"
43
+ },
44
+ "devDependencies": {
45
+ "@docusaurus/types": "npm:@azerion/bunosaurus-types@4.0.0",
46
+ "@types/escape-html": "^1.0.4",
47
+ "@types/estree": "^1.0.9",
48
+ "@types/mdast": "^4.0.4",
49
+ "@types/unist": "^3.0.3",
50
+ "lodash": "^4.18.1",
51
+ "mdast-util-directive": "3.1.0",
52
+ "rehype-stringify": "^10.0.1",
53
+ "remark": "^15.0.1",
54
+ "remark-rehype": "^11.1.2",
55
+ "to-vfile": "^8.0.0",
56
+ "unist-builder": "^4.0.0",
57
+ "utility-types": "^3.11.0",
58
+ "webpack": "^5.111.0"
59
+ },
60
+ "peerDependencies": {
61
+ "react": "^19.3.0",
62
+ "react-dom": "^19.3.0"
63
+ },
64
+ "engines": {
65
+ "bun": ">=1.4.1"
66
+ }
67
+ }
@@ -0,0 +1,65 @@
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
+
8
+ import {createProcessors} from './processor';
9
+ import type {Options} from './options';
10
+ import type {RuleSetRule, RuleSetUseItem} from 'webpack';
11
+
12
+ // Escape hatch to disable the MDX cross-compiler cache, just in case
13
+ // TODO Docusaurus v5: remove this escape hatch env variable
14
+ const DisableCrossCompilerCache =
15
+ process.env.DOCUSAURUS_NO_MDX_CROSS_COMPILER_CACHE === 'true';
16
+
17
+ function normalizeOptions(optionsInput: Options): Options {
18
+ // Skip eager processor creation in tests
19
+ if (process.env.NODE_ENV === 'test' || process.env.VITEST) {
20
+ return optionsInput;
21
+ }
22
+
23
+ let options = optionsInput;
24
+
25
+ // We create the processor earlier here, to avoid the lazy processor creating
26
+ // Lazy creation messes-up with Rsdoctor ability to measure mdx-loader perf
27
+ if (!options.processors) {
28
+ options = {...options, processors: createProcessors({options})};
29
+ }
30
+
31
+ // Cross-compiler cache permits to compile client/server MDX only once
32
+ // We don't want to cache in dev mode (docusaurus start)
33
+ // We only have multiple compilers in production mode (docusaurus build)
34
+ // TODO wrong but good enough for now (example: "docusaurus build --dev")
35
+ if (!DisableCrossCompilerCache && process.env.NODE_ENV === 'production') {
36
+ options = {
37
+ ...options,
38
+ crossCompilerCache: new Map(),
39
+ };
40
+ }
41
+
42
+ return options;
43
+ }
44
+
45
+ export function createMDXLoaderItem(options: Options): RuleSetUseItem {
46
+ return {
47
+ loader: require.resolve('./index'),
48
+ options: normalizeOptions(options),
49
+ };
50
+ }
51
+
52
+ export function createMDXLoaderRule({
53
+ include,
54
+ options,
55
+ }: {
56
+ include: RuleSetRule['include'];
57
+ options: Options;
58
+ }): RuleSetRule {
59
+ return {
60
+ test: /\.mdx?$/i,
61
+ include,
62
+ with: {type: {not: 'text'}},
63
+ use: [createMDXLoaderItem(options)],
64
+ };
65
+ }
package/src/format.ts ADDED
@@ -0,0 +1,50 @@
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
+
8
+ import path from 'node:path';
9
+ import type {MDXFrontMatter} from './frontMatter';
10
+ import type {Format, FormatInput} from './index';
11
+
12
+ // Copied from https://mdxjs.com/packages/mdx/#optionsmdextensions
13
+ // Although we are likely to only use .md / .mdx anyway...
14
+ const mdFormatExtensions = [
15
+ '.md',
16
+ '.markdown',
17
+ '.mdown',
18
+ '.mkdn',
19
+ '.mkd',
20
+ '.mdwn',
21
+ '.mkdown',
22
+ '.ron',
23
+ ];
24
+
25
+ function getExtensionFormat(filepath: string): Format {
26
+ const isMDFormat = mdFormatExtensions.includes(path.extname(filepath));
27
+ // Bias toward mdx if unknown extension
28
+ return isMDFormat ? 'md' : 'mdx';
29
+ }
30
+
31
+ export function getFormat({
32
+ filePath,
33
+ frontMatterFormat,
34
+ markdownConfigFormat,
35
+ }: {
36
+ filePath: string;
37
+ frontMatterFormat: MDXFrontMatter['format'];
38
+ markdownConfigFormat: FormatInput;
39
+ }): Format {
40
+ if (frontMatterFormat) {
41
+ if (frontMatterFormat !== 'detect') {
42
+ return frontMatterFormat;
43
+ }
44
+ return getExtensionFormat(filePath);
45
+ }
46
+ if (markdownConfigFormat !== 'detect') {
47
+ return markdownConfigFormat;
48
+ }
49
+ return getExtensionFormat(filePath);
50
+ }