@t8/docsgen 0.4.19 → 0.4.20
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 +36 -11
- package/dist/css/section.css +14 -0
- package/package.json +1 -1
- package/src/bin/parsing/getSectionPostprocess.ts +44 -7
- package/src/css/section.css +14 -0
package/dist/bin.js
CHANGED
|
@@ -349,7 +349,7 @@ async function getRepoMetadata({
|
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
// src/bin/parsing/getParsedContent.ts
|
|
352
|
-
import { JSDOM as
|
|
352
|
+
import { JSDOM as JSDOM3 } from "jsdom";
|
|
353
353
|
import Markdown from "markdown-it";
|
|
354
354
|
|
|
355
355
|
// src/bin/getSlug.ts
|
|
@@ -424,15 +424,40 @@ function getInstallationCode(element) {
|
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
// src/bin/parsing/getSectionPostprocess.ts
|
|
427
|
+
import { JSDOM as JSDOM2 } from "jsdom";
|
|
428
|
+
function isPreviewURL(url) {
|
|
429
|
+
return url.startsWith("https://codesandbox.io/p/sandbox/");
|
|
430
|
+
}
|
|
431
|
+
function getPreviewContent(url, title) {
|
|
432
|
+
let { pathname, searchParams } = new URL(url);
|
|
433
|
+
let sandboxId = pathname.split("/").at(-1);
|
|
434
|
+
let file = searchParams.get("file");
|
|
435
|
+
let previewURL = new URL(`https://codesandbox.io/embed/${sandboxId}`);
|
|
436
|
+
let previewContent = title ? `<legend>${title}</legend>` : "";
|
|
437
|
+
previewURL.searchParams.set("view", "preview");
|
|
438
|
+
if (file) previewURL.searchParams.set("module", file);
|
|
439
|
+
previewContent += `<iframe src="${previewURL.href}"${title ? ` title="${title}"` : ""} sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" loading="lazy"></iframe>`;
|
|
440
|
+
return previewContent;
|
|
441
|
+
}
|
|
427
442
|
function getSectionPostprocess(linkMap) {
|
|
428
443
|
return (content) => {
|
|
429
|
-
let
|
|
430
|
-
|
|
431
|
-
let
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
444
|
+
let { document } = new JSDOM2(content).window;
|
|
445
|
+
for (let a of document.querySelectorAll("a")) {
|
|
446
|
+
let href = a.getAttribute("href");
|
|
447
|
+
if (href === null) continue;
|
|
448
|
+
if (isPreviewURL(href) && a.parentElement) {
|
|
449
|
+
let preview = document.createElement("fieldset");
|
|
450
|
+
preview.innerHTML = getPreviewContent(href, a.innerHTML);
|
|
451
|
+
a.parentElement.insertBefore(preview, a);
|
|
452
|
+
a.remove();
|
|
453
|
+
} else {
|
|
454
|
+
let nextHref = linkMap[href] ?? href;
|
|
455
|
+
a.setAttribute("href", nextHref);
|
|
456
|
+
if (/^(https?:)?\/\//.test(nextHref))
|
|
457
|
+
a.setAttribute("target", "_blank");
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return document.body.innerHTML;
|
|
436
461
|
};
|
|
437
462
|
}
|
|
438
463
|
|
|
@@ -485,7 +510,7 @@ async function getParsedContent(ctx) {
|
|
|
485
510
|
let { singlePage, firstLineDescription, linkMap } = ctx;
|
|
486
511
|
let rawContent = await fetchContent(contentLocation);
|
|
487
512
|
let content = md.render(preprocessContent(rawContent));
|
|
488
|
-
let dom = new
|
|
513
|
+
let dom = new JSDOM3(content);
|
|
489
514
|
let { nav, linkMap: navLinkMap } = buildNav(ctx, dom);
|
|
490
515
|
let badges = "";
|
|
491
516
|
let title = "";
|
|
@@ -802,7 +827,7 @@ function escapeRegExp(s) {
|
|
|
802
827
|
}
|
|
803
828
|
|
|
804
829
|
// src/bin/content/getNav.ts
|
|
805
|
-
import { JSDOM as
|
|
830
|
+
import { JSDOM as JSDOM4 } from "jsdom";
|
|
806
831
|
|
|
807
832
|
// src/bin/getNpmLink.ts
|
|
808
833
|
function getNpmLink({ npm }, className) {
|
|
@@ -816,7 +841,7 @@ async function getNav(ctx, navItems) {
|
|
|
816
841
|
let navContent = await fetchContent(nav);
|
|
817
842
|
let s = "";
|
|
818
843
|
if (navContent) {
|
|
819
|
-
let navDom = new
|
|
844
|
+
let navDom = new JSDOM4(navContent).window.document.body;
|
|
820
845
|
for (let link of navDom.querySelectorAll("a")) {
|
|
821
846
|
if (link.dataset.name === name) {
|
|
822
847
|
let parent = link.parentElement;
|
package/dist/css/section.css
CHANGED
|
@@ -250,6 +250,20 @@ main h2 {
|
|
|
250
250
|
main h2:first-child {
|
|
251
251
|
margin-top: 0;
|
|
252
252
|
}
|
|
253
|
+
main fieldset {
|
|
254
|
+
border: 0.05em solid var(--secondary-color);
|
|
255
|
+
}
|
|
256
|
+
main fieldset legend {
|
|
257
|
+
font-size: 0.8em;
|
|
258
|
+
color: var(--secondary-color);
|
|
259
|
+
}
|
|
260
|
+
main fieldset iframe {
|
|
261
|
+
width: 100%;
|
|
262
|
+
height: 360px;
|
|
263
|
+
background: var(--code-block-background);
|
|
264
|
+
border: none;
|
|
265
|
+
overflow: hidden;
|
|
266
|
+
}
|
|
253
267
|
|
|
254
268
|
.pagenav {
|
|
255
269
|
--icon-width: 1.25em;
|
package/package.json
CHANGED
|
@@ -1,16 +1,53 @@
|
|
|
1
|
+
import { JSDOM } from "jsdom";
|
|
2
|
+
|
|
3
|
+
function isPreviewURL(url: string) {
|
|
4
|
+
return url.startsWith("https://codesandbox.io/p/sandbox/");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function getPreviewContent(url: string, title?: string) {
|
|
8
|
+
let { pathname, searchParams } = new URL(url);
|
|
9
|
+
let sandboxId = pathname.split("/").at(-1);
|
|
10
|
+
let file = searchParams.get("file");
|
|
11
|
+
|
|
12
|
+
let previewURL = new URL(`https://codesandbox.io/embed/${sandboxId}`);
|
|
13
|
+
let previewContent = title ? `<legend>${title}</legend>` : "";
|
|
14
|
+
|
|
15
|
+
previewURL.searchParams.set("view", "preview");
|
|
16
|
+
|
|
17
|
+
if (file) previewURL.searchParams.set("module", file);
|
|
18
|
+
|
|
19
|
+
previewContent += `<iframe src="${previewURL.href}"${title ? ` title="${title}"` : ""} sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" loading="lazy"></iframe>`;
|
|
20
|
+
|
|
21
|
+
return previewContent;
|
|
22
|
+
}
|
|
23
|
+
|
|
1
24
|
export function getSectionPostprocess(
|
|
2
25
|
linkMap: Record<string, string | undefined>,
|
|
3
26
|
) {
|
|
4
27
|
return (content: string) => {
|
|
5
|
-
let
|
|
28
|
+
let { document } = new JSDOM(content).window;
|
|
29
|
+
|
|
30
|
+
for (let a of document.querySelectorAll("a")) {
|
|
31
|
+
let href = a.getAttribute("href");
|
|
32
|
+
|
|
33
|
+
if (href === null) continue;
|
|
34
|
+
|
|
35
|
+
if (isPreviewURL(href) && a.parentElement) {
|
|
36
|
+
let preview = document.createElement("fieldset");
|
|
37
|
+
|
|
38
|
+
preview.innerHTML = getPreviewContent(href, a.innerHTML);
|
|
6
39
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
40
|
+
a.parentElement.insertBefore(preview, a);
|
|
41
|
+
a.remove();
|
|
42
|
+
} else {
|
|
43
|
+
let nextHref = linkMap[href] ?? href;
|
|
10
44
|
|
|
11
|
-
|
|
12
|
-
|
|
45
|
+
a.setAttribute("href", nextHref);
|
|
46
|
+
if (/^(https?:)?\/\//.test(nextHref))
|
|
47
|
+
a.setAttribute("target", "_blank");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
13
50
|
|
|
14
|
-
return
|
|
51
|
+
return document.body.innerHTML;
|
|
15
52
|
};
|
|
16
53
|
}
|
package/src/css/section.css
CHANGED
|
@@ -250,6 +250,20 @@ main h2 {
|
|
|
250
250
|
main h2:first-child {
|
|
251
251
|
margin-top: 0;
|
|
252
252
|
}
|
|
253
|
+
main fieldset {
|
|
254
|
+
border: 0.05em solid var(--secondary-color);
|
|
255
|
+
}
|
|
256
|
+
main fieldset legend {
|
|
257
|
+
font-size: 0.8em;
|
|
258
|
+
color: var(--secondary-color);
|
|
259
|
+
}
|
|
260
|
+
main fieldset iframe {
|
|
261
|
+
width: 100%;
|
|
262
|
+
height: 360px;
|
|
263
|
+
background: var(--code-block-background);
|
|
264
|
+
border: none;
|
|
265
|
+
overflow: hidden;
|
|
266
|
+
}
|
|
253
267
|
|
|
254
268
|
.pagenav {
|
|
255
269
|
--icon-width: 1.25em;
|