@t8/docsgen 0.2.28 → 0.2.30
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 +43 -46
- package/dist/css/index.css +3 -1
- package/package.json +1 -1
- package/src/bin/parsing/getParsedContent.ts +33 -33
- package/src/bin/parsing/isBadgeContainer.ts +18 -0
- package/src/css/index.css +3 -1
package/dist/bin.js
CHANGED
|
@@ -451,7 +451,7 @@ function getTitle(ctx, { cover, originalContent, withPackageURL } = {}) {
|
|
|
451
451
|
}
|
|
452
452
|
|
|
453
453
|
// src/bin/parsing/getParsedContent.ts
|
|
454
|
-
var
|
|
454
|
+
var import_jsdom3 = require("jsdom");
|
|
455
455
|
var import_markdown_it = __toESM(require("markdown-it"));
|
|
456
456
|
|
|
457
457
|
// src/bin/getSlug.ts
|
|
@@ -538,26 +538,22 @@ function getSectionPostprocess(linkMap) {
|
|
|
538
538
|
};
|
|
539
539
|
}
|
|
540
540
|
|
|
541
|
+
// src/bin/parsing/isBadgeContainer.ts
|
|
542
|
+
var badgeImageSelector = 'img[src^="https://img.shields.io/"], img[src^="https://flat.badgen.net/"]';
|
|
543
|
+
function isBadgeContainer(element) {
|
|
544
|
+
if (!element.matches("p") || element.children.length === 0) return false;
|
|
545
|
+
for (let e of element.children) {
|
|
546
|
+
if (!e.matches(badgeImageSelector) && (!e.matches("a") || e.children.length !== 1 || !e.children[0]?.matches(badgeImageSelector)))
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
|
|
541
552
|
// src/bin/parsing/joinLines.ts
|
|
542
553
|
function joinLines(x) {
|
|
543
554
|
return x.join("\n").trim();
|
|
544
555
|
}
|
|
545
556
|
|
|
546
|
-
// src/bin/parsing/postprocessBadges.ts
|
|
547
|
-
var import_jsdom3 = require("jsdom");
|
|
548
|
-
function postprocessBadges(content) {
|
|
549
|
-
let { document } = new import_jsdom3.JSDOM(content).window;
|
|
550
|
-
for (let img of document.querySelectorAll("img")) {
|
|
551
|
-
let parent = img.parentElement;
|
|
552
|
-
if (!parent) continue;
|
|
553
|
-
let container = document.createElement("span");
|
|
554
|
-
container.className = "badge";
|
|
555
|
-
parent.insertBefore(container, img);
|
|
556
|
-
container.append(img);
|
|
557
|
-
}
|
|
558
|
-
return document.body.innerHTML;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
557
|
// src/bin/parsing/preprocessContent.ts
|
|
562
558
|
var marker = {
|
|
563
559
|
show: {
|
|
@@ -589,9 +585,9 @@ async function getParsedContent(ctx) {
|
|
|
589
585
|
getLocation(ctx, "README.md", ctx.source)
|
|
590
586
|
);
|
|
591
587
|
let content = md.render(preprocessContent(rawContent));
|
|
592
|
-
let dom = new
|
|
588
|
+
let dom = new import_jsdom3.JSDOM(content);
|
|
593
589
|
let { nav, linkMap: navLinkMap } = buildNav(ctx, dom);
|
|
594
|
-
let badges =
|
|
590
|
+
let badges = "";
|
|
595
591
|
let title = "";
|
|
596
592
|
let description = [];
|
|
597
593
|
let descriptionNote = [];
|
|
@@ -601,41 +597,41 @@ async function getParsedContent(ctx) {
|
|
|
601
597
|
let installation = "";
|
|
602
598
|
let section = [];
|
|
603
599
|
let sections = [];
|
|
604
|
-
let hasTitle = false;
|
|
605
600
|
let hasFeatures = false;
|
|
606
601
|
let indexComplete = false;
|
|
607
|
-
let element
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
602
|
+
for (let element of dom.window.document.body.children) {
|
|
603
|
+
if (isBadgeContainer(element)) {
|
|
604
|
+
badges = element.outerHTML;
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
if (element.matches("h1")) {
|
|
608
|
+
title = element.innerHTML;
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
if (element.matches("h2")) {
|
|
612
|
+
if (!indexComplete) indexComplete = true;
|
|
613
|
+
if (!singlePage && section.length !== 0) {
|
|
614
|
+
sections.push(joinLines(section));
|
|
615
|
+
section = [];
|
|
617
616
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
features.push(outerHTML);
|
|
626
|
-
} else {
|
|
627
|
-
let installationCode = getInstallationCode(element);
|
|
628
|
-
if (installationCode) installation = installationCode;
|
|
629
|
-
else if (description.length === 0) description.push(outerHTML);
|
|
630
|
-
else intro.push(outerHTML);
|
|
631
|
-
}
|
|
617
|
+
}
|
|
618
|
+
let { outerHTML } = element;
|
|
619
|
+
if (indexComplete) section.push(outerHTML);
|
|
620
|
+
else if (!hasFeatures) {
|
|
621
|
+
if (element.matches("ul")) {
|
|
622
|
+
hasFeatures = true;
|
|
623
|
+
features.push(outerHTML);
|
|
632
624
|
} else {
|
|
633
625
|
let installationCode = getInstallationCode(element);
|
|
634
626
|
if (installationCode) installation = installationCode;
|
|
635
|
-
else
|
|
627
|
+
else if (description.length === 0) description.push(outerHTML);
|
|
628
|
+
else intro.push(outerHTML);
|
|
636
629
|
}
|
|
630
|
+
} else {
|
|
631
|
+
let installationCode = getInstallationCode(element);
|
|
632
|
+
if (installationCode) installation = installationCode;
|
|
633
|
+
else note.push(outerHTML);
|
|
637
634
|
}
|
|
638
|
-
element = element.nextElementSibling;
|
|
639
635
|
}
|
|
640
636
|
if (section.length !== 0) sections.push(joinLines(section));
|
|
641
637
|
let postprocess = getSectionPostprocess({
|
|
@@ -658,7 +654,8 @@ async function getParsedContent(ctx) {
|
|
|
658
654
|
}
|
|
659
655
|
}
|
|
660
656
|
return {
|
|
661
|
-
badges
|
|
657
|
+
badges,
|
|
658
|
+
// postprocessBadges(joinLines(badges)),
|
|
662
659
|
title,
|
|
663
660
|
description: joinLines(description),
|
|
664
661
|
descriptionNote: joinLines(descriptionNote),
|
package/dist/css/index.css
CHANGED
|
@@ -163,8 +163,10 @@ section.intro .section-content {
|
|
|
163
163
|
padding: 1rem var(--content-padding-x);
|
|
164
164
|
}
|
|
165
165
|
section.intro-title {
|
|
166
|
+
flex: auto;
|
|
166
167
|
width: auto;
|
|
167
168
|
align-items: center;
|
|
169
|
+
justify-content: center;
|
|
168
170
|
text-align: center;
|
|
169
171
|
}
|
|
170
172
|
section.intro-title .section-content {
|
|
@@ -179,7 +181,7 @@ section.intro .section-content {
|
|
|
179
181
|
}
|
|
180
182
|
section.intro {
|
|
181
183
|
width: auto;
|
|
182
|
-
flex:
|
|
184
|
+
flex: none;
|
|
183
185
|
justify-content: flex-start;
|
|
184
186
|
align-items: center;
|
|
185
187
|
}
|
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@ import { getLocation } from "../getLocation";
|
|
|
6
6
|
import { buildNav } from "./buildNav";
|
|
7
7
|
import { getInstallationCode } from "./getInstallationCode";
|
|
8
8
|
import { getSectionPostprocess } from "./getSectionPostprocess";
|
|
9
|
+
import { isBadgeContainer } from "./isBadgeContainer";
|
|
9
10
|
import { joinLines } from "./joinLines";
|
|
10
|
-
import { postprocessBadges } from "./postprocessBadges";
|
|
11
11
|
import { preprocessContent } from "./preprocessContent";
|
|
12
12
|
|
|
13
13
|
const md = new Markdown({
|
|
@@ -24,7 +24,7 @@ export async function getParsedContent(ctx: Context) {
|
|
|
24
24
|
|
|
25
25
|
let { nav, linkMap: navLinkMap } = buildNav(ctx, dom);
|
|
26
26
|
|
|
27
|
-
let badges
|
|
27
|
+
let badges = "";
|
|
28
28
|
let title = "";
|
|
29
29
|
let description: string[] = [];
|
|
30
30
|
let descriptionNote: string[] = [];
|
|
@@ -36,49 +36,49 @@ export async function getParsedContent(ctx: Context) {
|
|
|
36
36
|
let section: string[] = [];
|
|
37
37
|
let sections: string[] = [];
|
|
38
38
|
|
|
39
|
-
let hasTitle = false;
|
|
40
39
|
let hasFeatures = false;
|
|
41
40
|
let indexComplete = false;
|
|
42
41
|
|
|
43
|
-
let element
|
|
42
|
+
for (let element of dom.window.document.body.children) {
|
|
43
|
+
if (isBadgeContainer(element)) {
|
|
44
|
+
badges = element.outerHTML;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (element.matches("h1")) {
|
|
49
|
+
title = element.innerHTML;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
44
52
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
else {
|
|
48
|
-
if (element.matches("h2")) {
|
|
49
|
-
if (!indexComplete) indexComplete = true;
|
|
53
|
+
if (element.matches("h2")) {
|
|
54
|
+
if (!indexComplete) indexComplete = true;
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
56
|
+
if (!singlePage && section.length !== 0) {
|
|
57
|
+
sections.push(joinLines(section));
|
|
58
|
+
section = [];
|
|
55
59
|
}
|
|
60
|
+
}
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
hasFeatures = true;
|
|
65
|
-
features.push(outerHTML);
|
|
66
|
-
} else {
|
|
67
|
-
let installationCode = getInstallationCode(element);
|
|
68
|
-
|
|
69
|
-
if (installationCode) installation = installationCode;
|
|
70
|
-
else if (description.length === 0) description.push(outerHTML);
|
|
71
|
-
else intro.push(outerHTML);
|
|
72
|
-
}
|
|
62
|
+
let { outerHTML } = element;
|
|
63
|
+
|
|
64
|
+
if (indexComplete) section.push(outerHTML);
|
|
65
|
+
else if (!hasFeatures) {
|
|
66
|
+
if (element.matches("ul")) {
|
|
67
|
+
hasFeatures = true;
|
|
68
|
+
features.push(outerHTML);
|
|
73
69
|
} else {
|
|
74
70
|
let installationCode = getInstallationCode(element);
|
|
75
71
|
|
|
76
72
|
if (installationCode) installation = installationCode;
|
|
77
|
-
else
|
|
73
|
+
else if (description.length === 0) description.push(outerHTML);
|
|
74
|
+
else intro.push(outerHTML);
|
|
78
75
|
}
|
|
79
|
-
}
|
|
76
|
+
} else {
|
|
77
|
+
let installationCode = getInstallationCode(element);
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
if (installationCode) installation = installationCode;
|
|
80
|
+
else note.push(outerHTML);
|
|
81
|
+
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
if (section.length !== 0) sections.push(joinLines(section));
|
|
@@ -119,7 +119,7 @@ export async function getParsedContent(ctx: Context) {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
return {
|
|
122
|
-
badges
|
|
122
|
+
badges, // postprocessBadges(joinLines(badges)),
|
|
123
123
|
title,
|
|
124
124
|
description: joinLines(description),
|
|
125
125
|
descriptionNote: joinLines(descriptionNote),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
let badgeImageSelector =
|
|
2
|
+
'img[src^="https://img.shields.io/"], img[src^="https://flat.badgen.net/"]';
|
|
3
|
+
|
|
4
|
+
export function isBadgeContainer(element: Element) {
|
|
5
|
+
if (!element.matches("p") || element.children.length === 0) return false;
|
|
6
|
+
|
|
7
|
+
for (let e of element.children) {
|
|
8
|
+
if (
|
|
9
|
+
!e.matches(badgeImageSelector) &&
|
|
10
|
+
(!e.matches("a") ||
|
|
11
|
+
e.children.length !== 1 ||
|
|
12
|
+
!e.children[0]?.matches(badgeImageSelector))
|
|
13
|
+
)
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return true;
|
|
18
|
+
}
|
package/src/css/index.css
CHANGED
|
@@ -163,8 +163,10 @@ section.intro .section-content {
|
|
|
163
163
|
padding: 1rem var(--content-padding-x);
|
|
164
164
|
}
|
|
165
165
|
section.intro-title {
|
|
166
|
+
flex: auto;
|
|
166
167
|
width: auto;
|
|
167
168
|
align-items: center;
|
|
169
|
+
justify-content: center;
|
|
168
170
|
text-align: center;
|
|
169
171
|
}
|
|
170
172
|
section.intro-title .section-content {
|
|
@@ -179,7 +181,7 @@ section.intro .section-content {
|
|
|
179
181
|
}
|
|
180
182
|
section.intro {
|
|
181
183
|
width: auto;
|
|
182
|
-
flex:
|
|
184
|
+
flex: none;
|
|
183
185
|
justify-content: flex-start;
|
|
184
186
|
align-items: center;
|
|
185
187
|
}
|