@t8/docsgen 0.4.20 → 0.4.22
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 +16 -6
- package/dist/css/section.css +1 -0
- package/package.json +1 -1
- package/src/bin/parsing/getSectionPostprocess.ts +24 -6
- package/src/css/section.css +1 -0
package/dist/bin.js
CHANGED
|
@@ -432,12 +432,16 @@ function getPreviewContent(url, title) {
|
|
|
432
432
|
let { pathname, searchParams } = new URL(url);
|
|
433
433
|
let sandboxId = pathname.split("/").at(-1);
|
|
434
434
|
let file = searchParams.get("file");
|
|
435
|
+
let height = searchParams.get("h");
|
|
435
436
|
let previewURL = new URL(`https://codesandbox.io/embed/${sandboxId}`);
|
|
436
|
-
let
|
|
437
|
+
let content = title ? `<legend>${title}</legend>` : "";
|
|
437
438
|
previewURL.searchParams.set("view", "preview");
|
|
438
439
|
if (file) previewURL.searchParams.set("module", file);
|
|
439
|
-
|
|
440
|
-
|
|
440
|
+
let attrs = [`src="${previewURL.href}"`];
|
|
441
|
+
if (title) attrs.push(`title="${title}"`);
|
|
442
|
+
if (height) attrs.push(`style="height: ${height}px;"`);
|
|
443
|
+
content += `<iframe ${attrs.join(" ")} sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" loading="lazy"></iframe>`;
|
|
444
|
+
return content;
|
|
441
445
|
}
|
|
442
446
|
function getSectionPostprocess(linkMap) {
|
|
443
447
|
return (content) => {
|
|
@@ -445,11 +449,17 @@ function getSectionPostprocess(linkMap) {
|
|
|
445
449
|
for (let a of document.querySelectorAll("a")) {
|
|
446
450
|
let href = a.getAttribute("href");
|
|
447
451
|
if (href === null) continue;
|
|
448
|
-
if (isPreviewURL(href)
|
|
452
|
+
if (isPreviewURL(href)) {
|
|
449
453
|
let preview = document.createElement("fieldset");
|
|
450
454
|
preview.innerHTML = getPreviewContent(href, a.innerHTML);
|
|
451
|
-
a.
|
|
452
|
-
|
|
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
|
+
}
|
|
453
463
|
} else {
|
|
454
464
|
let nextHref = linkMap[href] ?? href;
|
|
455
465
|
a.setAttribute("href", nextHref);
|
package/dist/css/section.css
CHANGED
package/package.json
CHANGED
|
@@ -7,18 +7,25 @@ function isPreviewURL(url: string) {
|
|
|
7
7
|
function getPreviewContent(url: string, title?: string) {
|
|
8
8
|
let { pathname, searchParams } = new URL(url);
|
|
9
9
|
let sandboxId = pathname.split("/").at(-1);
|
|
10
|
+
|
|
10
11
|
let file = searchParams.get("file");
|
|
12
|
+
let height = searchParams.get("h");
|
|
11
13
|
|
|
12
14
|
let previewURL = new URL(`https://codesandbox.io/embed/${sandboxId}`);
|
|
13
|
-
let
|
|
15
|
+
let content = title ? `<legend>${title}</legend>` : "";
|
|
14
16
|
|
|
15
17
|
previewURL.searchParams.set("view", "preview");
|
|
16
18
|
|
|
17
19
|
if (file) previewURL.searchParams.set("module", file);
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
let attrs = [`src="${previewURL.href}"`];
|
|
22
|
+
|
|
23
|
+
if (title) attrs.push(`title="${title}"`);
|
|
24
|
+
if (height) attrs.push(`style="height: ${height}px;"`);
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
content += `<iframe ${attrs.join(" ")} sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" loading="lazy"></iframe>`;
|
|
27
|
+
|
|
28
|
+
return content;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
export function getSectionPostprocess(
|
|
@@ -32,17 +39,28 @@ export function getSectionPostprocess(
|
|
|
32
39
|
|
|
33
40
|
if (href === null) continue;
|
|
34
41
|
|
|
35
|
-
if (isPreviewURL(href)
|
|
42
|
+
if (isPreviewURL(href)) {
|
|
36
43
|
let preview = document.createElement("fieldset");
|
|
37
44
|
|
|
38
45
|
preview.innerHTML = getPreviewContent(href, a.innerHTML);
|
|
39
46
|
|
|
40
|
-
a.
|
|
41
|
-
|
|
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
|
+
}
|
|
42
59
|
} else {
|
|
43
60
|
let nextHref = linkMap[href] ?? href;
|
|
44
61
|
|
|
45
62
|
a.setAttribute("href", nextHref);
|
|
63
|
+
|
|
46
64
|
if (/^(https?:)?\/\//.test(nextHref))
|
|
47
65
|
a.setAttribute("target", "_blank");
|
|
48
66
|
}
|