@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,126 @@
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
+ /* 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) */
10
+ const mdast_util_to_string_1 = require("mdast-util-to-string");
11
+ const unist_util_visit_1 = require("unist-util-visit");
12
+ const utils_1 = require("@docusaurus/utils");
13
+ function getCommentContentHeadingId(comment) {
14
+ // If the comment has spaces, we only consider the first part
15
+ const firstPart = comment.trim().split(' ')[0];
16
+ // We ignore comments that don't start with # on purpose
17
+ // Forcing users to use a leading # is more explicit
18
+ // In the future it's possible we'd want to allow other types of comments
19
+ // For example class comments like {/* .my-class */}
20
+ if (firstPart?.startsWith('#')) {
21
+ return firstPart.slice(1) || undefined;
22
+ }
23
+ return undefined;
24
+ }
25
+ function getCommentHeadingId(heading) {
26
+ const lastChild = heading.children.at(-1);
27
+ // MDX comment: {/* my-id */} or {/* #my-id */}
28
+ if (lastChild &&
29
+ lastChild.type === 'mdxTextExpression' &&
30
+ lastChild.data?.estree) {
31
+ const program = lastChild.data.estree;
32
+ // We only extract the id from single-comment MDX expressions
33
+ // ✅ {/* #my-id */}
34
+ // ❌ {/* #my-id */ /* #my-id2 */}
35
+ // ❌ {someExpression /* #my-id */}
36
+ if (program.body.length === 0 && program.comments?.length === 1) {
37
+ const commentContent = program.comments[0].value;
38
+ return getCommentContentHeadingId(commentContent);
39
+ }
40
+ }
41
+ // HTML comment: <!-- my-id --> or <!-- #my-id -->
42
+ if (lastChild?.type === 'html') {
43
+ const match = /^<!--(?<comment>[\s\S]*)-->$/.exec(lastChild.value);
44
+ if (match?.groups?.comment) {
45
+ const commentContent = match.groups.comment;
46
+ return getCommentContentHeadingId(commentContent);
47
+ }
48
+ }
49
+ return undefined;
50
+ }
51
+ // Try to find an explicit id in MD/MDX comments
52
+ function extractCommentId(heading) {
53
+ const commentId = getCommentHeadingId(heading);
54
+ if (commentId) {
55
+ // Remove the last comment node
56
+ heading.children.pop();
57
+ // Trim the trailing space from the last text node ("text " → "text")
58
+ const newLast = heading.children.at(-1);
59
+ if (newLast?.type === 'text') {
60
+ newLast.value = newLast.value.trimEnd();
61
+ }
62
+ return commentId;
63
+ }
64
+ return undefined;
65
+ }
66
+ // Try to find an explicit id in the heading text (classic {#id} syntax)
67
+ function extractClassicSyntaxHeadingId(heading, headingText) {
68
+ const parsedHeading = (0, utils_1.parseMarkdownHeadingId)(headingText, 'classic');
69
+ // Remove the heading text from its id (legacy syntax)
70
+ if (parsedHeading.id) {
71
+ // When there's an id, it is always in the last child node
72
+ const lastNode = heading.children.at(-1);
73
+ if (heading.children.length > 1) {
74
+ const lastNodeText = (0, utils_1.parseMarkdownHeadingId)(lastNode.value, 'classic').text;
75
+ // When the last part contains text + id, remove the id
76
+ if (lastNodeText) {
77
+ lastNode.value = lastNodeText;
78
+ }
79
+ // When last part contains only the id: completely remove that node
80
+ else {
81
+ heading.children.pop();
82
+ }
83
+ }
84
+ else {
85
+ lastNode.value = parsedHeading.text;
86
+ }
87
+ return parsedHeading.id;
88
+ }
89
+ return undefined;
90
+ }
91
+ const plugin = function plugin({ anchorsMaintainCase, }) {
92
+ return (root) => {
93
+ function getHeadingText(heading) {
94
+ const headingTextNodes = heading.children.filter(({ type }) => !['html', 'jsx'].includes(type));
95
+ return (0, mdast_util_to_string_1.toString)(headingTextNodes.length > 0 ? headingTextNodes : heading);
96
+ }
97
+ const slugs = (0, utils_1.createSlugger)();
98
+ (0, unist_util_visit_1.visit)(root, 'heading', (heading) => {
99
+ const data = heading.data ?? (heading.data = {});
100
+ const properties = data.hProperties ?? (data.hProperties = {});
101
+ // Gives the ability to provide/write a remark plugin that sets an id
102
+ // When an id is already set, we use it instead of running our own plugin
103
+ function extractAlreadyExistingId() {
104
+ if (properties.id) {
105
+ // Not sure why we need to slugify here, historical code
106
+ return slugs.slug(properties.id, { maintainCase: true });
107
+ }
108
+ return undefined;
109
+ }
110
+ function extractIdFromText() {
111
+ const headingText = getHeadingText(heading);
112
+ return (extractClassicSyntaxHeadingId(heading, headingText) ??
113
+ slugs.slug(headingText, { maintainCase: anchorsMaintainCase }));
114
+ }
115
+ // All the ways we can extract an id, ordered by priority
116
+ // /!\ the extraction methods can perform AST cleanup side effects
117
+ const id = extractAlreadyExistingId() ??
118
+ extractCommentId(heading) ??
119
+ extractIdFromText();
120
+ data.id = id;
121
+ properties.id = id;
122
+ });
123
+ };
124
+ };
125
+ exports.default = plugin;
126
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,gMAAgM;AAEhM,+DAA8C;AAC9C,uDAAuC;AACvC,6CAAwE;AAQxE,SAAS,0BAA0B,CAAC,OAAe;IACjD,6DAA6D;IAC7D,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,wDAAwD;IACxD,oDAAoD;IACpD,yEAAyE;IACzE,oDAAoD;IACpD,IAAI,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,OAAO,SAAS,CA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D;YACzD,kEAAkE;YAClE,MAAM,EAAE,GACN,wBAAwB,EAAE;gBAC1B,gBAAgB,CAAC,OAAO,CAAC;gBACzB,iBAAiB,EAAE,CAAC;YAEtB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;YACb,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;kBAEa,MAAM"}
@@ -0,0 +1,11 @@
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
+ declare const plugin: Plugin<unknown[], Root>;
10
+ export default plugin;
11
+ //# 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;AAGH,OAAO,KAAK,EAAc,MAAM,EAAC,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC;AAShC,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,IAAI,CAcnC,CAAC;eAEa,MAAM"}
@@ -0,0 +1,30 @@
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 unist_util_visit_1 = require("unist-util-visit");
10
+ // Solution inspired by https://github.com/pomber/docusaurus-mdx-2/blob/main/packages/mdx-loader/src/remark/codeCompat/index.ts
11
+ // TODO after MDX 2 we probably don't need this - remove soon?
12
+ // Only fenced code blocks are swapped by pre/code MDX components
13
+ // Using <pre><code> in JSX shouldn't use our MDX components anymore
14
+ // To make theme-classic/src/theme/MDXComponents/Pre work
15
+ // we need to fill two properties that mdx v2 doesn't provide anymore
16
+ const plugin = function plugin() {
17
+ return (root) => {
18
+ (0, unist_util_visit_1.visit)(root, 'code', (node) => {
19
+ node.data = node.data || {};
20
+ node.data.hProperties = node.data.hProperties || {};
21
+ node.data.hProperties.metastring = node.meta;
22
+ // TODO Docusaurus v4: remove special case
23
+ // Retrocompatible support for live codeblock metastring
24
+ // Not really the appropriate place to handle that :s
25
+ node.data.hProperties.live = node.meta?.split(' ').includes('live');
26
+ });
27
+ };
28
+ };
29
+ exports.default = plugin;
30
+ //# 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,uDAAuC;AAIvC,+HAA+H;AAC/H,8DAA8D;AAC9D,iEAAiE;AACjE,oEAAoE;AAEpE,yDAAyD;AACzD,qEAAqE;AACrE,MAAM,MAAM,GAA4B,SAAS,MAAM;IACrD,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAA,wBAAK,EAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;YAE5B,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;YACpD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;YAE7C,0CAA0C;YAC1C,wDAAwD;YACxD,qDAAqD;YACrD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;kBAEa,MAAM"}
@@ -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/mermaid/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC;AAMhC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,CAiBlD"}
@@ -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
+ exports.default = plugin;
10
+ const unist_util_visit_1 = require("unist-util-visit");
11
+ const utils_1 = require("../utils");
12
+ // TODO: this plugin shouldn't be in the core MDX loader
13
+ // After we allow plugins to provide Remark/Rehype plugins (see
14
+ // https://github.com/facebook/docusaurus/issues/6370), this should be provided
15
+ // by theme-mermaid itself
16
+ function plugin() {
17
+ return (root) => {
18
+ (0, unist_util_visit_1.visit)(root, 'code', (node) => {
19
+ if (node.lang === 'mermaid') {
20
+ // TODO migrate to mdxJsxFlowElement? cf admonitions
21
+ (0, utils_1.transformNode)(node, {
22
+ type: 'mermaidCodeBlock',
23
+ data: {
24
+ hName: 'mermaid',
25
+ hProperties: {
26
+ value: node.value,
27
+ },
28
+ },
29
+ });
30
+ }
31
+ });
32
+ };
33
+ }
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/mermaid/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uDAAuC;AACvC,oCAAuC;AAKvC,wDAAwD;AACxD,+DAA+D;AAC/D,+EAA+E;AAC/E,0BAA0B;AAC1B;IACE,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAA,wBAAK,EAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAC3B,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC5B,oDAAoD;gBACpD,IAAA,qBAAa,EAAC,IAAI,EAAE;oBAClB,IAAI,EAAE,kBAAkB;oBACxB,IAAI,EAAE;wBACJ,KAAK,EAAE,SAAS;wBAChB,WAAW,EAAE;4BACX,KAAK,EAAE,IAAI,CAAC,KAAK;yBAClB;qBACF;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,33 @@
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
+ import type { MarkdownConfig } from '@docusaurus/types';
10
+ type ResolveMarkdownLinkParams = {
11
+ /**
12
+ * Absolute path to the source file containing this Markdown link.
13
+ */
14
+ sourceFilePath: string;
15
+ /**
16
+ * The Markdown link pathname to resolve, as found in the source file.
17
+ * If the link is "./myFile.mdx?qs#hash", this will be "./myFile.mdx"
18
+ */
19
+ linkPathname: string;
20
+ };
21
+ export type ResolveMarkdownLink = (params: ResolveMarkdownLinkParams) => string | null;
22
+ export interface PluginOptions {
23
+ resolveMarkdownLink: ResolveMarkdownLink;
24
+ onBrokenMarkdownLinks: MarkdownConfig['hooks']['onBrokenMarkdownLinks'];
25
+ }
26
+ /**
27
+ * A remark plugin to extract the h1 heading found in Markdown files
28
+ * This is exposed as "data.contentTitle" to the processed vfile
29
+ * Also gives the ability to strip that content title (used for the blog plugin)
30
+ */
31
+ declare const plugin: Plugin<PluginOptions[], Root>;
32
+ export default plugin;
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/resolveMarkdownLinks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,OAAO,KAAK,EAAC,MAAM,EAAc,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAmB,IAAI,EAAC,MAAM,OAAO,CAAC;AAClD,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAE3B,KAAK,yBAAyB,GAAG;IAC/B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,CAChC,MAAM,EAAE,yBAAyB,KAC9B,MAAM,GAAG,IAAI,CAAC;AAEnB,MAAM,WAAW,aAAa;IAC5B,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,qBAAqB,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,uBAAuB,CAAC,CAAC;CACzE;AA8CD;;;;GAIG;AAGH,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,CAsCzC,CAAC;eAEa,MAAM"}
@@ -0,0 +1,87 @@
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 = require("unist-util-visit");
11
+ const utils_1 = require("@docusaurus/utils");
12
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
+ const utils_2 = require("../utils");
14
+ function asFunction(onBrokenMarkdownLinks) {
15
+ if (typeof onBrokenMarkdownLinks === 'string') {
16
+ const extraHelp = onBrokenMarkdownLinks === 'throw'
17
+ ? logger_1.default.interpolate `\nTo ignore this error, use the code=${'siteConfig.markdown.hooks.onBrokenMarkdownLinks'} option, or apply the code=${'pathname://'} protocol to the broken link URLs.`
18
+ : '';
19
+ return ({ sourceFilePath, url: linkUrl, node }) => {
20
+ const relativePath = (0, utils_1.toMessageRelativeFilePath)(sourceFilePath);
21
+ logger_1.default.report(onBrokenMarkdownLinks) `Markdown link with URL code=${linkUrl} in source file path=${relativePath}${(0, utils_2.formatNodePositionExtraMessage)(node)} couldn't be resolved.
22
+ Make sure it references a local Markdown file that exists within the current plugin.${extraHelp}`;
23
+ };
24
+ }
25
+ else {
26
+ return (params) => onBrokenMarkdownLinks({
27
+ ...params,
28
+ sourceFilePath: (0, utils_1.toMessageRelativeFilePath)(params.sourceFilePath),
29
+ });
30
+ }
31
+ }
32
+ const HAS_MARKDOWN_EXTENSION = /\.mdx?$/i;
33
+ function parseMarkdownLinkURLPath(link) {
34
+ const urlPath = (0, utils_1.parseLocalURLPath)(link);
35
+ // If it's not local, we don't resolve it even if it's a Markdown file
36
+ // Example, we don't resolve https://github.com/project/README.md
37
+ if (!urlPath) {
38
+ return null;
39
+ }
40
+ // Ignore links without a Markdown file extension (ignoring qs/hash)
41
+ if (!HAS_MARKDOWN_EXTENSION.test(urlPath.pathname)) {
42
+ return null;
43
+ }
44
+ return urlPath;
45
+ }
46
+ /**
47
+ * A remark plugin to extract the h1 heading found in Markdown files
48
+ * This is exposed as "data.contentTitle" to the processed vfile
49
+ * Also gives the ability to strip that content title (used for the blog plugin)
50
+ */
51
+ // TODO merge this plugin with "transformLinks"
52
+ // in general we'd want to avoid traversing multiple times the same AST
53
+ const plugin = function plugin(options) {
54
+ const { resolveMarkdownLink } = options;
55
+ const onBrokenMarkdownLinks = asFunction(options.onBrokenMarkdownLinks);
56
+ return (root, file) => {
57
+ (0, unist_util_visit_1.visit)(root, ['link', 'definition'], (node) => {
58
+ const link = node;
59
+ const linkURLPath = parseMarkdownLinkURLPath(link.url);
60
+ if (!linkURLPath) {
61
+ return;
62
+ }
63
+ const sourceFilePath = file.path;
64
+ const permalink = resolveMarkdownLink({
65
+ sourceFilePath,
66
+ linkPathname: linkURLPath.pathname,
67
+ });
68
+ if (permalink) {
69
+ // This reapplies the link ?qs#hash part to the resolved pathname
70
+ link.url = (0, utils_1.serializeURLPath)({
71
+ ...linkURLPath,
72
+ pathname: permalink,
73
+ });
74
+ }
75
+ else {
76
+ link.url =
77
+ onBrokenMarkdownLinks({
78
+ url: link.url,
79
+ sourceFilePath,
80
+ node: link,
81
+ }) ?? link.url;
82
+ }
83
+ });
84
+ };
85
+ };
86
+ exports.default = plugin;
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/resolveMarkdownLinks/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uDAAuC;AACvC,6CAK2B;AAC3B,wEAAwC;AAExC,oCAAwD;AA6BxD,SAAS,UAAU,CACjB,qBAA6D;IAE7D,IAAI,OAAO,qBAAqB,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,SAAS,GACb,qBAAqB,KAAK,OAAO;YAC/B,CAAC,CAAC,gBAAM,CAAC,WAAW,CAAA,wCAAwC,iDAAiD,8BAA8B,aAAa,oCAAoC;YAC5L,CAAC,CAAC,EAAE,CAAC;QACT,OAAO,CAAC,EAAC,cAAc,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAC,EAAE,EAAE;YAC9C,MAAM,YAAY,GAAG,IAAA,iCAAyB,EAAC,cAAc,CAAC,CAAC;YAC/D,gBAAM,CAAC,MAAM,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E,CAAC;gBACjB,OAAO;YACT,CAAC;YAED,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC;YAEjC,MAAM,SAAS,GAAG,mBAAmB,CAAC;gBACpC,cAAc;gBACd,YAAY,EAAE,WAAW,CAAC,QAAQ;aACnC,CAAC,CAAC;YAEH,IAAI,SAAS,EAAE,CAAC;gBACd,iEAAiE;gBACjE,IAAI,CAAC,GAAG,GAAG,IAAA,wBAAgB,EAAC;oBAC1B,GAAG,WAAW;oBACd,QAAQ,EAAE,SAAS;iBACpB,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG;oBACN,qBAAqB,CAAC;wBACpB,GAAG,EAAE,IAAI,CAAC,GAAG;wBACb,cAAc;wBACd,IAAI,EAAE,IAAI;qBACX,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC;YACnB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;kBAEa,MAAM"}
@@ -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 { Root } from 'mdast';
8
+ import type { Plugin } from 'unified';
9
+ interface PluginOptions {
10
+ name?: string;
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/toc/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,OAAO,KAAK,EAAU,IAAI,EAAC,MAAM,OAAO,CAAC;AACzC,OAAO,KAAK,EAAC,MAAM,EAAc,MAAM,SAAS,CAAC;AAKjD,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AA4HD,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,CA+BzC,CAAC;eAEa,MAAM"}
@@ -0,0 +1,115 @@
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 unist_util_visit_1 = require("unist-util-visit");
10
+ const mdast_util_to_string_1 = require("mdast-util-to-string");
11
+ const utils_1 = require("./utils");
12
+ function createTocSliceImportName({ tocExportName, componentName, }) {
13
+ // The name of the toc slice import alias doesn't matter much
14
+ // We just need to ensure it's valid and won't conflict with other names
15
+ return `__${tocExportName}${componentName}`;
16
+ }
17
+ function collectImportsExports({ root, tocExportName, }) {
18
+ const markdownImports = new Map();
19
+ let existingTocExport = null;
20
+ (0, unist_util_visit_1.visit)(root, 'mdxjsEsm', (node) => {
21
+ if (!node.data?.estree) {
22
+ return;
23
+ }
24
+ if ((0, utils_1.isNamedExport)(node, tocExportName)) {
25
+ existingTocExport = node;
26
+ }
27
+ (0, utils_1.getImportDeclarations)(node.data.estree).forEach((declaration) => {
28
+ if (!(0, utils_1.isMarkdownImport)(declaration)) {
29
+ return;
30
+ }
31
+ const componentName = (0, utils_1.findDefaultImportName)(declaration);
32
+ if (!componentName) {
33
+ return;
34
+ }
35
+ markdownImports.set(componentName, {
36
+ declaration,
37
+ });
38
+ });
39
+ });
40
+ return { markdownImports, existingTocExport };
41
+ }
42
+ function collectTOCItems({ root, tocExportName, markdownImports, }) {
43
+ const tocItems = [];
44
+ (0, unist_util_visit_1.visit)(root, (child) => {
45
+ if (child.type === 'heading') {
46
+ visitHeading(child);
47
+ }
48
+ else if (child.type === 'mdxJsxFlowElement') {
49
+ visitJSXElement(child);
50
+ }
51
+ });
52
+ return { tocItems };
53
+ // Visit Markdown headings
54
+ function visitHeading(node) {
55
+ const value = (0, mdast_util_to_string_1.toString)(node);
56
+ // depth:1 headings are titles and not included in the TOC
57
+ if (!value || node.depth < 2) {
58
+ return;
59
+ }
60
+ tocItems.push({
61
+ type: 'heading',
62
+ heading: node,
63
+ });
64
+ }
65
+ // Visit JSX elements, such as <Partial/>
66
+ function visitJSXElement(node) {
67
+ const componentName = node.name;
68
+ if (!componentName) {
69
+ return;
70
+ }
71
+ const importDeclaration = markdownImports.get(componentName)?.declaration;
72
+ if (!importDeclaration) {
73
+ return;
74
+ }
75
+ const tocSliceImportName = createTocSliceImportName({
76
+ tocExportName,
77
+ componentName,
78
+ });
79
+ tocItems.push({
80
+ type: 'slice',
81
+ importName: tocSliceImportName,
82
+ });
83
+ (0, utils_1.addTocSliceImportIfNeeded)({
84
+ importDeclaration,
85
+ tocExportName,
86
+ tocSliceImportName,
87
+ });
88
+ }
89
+ }
90
+ const plugin = function plugin(options = {}) {
91
+ const tocExportName = options.name || 'toc';
92
+ return (root) => {
93
+ const { markdownImports, existingTocExport } = collectImportsExports({
94
+ root,
95
+ tocExportName,
96
+ });
97
+ // If user explicitly writes "export const toc" in his mdx file
98
+ // We keep it as is do not override their explicit toc structure
99
+ // See https://github.com/facebook/docusaurus/pull/7530#discussion_r1458087876
100
+ if (existingTocExport) {
101
+ return;
102
+ }
103
+ const { tocItems } = collectTOCItems({
104
+ root,
105
+ tocExportName,
106
+ markdownImports,
107
+ });
108
+ root.children.push((0, utils_1.createTOCExportNodeAST)({
109
+ tocExportName,
110
+ tocItems,
111
+ }));
112
+ };
113
+ };
114
+ exports.default = plugin;
115
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/toc/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,uDAAuC;AACvC,+DAA8C;AAC9C,mCAOiB;AAiBjB,SAAS,wBAAwB,CAAC,EAChC,aAAa,EACb,aAAa,GAId;IACC,6DAA6D;IAC7D,wEAAwE;IACxE,OAAO,KAAK,aAAa,GAAG,aAAa,EAAE,CAAC;AAC9C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AG,qBAAqB,CAAC;YACjE,IAAI;YACJ,aAAa;SACd,CAAC,CAAC;QAEH,+DAA+D;QAC/D,gEAAgE;QAChE,8EAA8E;QAC9E,IAAI,iBAAiB,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,MAAM,EAAC,QAAQ,EAAC,GAAG,eAAe,CAAC;YACjC,IAAI;YACJ,aAAa;YACb,eAAe;SAChB,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAChB,IAAA,8BAAsB,EAAC;YACrB,aAAa;YACb,QAAQ;SACT,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;kBAEa,MAAM"}
@@ -0,0 +1,22 @@
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 { Heading } from 'mdast';
8
+ export type TOCItem = {
9
+ readonly value: string;
10
+ readonly id: string;
11
+ readonly level: number;
12
+ };
13
+ export type TOCHeading = {
14
+ readonly type: 'heading';
15
+ readonly heading: Heading;
16
+ };
17
+ export type TOCSlice = {
18
+ readonly type: 'slice';
19
+ readonly importName: string;
20
+ };
21
+ export type TOCItems = (TOCHeading | TOCSlice)[];
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/remark/toc/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAInC,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAGF,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,CAAC,UAAU,GAAG,QAAQ,CAAC,EAAE,CAAC"}
@@ -0,0 +1,9 @@
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
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/remark/toc/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
@@ -0,0 +1,26 @@
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 { MdxjsEsm, MdxJsxTextElement } from 'mdast-util-mdx';
9
+ import type { TOCItems } from './types';
10
+ import type { Program, ImportDeclaration } from 'estree';
11
+ import type { Heading, PhrasingContent } from 'mdast';
12
+ export declare function getImportDeclarations(program: Program): ImportDeclaration[];
13
+ export declare function isMarkdownImport(node: Node): node is ImportDeclaration;
14
+ export declare function findDefaultImportName(importDeclaration: ImportDeclaration): string | undefined;
15
+ export declare function addTocSliceImportIfNeeded({ importDeclaration, tocExportName, tocSliceImportName, }: {
16
+ importDeclaration: ImportDeclaration;
17
+ tocExportName: string;
18
+ tocSliceImportName: string;
19
+ }): void;
20
+ export declare function isNamedExport(node: Node, exportName: string): node is MdxjsEsm;
21
+ export declare function createTOCExportNodeAST({ tocExportName, tocItems, }: {
22
+ tocExportName: string;
23
+ tocItems: TOCItems;
24
+ }): MdxjsEsm;
25
+ export declare function toHeadingHTMLValue(node: PhrasingContent | Heading | MdxJsxTextElement): string;
26
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/remark/toc/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAC,IAAI,EAAS,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EACV,QAAQ,EAER,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAsB,QAAQ,EAAW,MAAM,SAAS,CAAC;AACrE,OAAO,KAAK,EACV,OAAO,EAEP,iBAAiB,EAElB,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAC,OAAO,EAAE,eAAe,EAAC,MAAM,OAAO,CAAC;AAEpD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,EAAE,CAI3E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,iBAAiB,CAMtE;AAED,wBAAgB,qBAAqB,CACnC,iBAAiB,EAAE,iBAAiB,GACnC,MAAM,GAAG,SAAS,CAIpB;AAeD,wBAAgB,yBAAyB,CAAC,EACxC,iBAAiB,EACjB,aAAa,EACb,kBAAkB,GACnB,EAAE;IACD,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,GAAG,IAAI,CASP;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,GACjB,IAAI,IAAI,QAAQ,CAyBlB;AAED,wBAAgB,sBAAsB,CAAC,EACrC,aAAa,EACb,QAAQ,GACT,EAAE;IACD,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,QAAQ,CAAC;CACpB,GAAG,QAAQ,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