@mintlify/scraping 4.0.1168 → 4.0.1170
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.
- package/__test__/sdk-go.test.ts +118 -1
- package/bin/sdk/convert.js +40 -0
- package/bin/sdk/convert.js.map +1 -1
- package/bin/sdk/converters/go.js +24 -3
- package/bin/sdk/converters/go.js.map +1 -1
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/sdk/convert.ts +37 -0
- package/src/sdk/converters/go.ts +21 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/scraping",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1170",
|
|
4
4
|
"description": "Scrape documentation frameworks to Mintlify docs",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"format:check": "oxfmt --check"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@mintlify/common": "1.0.
|
|
46
|
+
"@mintlify/common": "1.0.1296",
|
|
47
47
|
"fast-xml-parser": "5.7.3",
|
|
48
48
|
"fs-extra": "11.1.1",
|
|
49
49
|
"graphql": "16.11.0",
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
"optional": true
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "21e4cfc701552fe0fb6d40c8b5b4896fb50c08ff"
|
|
91
91
|
}
|
package/src/sdk/convert.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Root as HastRoot, Element } from 'hast';
|
|
2
2
|
import type {
|
|
3
|
+
Blockquote,
|
|
3
4
|
Definition,
|
|
4
5
|
Heading,
|
|
5
6
|
Html,
|
|
@@ -12,6 +13,7 @@ import type {
|
|
|
12
13
|
Root as MdastRoot,
|
|
13
14
|
Text,
|
|
14
15
|
} from 'mdast';
|
|
16
|
+
import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
|
|
15
17
|
import remarkGfm from 'remark-gfm';
|
|
16
18
|
import remarkMdx from 'remark-mdx';
|
|
17
19
|
import remarkParse from 'remark-parse';
|
|
@@ -99,6 +101,40 @@ export function htmlToMdx(html: string, rewriteLink?: RewriteLink): string {
|
|
|
99
101
|
// paragraph and keep their block boundaries; inline HTML becomes text within
|
|
100
102
|
// its paragraph, merged with its neighbours so a paragraph that opens with a
|
|
101
103
|
// tag still starts with its first word.
|
|
104
|
+
const GITHUB_ALERT_CALLOUTS: Record<string, string> = {
|
|
105
|
+
NOTE: 'Note',
|
|
106
|
+
TIP: 'Tip',
|
|
107
|
+
IMPORTANT: 'Info',
|
|
108
|
+
WARNING: 'Warning',
|
|
109
|
+
CAUTION: 'Danger',
|
|
110
|
+
};
|
|
111
|
+
const GITHUB_ALERT = /^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\][ \t]*(\n|$)/i;
|
|
112
|
+
|
|
113
|
+
function githubAlertsToCallouts(tree: MdastRoot): void {
|
|
114
|
+
visit(tree, 'blockquote', (node: Blockquote, index, parent) => {
|
|
115
|
+
if (!parent || index === undefined) return;
|
|
116
|
+
const [first] = node.children;
|
|
117
|
+
if (first?.type !== 'paragraph') return;
|
|
118
|
+
const [lead] = first.children;
|
|
119
|
+
if (lead?.type !== 'text') return;
|
|
120
|
+
const match = GITHUB_ALERT.exec(lead.value);
|
|
121
|
+
const name = match?.[1] ? GITHUB_ALERT_CALLOUTS[match[1].toUpperCase()] : undefined;
|
|
122
|
+
if (!match || !name) return;
|
|
123
|
+
const next = first.children[1];
|
|
124
|
+
if (match[2] === '' && next !== undefined && next.type !== 'break') return;
|
|
125
|
+
lead.value = lead.value.slice(match[0].length);
|
|
126
|
+
if (lead.value === '') first.children.shift();
|
|
127
|
+
if (first.children[0]?.type === 'break') first.children.shift();
|
|
128
|
+
const callout: MdxJsxFlowElement = {
|
|
129
|
+
type: 'mdxJsxFlowElement',
|
|
130
|
+
name,
|
|
131
|
+
attributes: [],
|
|
132
|
+
children: first.children.length > 0 ? node.children : node.children.slice(1),
|
|
133
|
+
};
|
|
134
|
+
parent.children.splice(index, 1, callout);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
102
138
|
export function parseMarkdown(markdown: string, minHeadingDepth?: Heading['depth']): MdastRoot {
|
|
103
139
|
// CommonMark treats \r\n and a bare \r as line endings; normalising them up
|
|
104
140
|
// front means every later split and check only has to know about \n.
|
|
@@ -132,6 +168,7 @@ export function parseMarkdown(markdown: string, minHeadingDepth?: Heading['depth
|
|
|
132
168
|
visit(mdastTree, 'paragraph', (node: Paragraph) => {
|
|
133
169
|
node.children = mergeText(node.children);
|
|
134
170
|
});
|
|
171
|
+
githubAlertsToCallouts(mdastTree);
|
|
135
172
|
if (minHeadingDepth) {
|
|
136
173
|
visit(mdastTree, 'heading', (node: Heading) => {
|
|
137
174
|
node.depth = node.depth < minHeadingDepth ? minHeadingDepth : node.depth;
|
package/src/sdk/converters/go.ts
CHANGED
|
@@ -404,7 +404,7 @@ class GoRenderer {
|
|
|
404
404
|
private packagePage(): SdkPage {
|
|
405
405
|
const slug =
|
|
406
406
|
this.index.packageSlug(this.pkg.importPath) ?? path.posix.join(this.base, PACKAGE_PAGE);
|
|
407
|
-
const lines = [this.
|
|
407
|
+
const lines = [this.body(this.pkg.doc), this.deprecated(this.pkg.deprecated)];
|
|
408
408
|
const types = this.pkg.types ?? [];
|
|
409
409
|
if (types.length) lines.push('## Types', this.indexList(types.map((type) => type.name)));
|
|
410
410
|
if (this.funcs.length) {
|
|
@@ -505,7 +505,7 @@ class GoRenderer {
|
|
|
505
505
|
|
|
506
506
|
private typePage(type: GoType): SdkPage {
|
|
507
507
|
const lines = [
|
|
508
|
-
this.
|
|
508
|
+
this.body(type.doc),
|
|
509
509
|
this.deprecated(type.deprecated),
|
|
510
510
|
codeBlock(declarationHeader(type)),
|
|
511
511
|
];
|
|
@@ -535,7 +535,7 @@ class GoRenderer {
|
|
|
535
535
|
|
|
536
536
|
private funcPage(fn: GoFunc): SdkPage {
|
|
537
537
|
const lines = [
|
|
538
|
-
this.
|
|
538
|
+
this.body(fn.doc),
|
|
539
539
|
this.deprecated(fn.deprecated),
|
|
540
540
|
codeBlock(codeText(fn.decl)),
|
|
541
541
|
...this.signatureDetails(fn, 2),
|
|
@@ -736,6 +736,24 @@ class GoRenderer {
|
|
|
736
736
|
return markdown ? stringifyMdast(this.doc(markdown).tree) : '';
|
|
737
737
|
}
|
|
738
738
|
|
|
739
|
+
private body(markdown?: string): string {
|
|
740
|
+
if (!markdown) return '';
|
|
741
|
+
const { tree } = this.doc(markdown);
|
|
742
|
+
const [first] = tree.children;
|
|
743
|
+
if (first?.type !== 'paragraph') return stringifyMdast(tree);
|
|
744
|
+
const text = plainText(first).replace(/\s+/g, ' ').trim();
|
|
745
|
+
const sentence = leadingSentence(text);
|
|
746
|
+
if (!sentence || sentence === text || truncate(sentence, MAX_DESCRIPTION) !== sentence) {
|
|
747
|
+
return stringifyMdast(tree);
|
|
748
|
+
}
|
|
749
|
+
const copy = structuredClone(tree);
|
|
750
|
+
const [paragraph] = copy.children;
|
|
751
|
+
if (paragraph?.type !== 'paragraph') return stringifyMdast(tree);
|
|
752
|
+
dropLeadingSentence(paragraph);
|
|
753
|
+
if (paragraph.children.length === 0) copy.children.shift();
|
|
754
|
+
return stringifyMdast(copy);
|
|
755
|
+
}
|
|
756
|
+
|
|
739
757
|
private doc(markdown: string): GoDoc {
|
|
740
758
|
let doc = this.rendered.get(markdown);
|
|
741
759
|
if (!doc) {
|