@dogsbay/format-html 0.0.0-stage → 0.2.0-beta.180

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.
@@ -0,0 +1,74 @@
1
+ /**
2
+ * GitBook published sites, on any domain (developer.harness.io, gitbook.com/docs). One book
3
+ * is one GitBook **space** (owner, 2026-11-18): the space the reader is on.
4
+ *
5
+ * Measured 2026-11-18 (plans/import-extension-sniffing.md, docs-dev/format-html.md):
6
+ * - Pages are read from their `.md`, not their HTML: the `.md` is GitBook's document written
7
+ * out again, every tag and word of the Git Sync source (checked against GitbookIO/public-docs),
8
+ * which @dogsbay/format-gitbook translates. The HTML lacks Mermaid source, code languages and
9
+ * the API pages' OpenAPI specs, and streams half its content (Next.js `$RC` moves).
10
+ * - The contents come from the start page's own data: Next.js puts the sidebar's whole tree
11
+ * (`"pages":[…]`: id, title, href, pathnames, groups with `descendants`) in the page's
12
+ * `self.__next_f.push(…)` scripts; the server's HTML draws only part of it. `llms.txt` is flat
13
+ * (one `##` per site section, spaces mixed) and not used.
14
+ * - A space's first page has two pathnames (`""` and its slug): its `.md` is `<space>/<slug>.md`;
15
+ * `<space>.md` is a "Page Not Found" Markdown page with status 200 (a soft 404).
16
+ * - Each `.md` starts with a "For the complete documentation index" banner and ends with an
17
+ * appended `# Agent Instructions` section: both are GitBook's, not the page's.
18
+ * - Card links are `{% content-ref url="/pages/<id>" %}`: the id is in the tree, kept as an alias.
19
+ * - Images are on `<n>-files.gitbook.io`, which answers any origin (`Access-Control-Allow-Origin: *`);
20
+ * GitBook's own `/~gitbook/image` proxy needs a signature we cannot make.
21
+ *
22
+ * Detected by `<meta name="generator" content="GitBook …">`; `bind` makes the adapter of the
23
+ * page's site and space. Reads, never fetches.
24
+ */
25
+ import { type CheerioAPI } from "cheerio";
26
+ import { type PageIntegration } from "@dogsbay/format-gitbook";
27
+ import type { Counts } from "../core/fidelity.js";
28
+ import type { SiteAdapter, TextPage } from "./types.js";
29
+ /** One entry of GitBook's page tree, as its page data writes it. */
30
+ interface GbPage {
31
+ id: string;
32
+ title: string;
33
+ href?: string;
34
+ pathnames?: string[];
35
+ type: string;
36
+ descendants?: GbPage[];
37
+ }
38
+ /** What a GitBook page's data says about its space. */
39
+ export interface GitbookData {
40
+ pages: GbPage[];
41
+ /** The space's title (the book's). */
42
+ title?: string;
43
+ /** The space's published address (`https://site/space/`). */
44
+ published?: string;
45
+ }
46
+ /**
47
+ * The space's page tree and facts, from the page's Next.js data (`self.__next_f.push([1,"…"])`
48
+ * scripts, each a JSON string; together one stream). Null when the page has none.
49
+ */
50
+ export declare function gitbookData($: CheerioAPI): GitbookData | null;
51
+ /** The adapter of one GitBook site and space, from a page of it. */
52
+ export declare function gitbookSite(origin: string, data: GitbookData): SiteAdapter;
53
+ /** The adapter every GitBook site gets bound from: detects, then `bind`s to the page's site. */
54
+ export declare const gitbook: SiteAdapter;
55
+ /**
56
+ * The integration blocks a published GitBook page's data holds (plans/gitbook-integrations.md):
57
+ * each object with `renderContext.integrationName` and `initialInput`, its input props and its
58
+ * ContentKit element (`initialOutput.element`), references resolved. In the data's order, which
59
+ * is not the page's: format-gitbook matches them by props.
60
+ */
61
+ export declare function gitbookIntegrations($: CheerioAPI): PageIntegration[];
62
+ /**
63
+ * A page's `.md` as a tree, or null when it is GitBook's "Page Not Found". With its published
64
+ * page's integration blocks (`gitbookIntegrations`), its own are filled from them.
65
+ */
66
+ export declare function readGitbookText(text: string, pageIntegrations?: PageIntegration[]): TextPage | null;
67
+ /**
68
+ * What a GitBook page's text holds, counted from the text (outside code), for the fidelity
69
+ * report: headings, code blocks, tables, list items, images, callouts (hints), links. Every scan
70
+ * is linear (the text is someone else's: a backtracking pattern over `<a href="x" ` repeated took
71
+ * minutes, review 2026-11-18).
72
+ */
73
+ export declare function countGitbook(text: string): Counts;
74
+ export {};