@rasenganjs/mdx 1.2.0-beta.7 → 1.2.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 (74) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/chunk-U2MZHTHK.js +89 -0
  3. package/dist/index.cjs +922 -0
  4. package/dist/index.d.cts +150 -0
  5. package/dist/index.d.ts +150 -0
  6. package/dist/index.js +798 -0
  7. package/dist/plugin.cjs +289 -0
  8. package/dist/plugin.d.cts +20 -0
  9. package/dist/plugin.d.ts +20 -0
  10. package/dist/plugin.js +174 -0
  11. package/package.json +15 -15
  12. package/tsup.config.ts +11 -0
  13. package/types/client.d.ts +1 -1
  14. package/lib/components/codeblock.d.ts +0 -15
  15. package/lib/components/codeblock.js +0 -62
  16. package/lib/components/codeblock.js.map +0 -1
  17. package/lib/components/codeblock2.d.ts +0 -14
  18. package/lib/components/codeblock2.js +0 -47
  19. package/lib/components/codeblock2.js.map +0 -1
  20. package/lib/components/heading.d.ts +0 -2
  21. package/lib/components/heading.js +0 -27
  22. package/lib/components/heading.js.map +0 -1
  23. package/lib/components/index.d.ts +0 -5
  24. package/lib/components/index.js +0 -8
  25. package/lib/components/index.js.map +0 -1
  26. package/lib/components/markdown.d.ts +0 -7
  27. package/lib/components/markdown.js +0 -28
  28. package/lib/components/markdown.js.map +0 -1
  29. package/lib/components/renderer.d.ts +0 -12
  30. package/lib/components/renderer.js +0 -45
  31. package/lib/components/renderer.js.map +0 -1
  32. package/lib/components/table.d.ts +0 -3
  33. package/lib/components/table.js +0 -5
  34. package/lib/components/table.js.map +0 -1
  35. package/lib/components/toc.d.ts +0 -7
  36. package/lib/components/toc.js +0 -26
  37. package/lib/components/toc.js.map +0 -1
  38. package/lib/hooks/use-toc-observer.d.ts +0 -8
  39. package/lib/hooks/use-toc-observer.js +0 -60
  40. package/lib/hooks/use-toc-observer.js.map +0 -1
  41. package/lib/index.d.ts +0 -13
  42. package/lib/index.js +0 -16
  43. package/lib/index.js.map +0 -1
  44. package/lib/styles/rasengan-mdx.min.css +0 -1
  45. package/lib/types/index.d.ts +0 -67
  46. package/lib/types/index.js +0 -2
  47. package/lib/types/index.js.map +0 -1
  48. package/lib/utils/create-filter.d.ts +0 -8
  49. package/lib/utils/create-filter.js +0 -23
  50. package/lib/utils/create-filter.js.map +0 -1
  51. package/lib/utils/create-heading.d.ts +0 -4
  52. package/lib/utils/create-heading.js +0 -19
  53. package/lib/utils/create-heading.js.map +0 -1
  54. package/lib/utils/define-mdx-config.d.ts +0 -2
  55. package/lib/utils/define-mdx-config.js +0 -4
  56. package/lib/utils/define-mdx-config.js.map +0 -1
  57. package/lib/utils/extract-toc.d.ts +0 -23
  58. package/lib/utils/extract-toc.js +0 -113
  59. package/lib/utils/extract-toc.js.map +0 -1
  60. package/lib/utils/generate-navigation.d.ts +0 -0
  61. package/lib/utils/generate-navigation.js +0 -75
  62. package/lib/utils/generate-navigation.js.map +0 -1
  63. package/lib/utils/index.d.ts +0 -15
  64. package/lib/utils/index.js +0 -4
  65. package/lib/utils/index.js.map +0 -1
  66. package/lib/utils/mark-to-html.d.ts +0 -1
  67. package/lib/utils/mark-to-html.js +0 -15
  68. package/lib/utils/mark-to-html.js.map +0 -1
  69. package/lib/utils/plugin.d.ts +0 -26
  70. package/lib/utils/plugin.js +0 -149
  71. package/lib/utils/plugin.js.map +0 -1
  72. package/lib/utils/polyfill.d.ts +0 -10
  73. package/lib/utils/polyfill.js +0 -15
  74. package/lib/utils/polyfill.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 1.2.0 (2026-04-03)
4
+
5
+ ## 1.2.0-beta.8 (2026-03-14)
6
+
3
7
  ## 1.2.0-beta.7 (2026-01-30)
4
8
 
5
9
  ## 1.2.0-beta.6 (2026-01-11)
@@ -0,0 +1,89 @@
1
+ // src/utils/extract-toc.ts
2
+ import React from "react";
3
+ function extractTOC(markdown) {
4
+ const lines = markdown.split("\n");
5
+ const toc = [];
6
+ lines.forEach((line) => {
7
+ const h2Match = line.match(/^## (.+)/);
8
+ const h3Match = line.match(/^### (.+)/);
9
+ if (h2Match) {
10
+ const title = h2Match[1].trim();
11
+ const anchor = generateAnchor(title);
12
+ toc.push({
13
+ title,
14
+ anchor,
15
+ level: 2,
16
+ children: []
17
+ });
18
+ } else if (h3Match && toc.length > 0) {
19
+ const title = h3Match[1].trim();
20
+ const anchor = generateAnchor(title);
21
+ toc[toc.length - 1].children.push({
22
+ title,
23
+ anchor,
24
+ level: 3
25
+ });
26
+ }
27
+ });
28
+ return toc;
29
+ }
30
+ var generateAnchor = (title) => {
31
+ if (Array.isArray(title)) {
32
+ const text2 = title.map((item) => {
33
+ if (React.isValidElement(item)) {
34
+ return item.props["children"].toString().trim();
35
+ }
36
+ return item.toString().trim();
37
+ }).join(" ");
38
+ const lastItem = title[title.length - 1];
39
+ if (typeof lastItem === "string") {
40
+ const match1 = text2.match(/\s\[#([^\]]+)\]$/);
41
+ if (match1) {
42
+ return {
43
+ id: match1[1],
44
+ // remove the last element from title
45
+ text: title.slice(0, title.length - 1)
46
+ };
47
+ }
48
+ }
49
+ return {
50
+ id: text2.replace(/\s+/g, "-").toLowerCase(),
51
+ text: title
52
+ };
53
+ }
54
+ if (React.isValidElement(title)) {
55
+ return {
56
+ id: title.props["children"].toString().trim().replace(/\s+/g, "-").toLowerCase(),
57
+ text: title
58
+ };
59
+ }
60
+ const strippedTitle = String(toText(title).trim());
61
+ const match = strippedTitle.match(/\s\[#([^\]]+)\]$/);
62
+ let id;
63
+ let text;
64
+ if (match) {
65
+ id = match[1].trim().replace(/\s+/g, "-").toLowerCase();
66
+ text = strippedTitle.replace(match[0], "").trim();
67
+ } else {
68
+ id = strippedTitle.replace(/\s+/g, "-").toLowerCase();
69
+ text = strippedTitle;
70
+ }
71
+ return { id, text };
72
+ };
73
+ function toText(input) {
74
+ if (input == null) return "";
75
+ if (typeof input === "string") return input;
76
+ if (Array.isArray(input)) return input.map(toText).join(" ");
77
+ if (input instanceof Uint8Array)
78
+ return new TextDecoder().decode(input);
79
+ try {
80
+ return String(input);
81
+ } catch {
82
+ return "";
83
+ }
84
+ }
85
+
86
+ export {
87
+ extractTOC,
88
+ generateAnchor
89
+ };