@mintlify/scraping 4.0.1117 → 4.0.1118

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/scraping",
3
- "version": "4.0.1117",
3
+ "version": "4.0.1118",
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.1245",
46
+ "@mintlify/common": "1.0.1246",
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": "2e4488638a4ebfbec9edce575ab84a0df7d8d329"
90
+ "gitHead": "00242cc7f875194e9a9140c29c0fe8a00e5cd318"
91
91
  }
@@ -1,3 +1,4 @@
1
+ import { hastToText } from '@mintlify/common';
1
2
  import fse from 'fs-extra';
2
3
  import type { Element, ElementContent, Root as HastRoot } from 'hast';
3
4
  import path from 'node:path';
@@ -196,7 +197,7 @@ function explodePyDl(dl: Element, depth: number): ElementContent[] {
196
197
  if (child.tagName === 'dt' && classList(child).includes('sig')) {
197
198
  const name = findDescName(child);
198
199
  if (name) out.push(heading(Math.min(3 + depth, 6), callable ? `${name}()` : name));
199
- out.push(pythonCodeBlock(textOf(child).replace(/\s+/g, ' ').trim()));
200
+ out.push(pythonCodeBlock(hastToText(child).replace(/\s+/g, ' ').trim()));
200
201
  } else if (child.tagName === 'dd') {
201
202
  transformPyDls(child, depth + 1);
202
203
  out.push(...child.children);
@@ -209,7 +210,7 @@ function findDescName(node: Element): string | undefined {
209
210
  let name: string | undefined;
210
211
  visit(node, 'element', (inner: Element) => {
211
212
  if (!classList(inner).includes('descname')) return;
212
- name = textOf(inner).trim();
213
+ name = hastToText(inner).trim();
213
214
  return SKIP;
214
215
  });
215
216
  return name;
@@ -238,7 +239,7 @@ function extractDescription(hast: HastRoot): string | undefined {
238
239
  visit(hast, 'element', (node: Element, _index, parent) => {
239
240
  if (description || node.tagName !== 'p') return;
240
241
  if (parent && parent.type === 'element' && parent.tagName === 'li') return SKIP;
241
- const text = textOf(node).replace(/\s+/g, ' ').trim();
242
+ const text = hastToText(node).replace(/\s+/g, ' ').trim();
242
243
  if (!text || text.startsWith('Bases:')) return;
243
244
  const sentence = text.split(/(?<=\.)\s/)[0] ?? text;
244
245
  description = sentence.length > 160 ? `${sentence.slice(0, 159)}…` : sentence;
@@ -246,12 +247,6 @@ function extractDescription(hast: HastRoot): string | undefined {
246
247
  return description;
247
248
  }
248
249
 
249
- function textOf(node: ElementContent): string {
250
- if (node.type === 'text') return node.value;
251
- if ('children' in node) return node.children.map(textOf).join('');
252
- return '';
253
- }
254
-
255
250
  function classList(node: Element): string[] {
256
251
  const value = node.properties.className;
257
252
  return Array.isArray(value)