@t8/docsgen 0.1.11 → 0.1.13

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
@@ -299,7 +299,7 @@ async function getNav(ctx, navItems) {
299
299
  if (navItems.length > 1) {
300
300
  for (let { id, title, items } of navItems) {
301
301
  s += `
302
- <li data-id="${id}"><a href="${root}${contentDir}/${id}">${title}</a></li>`;
302
+ <li data-id="${id}"><a href="${root}${contentDir}/${id}">${title}</a>`;
303
303
  if (items.length !== 0) {
304
304
  s += "\n <ul>";
305
305
  for (let { title: title2 } of items) s += `
@@ -413,6 +413,18 @@ function getSectionPostprocess(linkMap) {
413
413
  return s;
414
414
  };
415
415
  }
416
+ function postprocessBadges(content) {
417
+ let { document } = new import_jsdom2.JSDOM(content).window;
418
+ for (let img of document.querySelectorAll("img")) {
419
+ let parent = img.parentElement;
420
+ if (!parent) continue;
421
+ let container = document.createElement("span");
422
+ container.className = "badge";
423
+ parent.insertBefore(container, img);
424
+ container.append(img);
425
+ }
426
+ return document.body.innerHTML;
427
+ }
416
428
  async function getParsedContent(ctx) {
417
429
  let { singlePage } = ctx;
418
430
  let rawContent = await fetchText(getLocation(ctx, "README.md", ctx.source));
@@ -465,7 +477,7 @@ async function getParsedContent(ctx) {
465
477
  if (section.length !== 0) sections.push(joinLines(section));
466
478
  let postprocess = getSectionPostprocess(linkMap);
467
479
  return {
468
- badges: joinLines(badges),
480
+ badges: postprocessBadges(joinLines(badges)),
469
481
  title,
470
482
  description: joinLines(description),
471
483
  features: joinLines(features),
@@ -599,9 +611,9 @@ ${content}
599
611
  ${navContent ? "<hr>" : ""}
600
612
  ${navContent.replace(
601
613
  new RegExp(
602
- `(<li data-id="${escapeRegExp(nav[i]?.id)}">)<a href="[^"]+">([^<]+)</a>(</li>)`
614
+ `(<li data-id="${escapeRegExp(nav[i]?.id)}">)<a href="[^"]+">([^<]+)</a>`
603
615
  ),
604
- "$1<strong>$2</strong>$3"
616
+ "$1<strong>$2</strong>"
605
617
  )}
606
618
  </div>
607
619
  </div>
package/dist/css/base.css CHANGED
@@ -227,3 +227,23 @@ html.blank .layout {
227
227
  justify-content: center;
228
228
  overflow: hidden;
229
229
  }
230
+
231
+ .badges .badge {
232
+ display: inline-flex;
233
+ min-width: 60px;
234
+ min-height: 20px;
235
+ font-size: 11px;
236
+ font-family: Verdana, sans-serif;
237
+ text-align: center;
238
+ white-space: nowrap;
239
+ place-content: center;
240
+ color: #fff;
241
+ background: #345;
242
+ box-sizing: border-box;
243
+ }
244
+ .badges img {
245
+ vertical-align: top;
246
+ }
247
+ .badges a {
248
+ text-decoration: none;
249
+ }
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "@t8/docsgen",
3
- "version": "0.1.11",
4
- "description": "",
5
- "main": "dist/bin.js",
6
- "bin": {
7
- "docsgen": "dist/bin.js"
8
- },
9
- "scripts": {
10
- "build": "npx npm-run-all clean build-bin -s build-css",
11
- "build-bin": "npx esbuild ./src/bin/run.ts --bundle --outfile=dist/bin.js --platform=node --external:jsdom --external:markdown-it",
12
- "build-css": "node -e \"require('node:fs').cpSync('src/css', 'dist/css', { force: true, recursive: true });\"",
13
- "clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
14
- "prepublishOnly": "npm run build",
15
- "preversion": "npx npm-run-all typecheck shape build",
16
- "shape": "npx codeshape",
17
- "typecheck": "tsc --noEmit"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/t8js/docsgen.git"
22
- },
23
- "license": "ISC",
24
- "author": "axtk",
25
- "devDependencies": {
26
- "@types/jsdom": "^27.0.0",
27
- "@types/markdown-it": "^14.1.2",
28
- "@types/node": "^24.7.0",
29
- "typescript": "^5.9.3"
30
- },
31
- "dependencies": {
32
- "args-json": "^1.2.4",
33
- "jsdom": "^27.0.0",
34
- "markdown-it": "^14.1.0"
35
- }
36
- }
1
+ {
2
+ "name": "@t8/docsgen",
3
+ "version": "0.1.13",
4
+ "description": "",
5
+ "main": "dist/bin.js",
6
+ "bin": {
7
+ "docsgen": "dist/bin.js"
8
+ },
9
+ "scripts": {
10
+ "build": "npx npm-run-all clean build-bin -s build-css",
11
+ "build-bin": "npx esbuild ./src/bin/run.ts --bundle --outfile=dist/bin.js --platform=node --external:jsdom --external:markdown-it",
12
+ "build-css": "node -e \"require('node:fs').cpSync('src/css', 'dist/css', { force: true, recursive: true });\"",
13
+ "clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
14
+ "prepublishOnly": "npm run build",
15
+ "preversion": "npx npm-run-all typecheck shape build",
16
+ "shape": "npx codeshape",
17
+ "typecheck": "tsc --noEmit"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/t8js/docsgen.git"
22
+ },
23
+ "license": "ISC",
24
+ "author": "axtk",
25
+ "devDependencies": {
26
+ "@types/jsdom": "^27.0.0",
27
+ "@types/markdown-it": "^14.1.2",
28
+ "@types/node": "^24.7.0",
29
+ "typescript": "^5.9.3"
30
+ },
31
+ "dependencies": {
32
+ "args-json": "^1.2.4",
33
+ "jsdom": "^27.0.0",
34
+ "markdown-it": "^14.1.0"
35
+ }
36
+ }
package/src/bin/getNav.ts CHANGED
@@ -32,7 +32,7 @@ export async function getNav(ctx: Context, navItems: NavItem[]) {
32
32
 
33
33
  if (navItems.length > 1) {
34
34
  for (let { id, title, items } of navItems) {
35
- s += `\n<li data-id="${id}"><a href="${root}${contentDir}/${id}">${title}</a></li>`;
35
+ s += `\n<li data-id="${id}"><a href="${root}${contentDir}/${id}">${title}</a>`;
36
36
 
37
37
  if (items.length !== 0) {
38
38
  s += "\n <ul>";
@@ -103,6 +103,24 @@ function getSectionPostprocess(linkMap: Record<string, string>) {
103
103
  };
104
104
  }
105
105
 
106
+ function postprocessBadges(content: string) {
107
+ let { document } = new JSDOM(content).window;
108
+
109
+ for (let img of document.querySelectorAll("img")) {
110
+ let parent = img.parentElement;
111
+
112
+ if (!parent) continue;
113
+
114
+ let container = document.createElement("span");
115
+ container.className = "badge";
116
+
117
+ parent.insertBefore(container, img);
118
+ container.append(img);
119
+ }
120
+
121
+ return document.body.innerHTML;
122
+ }
123
+
106
124
  export async function getParsedContent(ctx: Context) {
107
125
  let { singlePage } = ctx;
108
126
  let rawContent = await fetchText(getLocation(ctx, "README.md", ctx.source));
@@ -170,7 +188,7 @@ export async function getParsedContent(ctx: Context) {
170
188
  let postprocess = getSectionPostprocess(linkMap);
171
189
 
172
190
  return {
173
- badges: joinLines(badges),
191
+ badges: postprocessBadges(joinLines(badges)),
174
192
  title,
175
193
  description: joinLines(description),
176
194
  features: joinLines(features),
@@ -132,9 +132,9 @@ ${content}
132
132
  ${navContent ? "<hr>" : ""}
133
133
  ${navContent.replace(
134
134
  new RegExp(
135
- `(<li data-id="${escapeRegExp(nav[i]?.id)}">)<a href="[^"]+">([^<]+)</a>(</li>)`,
135
+ `(<li data-id="${escapeRegExp(nav[i]?.id)}">)<a href="[^"]+">([^<]+)</a>`,
136
136
  ),
137
- "$1<strong>$2</strong>$3",
137
+ "$1<strong>$2</strong>",
138
138
  )}
139
139
  </div>
140
140
  </div>
package/src/css/base.css CHANGED
@@ -227,3 +227,23 @@ html.blank .layout {
227
227
  justify-content: center;
228
228
  overflow: hidden;
229
229
  }
230
+
231
+ .badges .badge {
232
+ display: inline-flex;
233
+ min-width: 60px;
234
+ min-height: 20px;
235
+ font-size: 11px;
236
+ font-family: Verdana, sans-serif;
237
+ text-align: center;
238
+ white-space: nowrap;
239
+ place-content: center;
240
+ color: #fff;
241
+ background: #345;
242
+ box-sizing: border-box;
243
+ }
244
+ .badges img {
245
+ vertical-align: top;
246
+ }
247
+ .badges a {
248
+ text-decoration: none;
249
+ }