@t8/docsgen 0.4.22 → 0.4.24

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);
@@ -875,19 +889,14 @@ async function getNav(ctx, navItems) {
875
889
  navItemCount++;
876
890
  }
877
891
  } else {
878
- for (let { id, title, items } of navItems) {
892
+ for (let {
893
+ id,
894
+ title
895
+ /*, items */
896
+ } of navItems) {
879
897
  let itemLink = `${root}${contentDir}/${encodeURIComponent(id)}`;
880
898
  s += `
881
899
  <li data-id="${id}"><a href="${itemLink}">${title}</a>`;
882
- if (items.length !== 0) {
883
- s += "\n <ul>";
884
- for (let { id: id2, title: title2 } of items) {
885
- s += `
886
- <li><a href="${itemLink}#${encodeURIComponent(id2)}">${title2}</a></li>`;
887
- navItemCount++;
888
- }
889
- s += "\n </ul>\n";
890
- }
891
900
  s += "</li>";
892
901
  navItemCount++;
893
902
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/docsgen",
3
- "version": "0.4.22",
3
+ "version": "0.4.24",
4
4
  "description": "",
5
5
  "main": "dist/bin.js",
6
6
  "type": "module",
@@ -42,21 +42,21 @@ export async function getNav(ctx: Context, navItems: NavItem[]) {
42
42
  navItemCount++;
43
43
  }
44
44
  } else {
45
- for (let { id, title, items } of navItems) {
45
+ for (let { id, title /*, items */ } of navItems) {
46
46
  let itemLink = `${root}${contentDir}/${encodeURIComponent(id)}`;
47
47
 
48
48
  s += `\n<li data-id="${id}"><a href="${itemLink}">${title}</a>`;
49
49
 
50
- if (items.length !== 0) {
51
- s += "\n <ul>";
50
+ // if (items.length !== 0) {
51
+ // s += "\n <ul>";
52
52
 
53
- for (let { id, title } of items) {
54
- s += `\n <li><a href="${itemLink}#${encodeURIComponent(id)}">${title}</a></li>`;
55
- navItemCount++;
56
- }
53
+ // for (let { id, title } of items) {
54
+ // s += `\n <li><a href="${itemLink}#${encodeURIComponent(id)}">${title}</a></li>`;
55
+ // navItemCount++;
56
+ // }
57
57
 
58
- s += "\n </ul>\n";
59
- }
58
+ // s += "\n </ul>\n";
59
+ // }
60
60
 
61
61
  s += "</li>";
62
62
  navItemCount++;
@@ -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