@dogsbay/format-html 0.2.0-beta.179 → 0.2.0-beta.181
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/core/fidelity.js +4 -0
- package/dist/core/inline.js +17 -1
- package/dist/site/book.d.ts +32 -5
- package/dist/site/book.js +239 -60
- package/dist/site/gitbook.d.ts +74 -0
- package/dist/site/gitbook.js +730 -0
- package/dist/site/index.d.ts +9 -4
- package/dist/site/index.js +11 -4
- package/dist/site/next-data.d.ts +25 -0
- package/dist/site/next-data.js +136 -0
- package/dist/site/sniff.d.ts +38 -0
- package/dist/site/sniff.js +57 -0
- package/dist/site/types.d.ts +50 -0
- package/package.json +8 -3
package/dist/site/index.d.ts
CHANGED
|
@@ -3,15 +3,20 @@
|
|
|
3
3
|
* adapters. Never fetches; the caller passes its fetch to importBook.
|
|
4
4
|
*/
|
|
5
5
|
import type { CheerioAPI } from "cheerio";
|
|
6
|
+
import { gitbook, gitbookSite, gitbookData, readGitbookText, countGitbook } from "./gitbook.js";
|
|
6
7
|
import { ibm } from "./ibm.js";
|
|
7
8
|
import { redhat } from "./redhat.js";
|
|
8
9
|
import type { SiteAdapter } from "./types.js";
|
|
10
|
+
/** Sites by their own domain first; GitBook (any domain, by its generator tag) last. */
|
|
9
11
|
export declare const SITES: SiteAdapter[];
|
|
10
12
|
export declare function siteByName(name: string): SiteAdapter | undefined;
|
|
13
|
+
/** The adapter for a page: an adapter for any site (GitBook) bound to the page's site, or none when it cannot be. */
|
|
11
14
|
export declare function detectSite($: CheerioAPI, url?: string): SiteAdapter | undefined;
|
|
12
|
-
export { redhat, ibm };
|
|
15
|
+
export { redhat, ibm, gitbook, gitbookSite, gitbookData, readGitbookText, countGitbook };
|
|
13
16
|
/** Every adapter's pages, as extension match patterns. */
|
|
14
17
|
export declare const SITE_MATCHES: string[];
|
|
15
|
-
export { importBook, planBook, findBook, navYaml } from "./book.js";
|
|
16
|
-
export type { ImportBookOptions, ImportBookResult, PageReport, BookPlan } from "./book.js";
|
|
17
|
-
export type { SiteAdapter, SitePageInfo, ContentsEntry } from "./types.js";
|
|
18
|
+
export { importBook, planBook, planScopes, findBook, navYaml } from "./book.js";
|
|
19
|
+
export type { ImportBookOptions, ImportBookResult, PageReport, BookPlan, ScopePlan, ScopeRung } from "./book.js";
|
|
20
|
+
export type { SiteAdapter, SitePageInfo, ContentsEntry, TextPage } from "./types.js";
|
|
21
|
+
export { identifyTool, pageFacts } from "./sniff.js";
|
|
22
|
+
export type { PageFacts, Tool, ToolId } from "./sniff.js";
|
package/dist/site/index.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
import { gitbook, gitbookSite, gitbookData, readGitbookText, countGitbook } from "./gitbook.js";
|
|
1
2
|
import { ibm } from "./ibm.js";
|
|
2
3
|
import { redhat } from "./redhat.js";
|
|
3
|
-
|
|
4
|
+
/** Sites by their own domain first; GitBook (any domain, by its generator tag) last. */
|
|
5
|
+
export const SITES = [redhat, ibm, gitbook];
|
|
4
6
|
export function siteByName(name) {
|
|
5
7
|
return SITES.find((s) => s.name === name);
|
|
6
8
|
}
|
|
9
|
+
/** The adapter for a page: an adapter for any site (GitBook) bound to the page's site, or none when it cannot be. */
|
|
7
10
|
export function detectSite($, url) {
|
|
8
|
-
|
|
11
|
+
const site = SITES.find((s) => s.detect($, url));
|
|
12
|
+
if (!site?.bind)
|
|
13
|
+
return site;
|
|
14
|
+
return site.bind($, url) ?? undefined;
|
|
9
15
|
}
|
|
10
|
-
export { redhat, ibm };
|
|
16
|
+
export { redhat, ibm, gitbook, gitbookSite, gitbookData, readGitbookText, countGitbook };
|
|
11
17
|
/** Every adapter's pages, as extension match patterns. */
|
|
12
18
|
export const SITE_MATCHES = [...new Set(SITES.flatMap((s) => s.matches))];
|
|
13
|
-
export { importBook, planBook, findBook, navYaml } from "./book.js";
|
|
19
|
+
export { importBook, planBook, planScopes, findBook, navYaml } from "./book.js";
|
|
20
|
+
export { identifyTool, pageFacts } from "./sniff.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Next.js page's streamed data (React Server Components): the `self.__next_f.push([1,"…"])`
|
|
3
|
+
* scripts joined into one stream of rows, `<hex id>:<payload>\n`. A payload is JSON, or a text
|
|
4
|
+
* row `T<hex byte length>,<text>` (long strings: GitHub Files' code), or another kind (`I[…]`,
|
|
5
|
+
* `HL[…]`) not read here. In JSON, a string `"$<id>"` or `"$<id>:a:b"` is a reference to a
|
|
6
|
+
* row (and a path in it), `"$$…"` is a string starting `$`, and the other `$` forms (`$L…`
|
|
7
|
+
* lazy components, `$undefined`, `$@…`) are no data. The page is someone else's: sizes, depth
|
|
8
|
+
* and references are capped, and nothing found is trusted as more than plain values.
|
|
9
|
+
*/
|
|
10
|
+
import type { CheerioAPI } from "cheerio";
|
|
11
|
+
/** The joined stream of the page's data scripts, or "" when it has none (or more than 16 MB). */
|
|
12
|
+
export declare function nextStream($: CheerioAPI): string;
|
|
13
|
+
export type Rows = Map<string, unknown>;
|
|
14
|
+
/** The stream's rows by id: JSON values and text rows (as strings). Text rows are measured in UTF-8 bytes. */
|
|
15
|
+
export declare function nextRows(stream: string): Rows;
|
|
16
|
+
/**
|
|
17
|
+
* A value with its references resolved (rows and paths in them), at most `budget` values
|
|
18
|
+
* visited in all (`budget.left` is shared by a caller resolving several), `MAX_DEPTH` deep. A
|
|
19
|
+
* reference being resolved is not followed again (a cycle gives undefined).
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveRefs(value: unknown, rows: Rows, budget: {
|
|
22
|
+
left: number;
|
|
23
|
+
}, depth?: number, active?: Set<string>): unknown;
|
|
24
|
+
/** Every object in the rows (not following references), depth first, at most `limit`. */
|
|
25
|
+
export declare function objectsIn(rows: Rows, limit?: number): Generator<Record<string, unknown>>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
const MAX_STREAM = 16 * 1024 * 1024;
|
|
2
|
+
/** The joined stream of the page's data scripts, or "" when it has none (or more than 16 MB). */
|
|
3
|
+
export function nextStream($) {
|
|
4
|
+
let stream = "";
|
|
5
|
+
for (const el of $("script").toArray()) {
|
|
6
|
+
const text = $(el).text();
|
|
7
|
+
const m = /^\s*self\.__next_f\.push\((\[[\s\S]*\])\)\s*;?\s*$/.exec(text);
|
|
8
|
+
if (!m)
|
|
9
|
+
continue;
|
|
10
|
+
try {
|
|
11
|
+
const row = JSON.parse(m[1]);
|
|
12
|
+
if (row[0] === 1 && typeof row[1] === "string")
|
|
13
|
+
stream += row[1];
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// not a data row
|
|
17
|
+
}
|
|
18
|
+
if (stream.length > MAX_STREAM)
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
return stream;
|
|
22
|
+
}
|
|
23
|
+
/** The stream's rows by id: JSON values and text rows (as strings). Text rows are measured in UTF-8 bytes. */
|
|
24
|
+
export function nextRows(stream) {
|
|
25
|
+
const bytes = new TextEncoder().encode(stream);
|
|
26
|
+
const decode = new TextDecoder();
|
|
27
|
+
const rows = new Map();
|
|
28
|
+
const HEX = (c) => (c >= 0x30 && c <= 0x39) || (c >= 0x61 && c <= 0x66);
|
|
29
|
+
// Linear: every search moves `p` past what it scanned (a newline searched for from each text
|
|
30
|
+
// row, which ends without one, rescanned the stream: quadratic, review 2026-11-19)
|
|
31
|
+
const skipLine = (from) => {
|
|
32
|
+
const nl = bytes.indexOf(0x0a, from);
|
|
33
|
+
return nl < 0 ? bytes.length : nl + 1;
|
|
34
|
+
};
|
|
35
|
+
let p = 0;
|
|
36
|
+
while (p < bytes.length) {
|
|
37
|
+
let q = p;
|
|
38
|
+
while (q < bytes.length && q - p <= 8 && HEX(bytes[q]))
|
|
39
|
+
q++;
|
|
40
|
+
if (q === p || q - p > 8 || bytes[q] !== 0x3a /* : */) {
|
|
41
|
+
p = skipLine(p);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const id = decode.decode(bytes.subarray(p, q));
|
|
45
|
+
const colon = q;
|
|
46
|
+
if (bytes[colon + 1] === 0x54 /* T */) {
|
|
47
|
+
let comma = colon + 2;
|
|
48
|
+
while (comma < bytes.length && comma - colon < 12 && HEX(bytes[comma]))
|
|
49
|
+
comma++;
|
|
50
|
+
if (bytes[comma] !== 0x2c /* , */) {
|
|
51
|
+
p = skipLine(colon);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const len = parseInt(decode.decode(bytes.subarray(colon + 2, comma)), 16);
|
|
55
|
+
if (!Number.isFinite(len) || comma + 1 + len > bytes.length)
|
|
56
|
+
break;
|
|
57
|
+
rows.set(id, decode.decode(bytes.subarray(comma + 1, comma + 1 + len)));
|
|
58
|
+
p = comma + 1 + len;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const next = skipLine(colon);
|
|
62
|
+
const raw = decode.decode(bytes.subarray(colon + 1, next > colon + 1 && bytes[next - 1] === 0x0a ? next - 1 : next));
|
|
63
|
+
if (/^[[{"]/.test(raw)) {
|
|
64
|
+
try {
|
|
65
|
+
rows.set(id, JSON.parse(raw));
|
|
66
|
+
}
|
|
67
|
+
catch { /* not JSON: skipped */ }
|
|
68
|
+
}
|
|
69
|
+
p = next;
|
|
70
|
+
}
|
|
71
|
+
return rows;
|
|
72
|
+
}
|
|
73
|
+
const MAX_DEPTH = 64;
|
|
74
|
+
/**
|
|
75
|
+
* A value with its references resolved (rows and paths in them), at most `budget` values
|
|
76
|
+
* visited in all (`budget.left` is shared by a caller resolving several), `MAX_DEPTH` deep. A
|
|
77
|
+
* reference being resolved is not followed again (a cycle gives undefined).
|
|
78
|
+
*/
|
|
79
|
+
export function resolveRefs(value, rows, budget, depth = 0, active = new Set()) {
|
|
80
|
+
if (--budget.left < 0 || depth > MAX_DEPTH)
|
|
81
|
+
return undefined;
|
|
82
|
+
if (typeof value === "string") {
|
|
83
|
+
if (!value.startsWith("$"))
|
|
84
|
+
return value;
|
|
85
|
+
if (value.startsWith("$$"))
|
|
86
|
+
return value.slice(1);
|
|
87
|
+
const m = /^\$([0-9a-f]{1,8})((?::[^:]+)*)$/.exec(value);
|
|
88
|
+
if (!m || active.has(value))
|
|
89
|
+
return undefined;
|
|
90
|
+
let target = rows.get(m[1]);
|
|
91
|
+
for (const seg of m[2] ? m[2].slice(1).split(":") : []) {
|
|
92
|
+
// a path may run through references of its own
|
|
93
|
+
if (typeof target === "string" && target.startsWith("$")) {
|
|
94
|
+
active.add(value);
|
|
95
|
+
target = resolveRefs(target, rows, budget, depth + 1, active);
|
|
96
|
+
active.delete(value);
|
|
97
|
+
}
|
|
98
|
+
target = target !== null && typeof target === "object" && Object.prototype.hasOwnProperty.call(target, seg) ? target[seg] : undefined;
|
|
99
|
+
}
|
|
100
|
+
active.add(value);
|
|
101
|
+
const out = resolveRefs(target, rows, budget, depth + 1, active);
|
|
102
|
+
active.delete(value);
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
if (Array.isArray(value))
|
|
106
|
+
return value.map((v) => resolveRefs(v, rows, budget, depth + 1, active));
|
|
107
|
+
if (value !== null && typeof value === "object") {
|
|
108
|
+
const out = Object.create(null);
|
|
109
|
+
for (const [k, v] of Object.entries(value)) {
|
|
110
|
+
if (k === "__proto__")
|
|
111
|
+
continue;
|
|
112
|
+
out[k] = resolveRefs(v, rows, budget, depth + 1, active);
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
/** Every object in the rows (not following references), depth first, at most `limit`. */
|
|
119
|
+
export function* objectsIn(rows, limit = 1_000_000) {
|
|
120
|
+
let left = limit;
|
|
121
|
+
const stack = [...rows.values()].reverse();
|
|
122
|
+
while (stack.length && left-- > 0) {
|
|
123
|
+
const v = stack.pop();
|
|
124
|
+
if (Array.isArray(v)) {
|
|
125
|
+
for (let k = v.length - 1; k >= 0; k--)
|
|
126
|
+
stack.push(v[k]);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (v === null || typeof v !== "object")
|
|
130
|
+
continue;
|
|
131
|
+
yield v;
|
|
132
|
+
const vals = Object.values(v);
|
|
133
|
+
for (let k = vals.length - 1; k >= 0; k--)
|
|
134
|
+
stack.push(vals[k]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which documentation tool made a page, from what the page says about itself: its
|
|
3
|
+
* `generator` meta tags, a published Markdown version (`<link rel="alternate"
|
|
4
|
+
* type="text/markdown">`) and Sphinx's markers (Sphinx writes no generator tag). Read,
|
|
5
|
+
* never fetched; nothing on the page is changed.
|
|
6
|
+
*
|
|
7
|
+
* Two readers give the same facts: `pageFacts` (cheerio, the CLI and tests) and the
|
|
8
|
+
* extension's own DOM function (apps/import-extension/src/sniff.ts, which Chrome runs in
|
|
9
|
+
* the tab and so cannot import this module). Keep them in step.
|
|
10
|
+
*
|
|
11
|
+
* Checked on the tools' own sites 2026-11-18: GitBook, Docusaurus, VitePress, Starlight
|
|
12
|
+
* (beside an Astro tag), Astro, MkDocs Material, Hugo, Mintlify, Jekyll by its documented
|
|
13
|
+
* tag, Sphinx by its footer and `_static/documentation_options.js`, DITA-OT by its generator tag
|
|
14
|
+
* or its HTML5 classes (the dita-ot-html5 profile's markers).
|
|
15
|
+
*/
|
|
16
|
+
import type { CheerioAPI } from "cheerio";
|
|
17
|
+
/** What a page says about the tool that made it. */
|
|
18
|
+
export interface PageFacts {
|
|
19
|
+
/** Every `<meta name="generator">` content, in order (Starlight writes Astro's and its own). */
|
|
20
|
+
generators: string[];
|
|
21
|
+
/** The page's Markdown version, from `<link rel="alternate" type="text/markdown">`. */
|
|
22
|
+
markdown?: string;
|
|
23
|
+
/** Sphinx's markers: "Created using Sphinx" in the footer, or its `_static/documentation_options.js`. */
|
|
24
|
+
sphinx?: boolean;
|
|
25
|
+
/** DITA-OT's HTML5 markers, for builds without its generator tag: `h1.topictitle1`, a `div.body` of a topic type. */
|
|
26
|
+
dita?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export type ToolId = "gitbook" | "docusaurus" | "vitepress" | "starlight" | "mkdocs" | "hugo" | "mintlify" | "jekyll" | "sphinx" | "astro" | "dita-ot";
|
|
29
|
+
export interface Tool {
|
|
30
|
+
id: ToolId;
|
|
31
|
+
/** The tool's name as people know it ("MkDocs Material"). */
|
|
32
|
+
label: string;
|
|
33
|
+
version?: string;
|
|
34
|
+
}
|
|
35
|
+
/** The tool that made a page, or undefined when it does not say. */
|
|
36
|
+
export declare function identifyTool(facts: PageFacts): Tool | undefined;
|
|
37
|
+
/** The facts, from a page parsed with cheerio. */
|
|
38
|
+
export declare function pageFacts($: CheerioAPI, url?: string): PageFacts;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Generator tags, most specific first: Starlight before the Astro tag it sits beside. */
|
|
2
|
+
const GENERATORS = [
|
|
3
|
+
{ id: "gitbook", label: "GitBook", pattern: /^GitBook\b/i },
|
|
4
|
+
{ id: "docusaurus", label: "Docusaurus", pattern: /^Docusaurus\b/i },
|
|
5
|
+
{ id: "vitepress", label: "VitePress", pattern: /^VitePress\b/i },
|
|
6
|
+
{ id: "starlight", label: "Starlight", pattern: /^Starlight\b/i },
|
|
7
|
+
{ id: "mintlify", label: "Mintlify", pattern: /^Mintlify\b/i },
|
|
8
|
+
{ id: "mkdocs", label: "MkDocs", pattern: /^mkdocs\b/i },
|
|
9
|
+
{ id: "hugo", label: "Hugo", pattern: /^Hugo\b/i },
|
|
10
|
+
{ id: "jekyll", label: "Jekyll", pattern: /^Jekyll\b/i },
|
|
11
|
+
{ id: "astro", label: "Astro", pattern: /^Astro\b/i },
|
|
12
|
+
{ id: "dita-ot", label: "DITA-OT", pattern: /^DITA-OT\b/i },
|
|
13
|
+
];
|
|
14
|
+
/** The tool that made a page, or undefined when it does not say. */
|
|
15
|
+
export function identifyTool(facts) {
|
|
16
|
+
const generators = facts.generators.map((g) => g.trim()).filter(Boolean);
|
|
17
|
+
for (const g of GENERATORS) {
|
|
18
|
+
const tag = generators.find((t) => g.pattern.test(t));
|
|
19
|
+
if (!tag)
|
|
20
|
+
continue;
|
|
21
|
+
// MkDocs writes "mkdocs-1.6.1, mkdocs-material-9.8.1": the theme is what people name
|
|
22
|
+
if (g.id === "mkdocs") {
|
|
23
|
+
const material = /mkdocs-material-([\w.-]+)/i.exec(tag);
|
|
24
|
+
return material ? { id: "mkdocs", label: "MkDocs Material", version: material[1] } : { id: "mkdocs", label: "MkDocs", version: /mkdocs-([\d][\w.-]*)/i.exec(tag)?.[1] };
|
|
25
|
+
}
|
|
26
|
+
return { id: g.id, label: g.label, version: versionIn(tag.replace(g.pattern, "")) };
|
|
27
|
+
}
|
|
28
|
+
if (facts.sphinx)
|
|
29
|
+
return { id: "sphinx", label: "Sphinx" };
|
|
30
|
+
if (facts.dita)
|
|
31
|
+
return { id: "dita-ot", label: "DITA-OT" };
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
/** "v4.0.0", " (7ad3fff)", " 0.170.1" → the version; nothing that is not one. */
|
|
35
|
+
function versionIn(rest) {
|
|
36
|
+
return /^\s*\(?v?([\da-f][\w.-]*)\)?\s*$/i.exec(rest)?.[1];
|
|
37
|
+
}
|
|
38
|
+
/** DITA-OT HTML5's own markers (the dita-ot-html5 profile detects by the same). */
|
|
39
|
+
const DITA_MARKERS = "h1.topictitle1, div.body.conbody, div.body.taskbody, div.body.refbody, div.body.glossbody, div.body.troublebody";
|
|
40
|
+
/** The facts, from a page parsed with cheerio. */
|
|
41
|
+
export function pageFacts($, url) {
|
|
42
|
+
const generators = $('meta[name="generator" i]').map((_, e) => $(e).attr("content") ?? "").get().filter(Boolean);
|
|
43
|
+
const href = $('link[rel~="alternate" i][type="text/markdown" i]').first().attr("href");
|
|
44
|
+
let markdown;
|
|
45
|
+
if (href) {
|
|
46
|
+
try {
|
|
47
|
+
markdown = url ? new URL(href, url).href : href;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
markdown = undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const sphinx = $('script[src*="_static/documentation_options.js"]').length > 0 ||
|
|
54
|
+
$("footer, div.footer").toArray().some((e) => /Created using\s+Sphinx/i.test($(e).text()));
|
|
55
|
+
const dita = $(DITA_MARKERS).length > 0;
|
|
56
|
+
return { generators, ...(markdown ? { markdown } : {}), ...(sphinx ? { sphinx } : {}), ...(dita ? { dita } : {}) };
|
|
57
|
+
}
|
package/dist/site/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { CheerioAPI } from "cheerio";
|
|
2
|
+
import type { TreeNode } from "@dogsbay/types";
|
|
3
|
+
import type { Counts } from "../core/fidelity.js";
|
|
2
4
|
/**
|
|
3
5
|
* One entry of a site's table of contents. `key` identifies a page (see
|
|
4
6
|
* SiteAdapter.keyOf); a section heading with no page of its own has none.
|
|
@@ -13,8 +15,28 @@ export interface ContentsEntry {
|
|
|
13
15
|
* `?topic=<name>`), so a page read at one is found in the contents.
|
|
14
16
|
*/
|
|
15
17
|
aliases?: string[];
|
|
18
|
+
/** Where to fetch the page, when the contents say (GitBook: the page's `.md`, which only the site's data names for a space's first page). */
|
|
19
|
+
fetchUrl?: string;
|
|
16
20
|
children: ContentsEntry[];
|
|
17
21
|
}
|
|
22
|
+
/** A page read from the site's own text (`SiteAdapter.readText`), not from its HTML. */
|
|
23
|
+
export interface TextPage {
|
|
24
|
+
tree: TreeNode[];
|
|
25
|
+
title?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
/** The topic type for front matter (default `topic`). */
|
|
28
|
+
type?: string;
|
|
29
|
+
/** What the text holds (headings, code blocks, tables…), against which the tree is counted. */
|
|
30
|
+
source: Counts;
|
|
31
|
+
/**
|
|
32
|
+
* Data files the page's directives show (`data/<name>.json`), by name: records an integration
|
|
33
|
+
* block held. `links`: the fields holding a link (a site path), settled as the page's links are.
|
|
34
|
+
*/
|
|
35
|
+
data?: Record<string, {
|
|
36
|
+
rows: Array<Record<string, string | number | boolean>>;
|
|
37
|
+
links: string[];
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
18
40
|
/** What a site adapter learns from one page, after preparing it. */
|
|
19
41
|
export interface SitePageInfo {
|
|
20
42
|
/** The page's identity; the same key keyOf gives its URL. */
|
|
@@ -73,4 +95,32 @@ export interface SiteAdapter {
|
|
|
73
95
|
url: string;
|
|
74
96
|
notice: string;
|
|
75
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* Pages read as text, not HTML: a site that publishes each page's source (GitBook's `.md`).
|
|
100
|
+
* Given the text fetched from the entry's `fetchUrl` (else `fetchUrlOf`, else `urlOf`), the
|
|
101
|
+
* page, or null when the text is not one (a soft 404). Links and images as written (absolute,
|
|
102
|
+
* or relative to `page.url`); importBook settles them. The start page is fetched too: its HTML
|
|
103
|
+
* only says which page it is.
|
|
104
|
+
*/
|
|
105
|
+
readText?(text: string, page: {
|
|
106
|
+
key: string;
|
|
107
|
+
url: string;
|
|
108
|
+
}, html?: string): TextPage | null;
|
|
109
|
+
/**
|
|
110
|
+
* Whether this page's text needs its HTML too (GitBook: an integration block whose content
|
|
111
|
+
* only the published page holds). importBook then fetches `urlOf(key)` (the start page's is in
|
|
112
|
+
* hand) and gives it to `readText`.
|
|
113
|
+
*/
|
|
114
|
+
pageFor?(text: string): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Images on a host other than the site's own that a book keeps (GitBook's file host, which
|
|
117
|
+
* lets any site read it). Fetched without the reader's cookies, as any cross-site request.
|
|
118
|
+
*/
|
|
119
|
+
imageHost?(url: URL): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* An adapter for any site (GitBook on its own domain) has no origin of its own: the one bound
|
|
122
|
+
* to this page's site and space, or null when the page does not say enough. `detectSite`
|
|
123
|
+
* returns the bound adapter.
|
|
124
|
+
*/
|
|
125
|
+
bind?($: CheerioAPI, url?: string): SiteAdapter | null;
|
|
76
126
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dogsbay/format-html",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.181",
|
|
4
4
|
"description": "HTML importer for Dogsbay: semantic HTML to TreeNode[], generator profiles (DITA-OT HTML5 first), site adapters (docs.redhat.com first) and a per-page fidelity report. Never fetches; runs in Node, browsers and Workers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"./site": {
|
|
14
14
|
"types": "./dist/site/index.d.ts",
|
|
15
15
|
"import": "./dist/site/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./site/sniff": {
|
|
18
|
+
"types": "./dist/site/sniff.d.ts",
|
|
19
|
+
"import": "./dist/site/sniff.js"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"files": [
|
|
@@ -26,8 +30,9 @@
|
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
28
32
|
"cheerio": "^1.2.0",
|
|
29
|
-
"@dogsbay/
|
|
30
|
-
"@dogsbay/
|
|
33
|
+
"@dogsbay/format-dogsbay-md": "0.2.0-beta.181",
|
|
34
|
+
"@dogsbay/types": "0.2.0-beta.181",
|
|
35
|
+
"@dogsbay/format-gitbook": "0.2.0-beta.181"
|
|
31
36
|
},
|
|
32
37
|
"license": "MIT",
|
|
33
38
|
"repository": {
|