@mintlify/scraping 4.0.5 → 4.0.6

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 (124) hide show
  1. package/bin/components/AccordionGroup.d.ts +3 -3
  2. package/bin/components/AccordionGroup.js +54 -27
  3. package/bin/components/AccordionGroup.js.map +1 -1
  4. package/bin/components/Card.js +3 -2
  5. package/bin/components/Card.js.map +1 -1
  6. package/bin/components/CardGroup.js +3 -6
  7. package/bin/components/CardGroup.js.map +1 -1
  8. package/bin/components/CodeGroup.d.ts +1 -1
  9. package/bin/components/CodeGroup.js +107 -79
  10. package/bin/components/CodeGroup.js.map +1 -1
  11. package/bin/components/Tabs.d.ts +1 -1
  12. package/bin/components/Tabs.js +50 -23
  13. package/bin/components/Tabs.js.map +1 -1
  14. package/bin/constants.js +3 -3
  15. package/bin/constants.js.map +1 -1
  16. package/bin/nav/listItems.js +0 -1
  17. package/bin/nav/listItems.js.map +1 -1
  18. package/bin/scrapingPipeline/color.d.ts +8 -0
  19. package/bin/scrapingPipeline/color.js +91 -0
  20. package/bin/scrapingPipeline/color.js.map +1 -0
  21. package/bin/scrapingPipeline/group.js +1 -3
  22. package/bin/scrapingPipeline/group.js.map +1 -1
  23. package/bin/scrapingPipeline/icon.d.ts +1 -1
  24. package/bin/scrapingPipeline/icon.js +7 -6
  25. package/bin/scrapingPipeline/icon.js.map +1 -1
  26. package/bin/scrapingPipeline/logo.js +13 -9
  27. package/bin/scrapingPipeline/logo.js.map +1 -1
  28. package/bin/scrapingPipeline/page.js +28 -9
  29. package/bin/scrapingPipeline/page.js.map +1 -1
  30. package/bin/scrapingPipeline/site.js +64 -7
  31. package/bin/scrapingPipeline/site.js.map +1 -1
  32. package/bin/scrapingPipeline/tabs.js +15 -10
  33. package/bin/scrapingPipeline/tabs.js.map +1 -1
  34. package/bin/scrapingPipeline/title.d.ts +2 -0
  35. package/bin/scrapingPipeline/title.js +34 -0
  36. package/bin/scrapingPipeline/title.js.map +1 -0
  37. package/bin/tabs/retrieveReadme.js +0 -1
  38. package/bin/tabs/retrieveReadme.js.map +1 -1
  39. package/bin/tsconfig.build.tsbuildinfo +1 -1
  40. package/bin/types/result.d.ts +1 -0
  41. package/bin/utils/breaks.d.ts +3 -0
  42. package/bin/utils/breaks.js +17 -0
  43. package/bin/utils/breaks.js.map +1 -0
  44. package/bin/utils/children.js +9 -3
  45. package/bin/utils/children.js.map +1 -1
  46. package/bin/utils/className.d.ts +0 -1
  47. package/bin/utils/className.js +1 -1
  48. package/bin/utils/className.js.map +1 -1
  49. package/bin/utils/copyButton.d.ts +3 -0
  50. package/bin/utils/copyButton.js +30 -0
  51. package/bin/utils/copyButton.js.map +1 -0
  52. package/bin/utils/emptyEmphasis.d.ts +2 -0
  53. package/bin/utils/emptyEmphasis.js +18 -0
  54. package/bin/utils/emptyEmphasis.js.map +1 -0
  55. package/bin/utils/emptyParagraphs.d.ts +0 -1
  56. package/bin/utils/emptyParagraphs.js +1 -1
  57. package/bin/utils/emptyParagraphs.js.map +1 -1
  58. package/bin/utils/formatEmphasis.d.ts +2 -0
  59. package/bin/utils/formatEmphasis.js +32 -0
  60. package/bin/utils/formatEmphasis.js.map +1 -0
  61. package/bin/utils/images.js +9 -1
  62. package/bin/utils/images.js.map +1 -1
  63. package/bin/utils/lists.d.ts +2 -0
  64. package/bin/utils/lists.js +21 -0
  65. package/bin/utils/lists.js.map +1 -0
  66. package/bin/utils/log.d.ts +17 -0
  67. package/bin/utils/log.js +15 -5
  68. package/bin/utils/log.js.map +1 -1
  69. package/bin/utils/metadata.d.ts +2 -0
  70. package/bin/utils/metadata.js +23 -0
  71. package/bin/utils/metadata.js.map +1 -0
  72. package/bin/utils/nestedRoots.d.ts +0 -1
  73. package/bin/utils/nestedRoots.js +1 -1
  74. package/bin/utils/nestedRoots.js.map +1 -1
  75. package/bin/utils/position.d.ts +0 -1
  76. package/bin/utils/position.js +1 -1
  77. package/bin/utils/position.js.map +1 -1
  78. package/bin/utils/tableCells.d.ts +2 -0
  79. package/bin/utils/tableCells.js +22 -0
  80. package/bin/utils/tableCells.js.map +1 -0
  81. package/bin/utils/title.d.ts +1 -0
  82. package/bin/utils/title.js +9 -3
  83. package/bin/utils/title.js.map +1 -1
  84. package/bin/utils/updatedAt.d.ts +2 -0
  85. package/bin/utils/updatedAt.js +21 -0
  86. package/bin/utils/updatedAt.js.map +1 -0
  87. package/package.json +2 -2
  88. package/src/components/AccordionGroup.ts +55 -25
  89. package/src/components/Card.ts +3 -2
  90. package/src/components/CardGroup.ts +3 -6
  91. package/src/components/CodeGroup.ts +127 -83
  92. package/src/components/Tabs.ts +57 -24
  93. package/src/constants.ts +3 -3
  94. package/src/nav/listItems.ts +1 -2
  95. package/src/scrapingPipeline/color.ts +107 -0
  96. package/src/scrapingPipeline/group.ts +1 -4
  97. package/src/scrapingPipeline/icon.ts +8 -6
  98. package/src/scrapingPipeline/logo.ts +14 -9
  99. package/src/scrapingPipeline/page.ts +30 -9
  100. package/src/scrapingPipeline/site.ts +83 -7
  101. package/src/scrapingPipeline/tabs.ts +15 -13
  102. package/src/scrapingPipeline/title.ts +38 -0
  103. package/src/tabs/retrieveReadme.ts +1 -2
  104. package/src/types/result.ts +1 -1
  105. package/src/utils/breaks.ts +19 -0
  106. package/src/utils/children.ts +10 -3
  107. package/src/utils/className.ts +1 -1
  108. package/src/utils/copyButton.ts +35 -0
  109. package/src/utils/emptyEmphasis.ts +18 -0
  110. package/src/utils/emptyParagraphs.ts +1 -1
  111. package/src/utils/formatEmphasis.ts +37 -0
  112. package/src/utils/images.ts +13 -2
  113. package/src/utils/lists.ts +22 -0
  114. package/src/utils/log.ts +18 -5
  115. package/src/utils/metadata.ts +26 -0
  116. package/src/utils/nestedRoots.ts +1 -1
  117. package/src/utils/position.ts +1 -1
  118. package/src/utils/tableCells.ts +23 -0
  119. package/src/utils/title.ts +10 -4
  120. package/src/utils/updatedAt.ts +25 -0
  121. package/bin/utils/escape.d.ts +0 -2
  122. package/bin/utils/escape.js +0 -25
  123. package/bin/utils/escape.js.map +0 -1
  124. package/src/utils/escape.ts +0 -30
