@t8/docsgen 0.4.22 → 0.4.23

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/dist/bin.js CHANGED
@@ -443,6 +443,27 @@ function getPreviewContent(url, title) {
443
443
  content += `<iframe ${attrs.join(" ")} sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" loading="lazy"></iframe>`;
444
444
  return content;
445
445
  }
446
+ function isEmpty(element) {
447
+ return element.innerHTML.trim() === "";
448
+ }
449
+ function insertPreview(preview, a) {
450
+ let p = a.closest("p");
451
+ if (p?.parentElement) {
452
+ p.parentElement.insertBefore(preview, p);
453
+ if (a.nextElementSibling?.matches("br")) a.nextElementSibling.remove();
454
+ a.remove();
455
+ if (isEmpty(p)) p.remove();
456
+ return;
457
+ }
458
+ let li = a.closest("li");
459
+ let list = li?.closest("ul, ol");
460
+ if (li && list?.parentElement) {
461
+ list.parentElement.insertBefore(preview, list);
462
+ a.remove();
463
+ if (isEmpty(li)) li.remove();
464
+ if (isEmpty(list)) list.remove();
465
+ }
466
+ }
446
467
  function getSectionPostprocess(linkMap) {
447
468
  return (content) => {
448
469
  let { document } = new JSDOM2(content).window;
@@ -452,14 +473,7 @@ function getSectionPostprocess(linkMap) {
452
473
  if (isPreviewURL(href)) {
453
474
  let preview = document.createElement("fieldset");
454
475
  preview.innerHTML = getPreviewContent(href, a.innerHTML);
455
- let p = a.closest("p");
456
- if (p?.parentElement) {
457
- p.parentElement.insertBefore(preview, p);
458
- if (a.nextElementSibling?.matches("br"))
459
- a.nextElementSibling.remove();
460
- a.remove();
461
- if (p.innerHTML.trim() === "") p.remove();
462
- }
476
+ insertPreview(preview, a);
463
477
  } else {
464
478
  let nextHref = linkMap[href] ?? href;
465
479
  a.setAttribute("href", nextHref);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/docsgen",
3
- "version": "0.4.22",
3
+ "version": "0.4.23",
4
4
  "description": "",
5
5
  "main": "dist/bin.js",
6
6
  "type": "module",
@@ -28,6 +28,38 @@ function getPreviewContent(url: string, title?: string) {
28
28
  return content;
29
29
  }
30
30
 
31
+ function isEmpty(element: Element) {
32
+ return element.innerHTML.trim() === "";
33
+ }
34
+
35
+ function insertPreview(preview: HTMLElement, a: HTMLAnchorElement) {
36
+ let p: HTMLElement | null = a.closest("p");
37
+
38
+ if (p?.parentElement) {
39
+ p.parentElement.insertBefore(preview, p);
40
+
41
+ if (a.nextElementSibling?.matches("br")) a.nextElementSibling.remove();
42
+
43
+ a.remove();
44
+
45
+ if (isEmpty(p)) p.remove();
46
+
47
+ return;
48
+ }
49
+
50
+ let li = a.closest("li");
51
+ let list = li?.closest("ul, ol");
52
+
53
+ if (li && list?.parentElement) {
54
+ list.parentElement.insertBefore(preview, list);
55
+
56
+ a.remove();
57
+
58
+ if (isEmpty(li)) li.remove();
59
+ if (isEmpty(list)) list.remove();
60
+ }
61
+ }
62
+
31
63
  export function getSectionPostprocess(
32
64
  linkMap: Record<string, string | undefined>,
33
65
  ) {
@@ -44,18 +76,7 @@ export function getSectionPostprocess(
44
76
 
45
77
  preview.innerHTML = getPreviewContent(href, a.innerHTML);
46
78
 
47
- let p = a.closest("p");
48
-
49
- if (p?.parentElement) {
50
- p.parentElement.insertBefore(preview, p);
51
-
52
- if (a.nextElementSibling?.matches("br"))
53
- a.nextElementSibling.remove();
54
-
55
- a.remove();
56
-
57
- if (p.innerHTML.trim() === "") p.remove();
58
- }
79
+ insertPreview(preview, a);
59
80
  } else {
60
81
  let nextHref = linkMap[href] ?? href;
61
82