@@ -1,24 +1,34 @@
1
- import type { Element } from 'hast';
1
+ import type { Element, ElementContent } from 'hast';
2
2
 
3
3
  import type { HastNode, HastNodeIndex, HastNodeParent } from '../types/hast.js';
4
4
 
5
5
  export function gitBookScrapeAccordionGroup(
6
6
  node: HastNode,
7
- _: HastNodeIndex,
7
+ index: HastNodeIndex,
8
8
  parent: HastNodeParent
9
9
  ): Element | undefined {
10
10
  if (node.tagName !== 'Accordion') return undefined;
11
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
12
- if (!parent || !parent.children) return undefined;
11
+ if (!parent || typeof index !== 'number') return undefined;
13
12
 
14
13
  let accordionCount = 0;
15
- for (const child of parent.children) {
16
- if (child.type === 'element' && child.tagName === 'Accordion') accordionCount++;
14
+ while (parent.children[index]) {
15
+ const child = parent.children[index];
16
+ if (!child || child.type !== 'element' || child.tagName !== 'Accordion') break;
17
+ accordionCount++;
18
+ index++;
17
19
  }
18
20
 
19
- if (accordionCount === parent.children.length) {
20
- parent.type = 'element';
21
- (parent as Element).tagName = 'AccordionGroup';
21
+ index -= accordionCount;
22
+
23
+ if (accordionCount > 1) {
24
+ const children = parent.children.splice(index, accordionCount);
25
+ const newNode = {
26
+ type: 'element' as const,
27
+ tagName: 'AccordionGroup',
28
+ properties: {},
29
+ children: children as Array<ElementContent>,
30
+ };
31
+ parent.children.splice(index, 0, newNode);
22
32
  }
23
33
 
24
34
  return undefined;
@@ -26,21 +36,31 @@ export function gitBookScrapeAccordionGroup(
26
36
 
27
37
  export function readmeScrapeAccordionGroup(
28
38
  node: HastNode,
29
- _: HastNodeIndex,
39
+ index: HastNodeIndex,
30
40
  parent: HastNodeParent
31
41
  ): Element | undefined {
32
42
  if (node.tagName !== 'Accordion') return undefined;
33
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
34
- if (!parent || !parent.children) return undefined;
43
+ if (!parent || typeof index !== 'number') return undefined;
35
44
 
36
45
  let accordionCount = 0;
37
- for (const child of parent.children) {
38
- if (child.type === 'element' && child.tagName === 'Accordion') accordionCount++;
46
+ while (parent.children[index]) {
47
+ const child = parent.children[index];
48
+ if (!child || child.type !== 'element' || child.tagName !== 'Accordion') break;
49
+ accordionCount++;
50
+ index++;
39
51
  }
40
52
 
41
- if (accordionCount === parent.children.length) {
42
- parent.type = 'element';
43
- (parent as Element).tagName = 'AccordionGroup';
53
+ index -= accordionCount;
54
+
55
+ if (accordionCount > 1) {
56
+ const children = parent.children.splice(index, accordionCount);
57
+ const newNode = {
58
+ type: 'element' as const,
59
+ tagName: 'AccordionGroup',
60
+ properties: {},
61
+ children: children as Array<ElementContent>,
62
+ };
63
+ parent.children.splice(index, 0, newNode);
44
64
  }
45
65
 
46
66
  return undefined;
@@ -48,21 +68,31 @@ export function readmeScrapeAccordionGroup(
48
68
 
49
69
  export function docusaurusScrapeAccordionGroup(
50
70
  node: HastNode,
51
- _: HastNodeIndex,
71
+ index: HastNodeIndex,
52
72
  parent: HastNodeParent
53
73
  ): Element | undefined {
54
74
  if (node.tagName !== 'Accordion') return undefined;
55
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
56
- if (!parent || !parent.children) return undefined;
75
+ if (!parent || typeof index !== 'number') return undefined;
57
76
 
58
77
  let accordionCount = 0;
59
- for (const child of parent.children) {
60
- if (child.type === 'element' && child.tagName === 'Accordion') accordionCount++;
78
+ while (parent.children[index]) {
79
+ const child = parent.children[index];
80
+ if (!child || child.type !== 'element' || child.tagName !== 'Accordion') break;
81
+ accordionCount++;
82
+ index++;
61
83
  }
62
84
 
63
- if (accordionCount === parent.children.length) {
64
- parent.type = 'element';
65
- (parent as Element).tagName = 'AccordionGroup';
85
+ index -= accordionCount;
86
+
87
+ if (accordionCount > 1) {
88
+ const children = parent.children.splice(index, accordionCount);
89
+ const newNode = {
90
+ type: 'element' as const,
91
+ tagName: 'AccordionGroup',
92
+ properties: {},
93
+ children: children as Array<ElementContent>,
94
+ };
95
+ parent.children.splice(index, 0, newNode);
66
96
  }
67
97
 
68
98
  return undefined;
@@ -72,6 +72,7 @@ export function readmeScrapeCard(
72
72
  !node.properties.className.includes('card') &&
73
73
  !node.properties.className.includes('Card') &&
74
74
  !node.properties.className.includes('docs-card') &&
75
+ !node.properties.className.includes('next-steps__step') &&
75
76
  !node.properties.className.join(' ').includes('_card') &&
76
77
  !node.properties.className.join(' ').includes('-card'))
77
78
  ) {
@@ -107,7 +108,7 @@ export function readmeScrapeCard(
107
108
  title: title,
108
109
  href: href,
109
110
  },
110
- children: turnChildrenIntoMdx(parent.children as Array<Element>) as Array<ElementContent>,
111
+ children: turnChildrenIntoMdx(node.children as Array<Element>) as Array<ElementContent>,
111
112
  };
112
113
 
113
114
  return newNode;
@@ -161,7 +162,7 @@ export function docusaurusScrapeCard(
161
162
  title: title,
162
163
  href: href,
163
164
  },
164
- children: turnChildrenIntoMdx(parent.children as Array<Element>) as Array<ElementContent>,
165
+ children: turnChildrenIntoMdx(node.children as Array<Element>) as Array<ElementContent>,
165
166
  };
166
167
 
167
168
  return newNode;
@@ -8,8 +8,7 @@ export function gitBookScrapeCardGroup(
8
8
  parent: HastNodeParent
9
9
  ): Element | undefined {
10
10
  if (node.tagName !== 'Card') return undefined;
11
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
12
- if (!parent || !parent.children) return undefined;
11
+ if (!parent) return undefined;
13
12
 
14
13
  let cardCount = 0;
15
14
  for (const child of parent.children) {
@@ -30,8 +29,7 @@ export function readmeScrapeCardGroup(
30
29
  parent: HastNodeParent
31
30
  ): Element | undefined {
32
31
  if (node.tagName !== 'Card') return undefined;
33
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
34
- if (!parent || !parent.children) return undefined;
32
+ if (!parent) return undefined;
35
33
 
36
34
  let cardCount = 0;
37
35
  for (const child of parent.children) {
@@ -52,8 +50,7 @@ export function docusaurusScrapeCardGroup(
52
50
  parent: HastNodeParent
53
51
  ): Element | undefined {
54
52
  if (node.tagName !== 'Card') return undefined;
55
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
56
- if (!parent || !parent.children) return undefined;
53
+ if (!parent) return undefined;
57
54
 
58
55
  let cardCount = 0;
59
56
  for (const child of parent.children) {
@@ -6,36 +6,30 @@ import { assertIsDefined } from '../assert.js';
6
6
  import type { HastNode, HastNodeIndex, HastNodeParent } from '../types/hast.js';
7
7
  import { turnChildrenIntoMdx } from '../utils/children.js';
8
8
 
9
- function tabContainsOnlyCode(node: Element): boolean {
9
+ function tabContainsOnlyCode(node: Element | undefined): boolean {
10
+ if (!node) return false;
11
+
10
12
  let tabsCount = 0;
11
13
  let onlyCodeCount = 0;
12
14
 
13
15
  visit(node, 'element', function (subNode) {
14
- if (subNode.properties.role && subNode.properties.role === 'tabpanel') tabsCount++;
15
- visit(subNode, 'element', function (tabNode, index, parent) {
16
- if (tabNode.tagName === 'button' && typeof index === 'number' && parent) {
17
- parent.children.splice(index, 1);
18
- }
19
- });
16
+ if (subNode.properties.role !== 'tabpanel') return CONTINUE;
17
+ tabsCount++;
20
18
  if (
21
19
  subNode.children[0] &&
22
- subNode.children[1] &&
23
- subNode.children[2] &&
24
20
  subNode.children[0].type === 'element' &&
25
21
  subNode.children[0].children.length === 1 &&
26
- subNode.children[1].type === 'element' &&
27
- subNode.children[1].children.length === 1 &&
28
- subNode.children[2].type === 'element' &&
29
- subNode.children[2].children.length > 1 &&
30
- subNode.children[2].children.length < 4 &&
31
- subNode.children[2].children.find(
22
+ subNode.children[0].children[0] &&
23
+ subNode.children[0].children[0].type === 'element' &&
24
+ subNode.children[0].children[0].children.length > 1 &&
25
+ subNode.children[0].children[0].children.find(
32
26
  (child) => child.type === 'element' && (child.tagName === 'pre' || child.tagName === 'code')
33
- )
27
+ ) !== undefined
34
28
  ) {
35
- return onlyCodeCount++;
29
+ onlyCodeCount++;
36
30
  }
37
31
  });
38
- return onlyCodeCount === tabsCount;
32
+ return onlyCodeCount === tabsCount && tabsCount > 0;
39
33
  }
40
34
 
41
35
  export function gitBookScrapeCodeGroup(
@@ -43,11 +37,46 @@ export function gitBookScrapeCodeGroup(
43
37
  _: HastNodeIndex,
44
38
  parent: HastNodeParent
45
39
  ): Element | undefined {
46
- if (node.tagName !== 'div' || !node.properties.role || node.properties.role !== 'tablist') {
47
- return undefined;
40
+ if (
41
+ node.tagName === 'div' &&
42
+ Array.isArray(node.properties.className) &&
43
+ node.properties.className.includes('group/codeblock') &&
44
+ node.children.length === 2 &&
45
+ node.children[0] &&
46
+ node.children[1] &&
47
+ node.children[1].type === 'element' &&
48
+ (node.children[1].tagName === 'pre' || node.children[1].tagName === 'code')
49
+ ) {
50
+ let title = '';
51
+ visit(node.children[0], 'text', function (subNode) {
52
+ title = subNode.value;
53
+ return EXIT;
54
+ });
55
+
56
+ if (!title) return undefined;
57
+
58
+ const children = turnChildrenIntoMdx([node.children[1]]);
59
+ const code = {
60
+ type: 'code',
61
+ lang: 'bash',
62
+ meta: title,
63
+ value: (children[0] as unknown as Code).value,
64
+ };
65
+
66
+ const newNode: Element = {
67
+ type: 'element',
68
+ tagName: 'CodeGroup',
69
+ properties: {},
70
+ children: [code] as Array<ElementContent>,
71
+ };
72
+
73
+ return newNode;
48
74
  }
49
75
 
50
- if (!tabContainsOnlyCode(node)) return undefined;
76
+ if (node.tagName !== 'div' || node.properties.role !== 'tablist') return undefined;
77
+
78
+ if (!tabContainsOnlyCode(parent as Element | undefined)) return undefined;
79
+ assertIsDefined(parent);
51
80
 
52
81
  const titles: Array<string> = [];
53
82
  visit(node, 'element', function (subNode) {
@@ -58,28 +87,31 @@ export function gitBookScrapeCodeGroup(
58
87
  });
59
88
  });
60
89
 
61
- assertIsDefined(parent);
62
90
  parent.children.shift();
63
91
 
64
- let lang = '';
65
- visit(node, 'element', function (subNode) {
66
- if (subNode.tagName === 'code' && 'id' in subNode.properties) {
67
- lang = subNode.properties.id as string;
68
- return EXIT;
92
+ const langs: Array<string> = [];
93
+ visit(parent, 'element', function (subNode) {
94
+ if (
95
+ subNode.tagName === 'div' &&
96
+ 'id' in subNode.properties &&
97
+ subNode.properties.role === 'tabpanel'
98
+ ) {
99
+ langs.push(subNode.properties.id as string);
69
100
  }
70
101
  });
71
102
 
72
103
  const children = turnChildrenIntoMdx(parent.children) as Array<ElementContent>;
73
104
  const tabChildren: Array<ElementContent> = [];
74
- for (let childIndex = 0; childIndex < children.length; childIndex++) {
75
- const child = children[childIndex];
105
+ children.forEach((child, index) => {
106
+ const lang = langs[index] || 'bash';
107
+ const title = titles[index] || lang;
76
108
  tabChildren.push({
77
109
  type: 'code',
78
110
  lang: lang,
79
- meta: titles[childIndex],
111
+ meta: title,
80
112
  value: (child as unknown as Code).value,
81
113
  } as unknown as ElementContent);
82
- }
114
+ });
83
115
 
84
116
  const newNode: Element = {
85
117
  type: 'element',
@@ -88,13 +120,15 @@ export function gitBookScrapeCodeGroup(
88
120
  children: tabChildren as Array<ElementContent>,
89
121
  };
90
122
 
123
+ parent.children.length = 0;
124
+
91
125
  return newNode;
92
126
  }
93
127
 
94
128
  export function readmeScrapeCodeGroup(
95
129
  node: HastNode,
96
130
  _: HastNodeIndex,
97
- parent: HastNodeParent
131
+ __: HastNodeParent
98
132
  ): Element | undefined {
99
133
  if (
100
134
  node.tagName !== 'div' ||
@@ -105,52 +139,53 @@ export function readmeScrapeCodeGroup(
105
139
  return undefined;
106
140
  }
107
141
 
108
- if (node.children.length !== 2 || !node.children[0] || !node.children[1]) return undefined;
109
- const tabTitles = node.children[0];
110
-
111
- const titles: Array<string> = [];
112
- visit(tabTitles, 'element', function (subNode) {
113
- visit(subNode, 'text', function (textNode) {
114
- titles.push(textNode.value);
115
- return EXIT;
116
- });
117
- });
118
-
119
- assertIsDefined(parent);
120
- node.children.shift();
121
-
122
- let lang = '';
123
- visit(node, 'element', function (subNode, _, subParent) {
142
+ let newNode: Element | undefined = undefined;
143
+ visit(node, 'element', function (node) {
124
144
  if (
125
- subNode.tagName === 'code' &&
126
- subParent &&
127
- subParent.type === 'element' &&
128
- subParent.tagName === 'pre' &&
129
- 'dataLang' in subNode.properties
145
+ node.tagName !== 'div' ||
146
+ !node.properties.className ||
147
+ !Array.isArray(node.properties.className) ||
148
+ !node.properties.className.includes('CodeTabs-inner')
130
149
  ) {
131
- lang = subNode.properties.dataLang as string;
132
- return EXIT;
150
+ return CONTINUE;
133
151
  }
134
- });
135
152
 
136
- const children = turnChildrenIntoMdx(node.children) as Array<ElementContent>;
137
- const tabChildren: Array<ElementContent> = [];
138
- for (let childIndex = 0; childIndex < children.length; childIndex++) {
139
- const child = children[childIndex];
140
- tabChildren.push({
141
- type: 'code',
142
- lang: lang,
143
- meta: titles[childIndex],
144
- value: (child as unknown as Code).value,
145
- } as unknown as ElementContent);
146
- }
153
+ const langs: Array<string> = [];
154
+ const titles: Array<string> = [];
155
+ visit(node, 'element', function (subNode) {
156
+ if (
157
+ subNode.tagName !== 'code' ||
158
+ !Array.isArray(subNode.properties.className) ||
159
+ !subNode.properties.className.includes('rdmd-code')
160
+ )
161
+ return CONTINUE;
147
162
 
148
- const newNode: Element = {
149
- type: 'element',
150
- tagName: 'CodeGroup',
151
- properties: {},
152
- children: tabChildren as Array<ElementContent>,
153
- };
163
+ langs.push((subNode.properties.dataLang as string | undefined) ?? '');
164
+ titles.push((subNode.properties.name as string | undefined) ?? '');
165
+ });
166
+
167
+ const children = turnChildrenIntoMdx(node.children) as Array<ElementContent>;
168
+ const tabChildren: Array<ElementContent> = [];
169
+ children.forEach((child, index) => {
170
+ const lang = langs[index] || 'bash';
171
+ const title = titles[index] || lang;
172
+ tabChildren.push({
173
+ type: 'code',
174
+ lang: lang,
175
+ meta: title,
176
+ value: (child as unknown as Code).value,
177
+ } as unknown as ElementContent);
178
+ });
179
+
180
+ newNode = {
181
+ type: 'element',
182
+ tagName: 'CodeGroup',
183
+ properties: {},
184
+ children: tabChildren as Array<ElementContent>,
185
+ };
186
+
187
+ return EXIT;
188
+ });
154
189
 
155
190
  return newNode;
156
191
  }
@@ -165,6 +200,7 @@ export function docusaurusScrapeCodeGroup(
165
200
  }
166
201
 
167
202
  if (!tabContainsOnlyCode(node)) return undefined;
203
+ assertIsDefined(parent);
168
204
 
169
205
  const titles: Array<string> = [];
170
206
  visit(node, 'element', function (subNode) {
@@ -175,28 +211,34 @@ export function docusaurusScrapeCodeGroup(
175
211
  });
176
212
  });
177
213
 
178
- assertIsDefined(parent);
179
214
  parent.children.shift();
180
215
 
181
- let lang = '';
182
- visit(node, 'element', function (subNode) {
183
- if (Array.isArray(subNode.properties.className) && subNode.properties.className.length > 0) {
184
- lang = subNode.properties.className[0] as string;
185
- lang = lang.replace('language-', '');
216
+ const langs: Array<string> = [];
217
+ visit(parent, 'element', function (subNode) {
218
+ if (
219
+ subNode.tagName === 'div' &&
220
+ Array.isArray(subNode.properties.className) &&
221
+ subNode.properties.className.find((className) => className.toString().includes('language-'))
222
+ ) {
223
+ const lang = subNode.properties.className.find((className) =>
224
+ className.toString().includes('language-')
225
+ );
226
+ langs.push(lang?.toString().replace('language-', '') ?? '');
186
227
  }
187
228
  });
188
229
 
189
230
  const children = turnChildrenIntoMdx(parent.children) as Array<ElementContent>;
190
231
  const tabChildren: Array<ElementContent> = [];
191
- for (let childIndex = 0; childIndex < children.length; childIndex++) {
192
- const child = children[childIndex];
232
+ children.forEach((child, index) => {
233
+ const lang = langs[index] || 'bash';
234
+ const title = titles[index] || lang;
193
235
  tabChildren.push({
194
236
  type: 'code',
195
237
  lang: lang,
196
- meta: titles[childIndex],
238
+ meta: title,
197
239
  value: (child as unknown as Code).value,
198
240
  } as unknown as ElementContent);
199
- }
241
+ });
200
242
 
201
243
  const newNode: Element = {
202
244
  type: 'element',
@@ -205,5 +247,7 @@ export function docusaurusScrapeCodeGroup(
205
247
  children: tabChildren as Array<ElementContent>,
206
248
  };
207
249
 
250
+ parent.children.length = 0;
251
+
208
252
  return newNode;
209
253
  }
@@ -55,47 +55,80 @@ export function gitBookScrapeTabs(
55
55
  export function readmeScrapeTabs(
56
56
  node: HastNode,
57
57
  _: HastNodeIndex,
58
- parent: HastNodeParent
58
+ __: HastNodeParent
59
59
  ): Element | undefined {
60
60
  if (
61
61
  (node.tagName !== 'div' && node.tagName !== 'a') ||
62
62
  !node.properties.className ||
63
63
  !Array.isArray(node.properties.className) ||
64
- !node.properties.className.includes('tabbed-component')
64
+ (!node.properties.className.includes('tabbed-component') &&
65
+ !node.properties.className.includes('tabs') &&
66
+ !node.properties.className.includes('Tabs'))
65
67
  ) {
66
68
  return undefined;
67
69
  }
68
70
 
69
- if (node.children.length < 2 || !node.children[0] || !node.children[1]) return undefined;
70
- const tabTitles = node.children[0];
71
+ if (!node.children[0] || !node.children[1]) return undefined;
71
72
 
72
73
  const titles: Array<string> = [];
73
- visit(tabTitles, 'element', function (subNode) {
74
- visit(subNode, 'text', function (textNode) {
75
- titles.push(textNode.value);
76
- return EXIT;
77
- });
78
- });
74
+ const tabContents: Array<Element> = [];
79
75
 
80
- assertIsDefined(parent);
81
- node.children.shift();
76
+ if (node.children.length !== 2) {
77
+ visit(node, 'element', function (subNode) {
78
+ if (subNode.tagName !== 'label' && subNode.tagName !== 'button') return CONTINUE;
82
79
 
83
- const children = turnChildrenIntoMdx(node.children) as Array<ElementContent>;
84
- const tabChildren: Array<ElementContent> = [];
85
- for (let childIndex = 0; childIndex < children.length; childIndex++) {
86
- const child = children[childIndex];
87
- if (child) {
88
- tabChildren.push({
89
- type: 'element',
90
- tagName: 'Tab',
91
- properties: {
92
- title: titles[childIndex],
93
- },
94
- children: [child],
80
+ let title = '';
81
+ visit(subNode, 'text', function (textNode) {
82
+ title += textNode.value;
83
+ });
84
+
85
+ titles.push(title.trim().replace('\n', ''));
86
+ });
87
+
88
+ tabContents.push(
89
+ ...(node.children.filter((subNode) => {
90
+ if (
91
+ subNode.type === 'element' &&
92
+ Array.isArray(subNode.properties.className) &&
93
+ (subNode.properties.className.includes('tab') ||
94
+ subNode.properties.className.includes('Tab') ||
95
+ subNode.properties.className.includes('tabbed-content') ||
96
+ subNode.properties.className.includes('tab-content'))
97
+ )
98
+ return true;
99
+ return false;
100
+ }) as Array<Element>)
101
+ );
102
+ } else {
103
+ const tabTitles = node.children[0];
104
+
105
+ visit(tabTitles, 'element', function (subNode) {
106
+ visit(subNode, 'text', function (textNode) {
107
+ titles.push(textNode.value);
108
+ return EXIT;
95
109
  });
110
+ });
111
+
112
+ node.children.shift();
113
+ if (node.children[0].type === 'element') {
114
+ tabContents.push(...(node.children[0].children as Array<Element>));
96
115
  }
97
116
  }
98
117
 
118
+ const tabChildren: Array<ElementContent> = [];
119
+ tabContents.forEach((tab, index) => {
120
+ if (!titles[index]) return;
121
+ const children = turnChildrenIntoMdx([tab]) as Array<ElementContent>;
122
+ tabChildren.push({
123
+ type: 'element',
124
+ tagName: 'Tab',
125
+ properties: {
126
+ title: titles[index],
127
+ },
128
+ children,
129
+ });
130
+ });
131
+
99
132
  const newNode: Element = {
100
133
  type: 'element',
101
134
  tagName: 'Tabs',
package/src/constants.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { colors } from './utils/log.js';
1
+ import { activeColors } from './utils/log.js';
2
2
 
3
3
  export const SUPPORTED_MEDIA_EXTENSIONS = [
4
4
  'png',
@@ -51,5 +51,5 @@ ${SPACES}We currently support: ReadMe, GitBook, and Docusaurus`;
51
51
  export const MDAST_FAILURE_MSG = 'failed to convert MDAST to Markdown string';
52
52
 
53
53
  export const FINAL_SUCCESS_MESSAGE = `We've successfully scraped your docs site.
54
- ${SPACES}We've downloaded the ${colors.cyan}\`navigation\`${colors.default} array (and if necessary, the ${colors.cyan}\`tabs\`${colors.cyan} array)
55
- ${SPACES}into ${colors.blue}\`mint.json\`${colors.default}.`;
54
+ ${SPACES}We've downloaded the ${activeColors.cyan}\`navigation\`${activeColors.default} array (and if necessary, the ${activeColors.cyan}\`tabs\`${activeColors.default} array)
55
+ ${SPACES}into ${activeColors.blue}\`mint.json\`${activeColors.default}.`;
@@ -33,7 +33,7 @@ export function processListItem(
33
33
  return undefined;
34
34
  }
35
35
 
36
- let isApiReferenceLink = false;
36
+ let isApiReferenceLink = false as boolean;
37
37
  visit(link, 'element', function (subNode) {
38
38
  if (
39
39
  subNode.tagName === 'span' &&
@@ -44,7 +44,6 @@ export function processListItem(
44
44
  return EXIT;
45
45
  }
46
46
  });
47
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
48
47
  if (isApiReferenceLink) return undefined;
49
48
 
50
49
  if (linkHref.startsWith('/')) linkHref = linkHref.substring(1);