@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,126 @@
1
+ import type { CheerioAPI } from "cheerio";
2
+ import type { TreeNode } from "@dogsbay/types";
3
+ import type { Counts } from "../core/fidelity.js";
4
+ /**
5
+ * One entry of a site's table of contents. `key` identifies a page (see
6
+ * SiteAdapter.keyOf); a section heading with no page of its own has none.
7
+ */
8
+ export interface ContentsEntry {
9
+ title: string;
10
+ key: string | null;
11
+ /** A fragment in the entry's link (`page#section`): the entry is part of a page. */
12
+ fragment?: string;
13
+ /**
14
+ * Other keys that name the same page: addresses that do not give the page's own (IBM's
15
+ * `?topic=<name>`), so a page read at one is found in the contents.
16
+ */
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;
20
+ children: ContentsEntry[];
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
+ }
40
+ /** What a site adapter learns from one page, after preparing it. */
41
+ export interface SitePageInfo {
42
+ /** The page's identity; the same key keyOf gives its URL. */
43
+ key: string;
44
+ /** The page's absolute URL (relative links resolve against it). */
45
+ url: string;
46
+ /** CSS selector of the content root, for htmlToTree. */
47
+ root: string;
48
+ /** Site facts (product, version, language…) for front matter and the config. */
49
+ meta: Record<string, string>;
50
+ /** When the site says the page last changed (ISO date): the page's `updated` front matter. */
51
+ updated?: string;
52
+ }
53
+ /**
54
+ * One documentation site: its chrome, its contents, its URLs, how slowly to
55
+ * fetch it, and its licence. Adapters never fetch.
56
+ */
57
+ export interface SiteAdapter {
58
+ name: string;
59
+ /** Is this page from this site? */
60
+ detect($: CheerioAPI, url?: string): boolean;
61
+ /** The generator profile its content is written in. */
62
+ profile: string;
63
+ /**
64
+ * Read the page's facts and prepare its content in place: remove the chrome,
65
+ * rewrite custom elements to plain HTML (callouts as `data-callout`). Null when
66
+ * the page is not one of the site's content pages.
67
+ */
68
+ readPage($: CheerioAPI, url?: string): SitePageInfo | null;
69
+ /**
70
+ * The site's table of contents: from the page itself when every page carries it, else
71
+ * from what `contentsUrl` names (importBook fetches it): `$` is that response parsed as
72
+ * HTML, `source` its text (for contents served as JSON).
73
+ */
74
+ readContents?($: CheerioAPI, page: SitePageInfo, source?: string): ContentsEntry[];
75
+ /** Where the contents are, for a site whose pages do not carry them (IBM's contents API). */
76
+ contentsUrl?(page: SitePageInfo): string | undefined;
77
+ /**
78
+ * Where to fetch a page's content, when not from its address (IBM: its content API, as
79
+ * IBM's own app does; the address gives browsers an app with no content in it). When set,
80
+ * the start page is fetched from here too: the page the reader is on only says which it is.
81
+ */
82
+ fetchUrlOf?(key: string): string;
83
+ /** A URL's page key, or null when the URL is not a content page of this site. */
84
+ keyOf(url: URL): string | null;
85
+ /** The URL to fetch a page by key. */
86
+ urlOf(key: string): string;
87
+ /** File name (no folder) for a page in a project. */
88
+ fileOf(key: string): string;
89
+ /** Extension match patterns for the site's pages (a browser extension's content scripts). */
90
+ matches: string[];
91
+ /** Wait at least this long between two fetches. */
92
+ delayMs: number;
93
+ licence?: {
94
+ name: string;
95
+ url: string;
96
+ notice: string;
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;
126
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@dogsbay/format-html",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0-beta.180",
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
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./site": {
14
+ "types": "./dist/site/index.d.ts",
15
+ "import": "./dist/site/index.js"
16
+ },
17
+ "./site/sniff": {
18
+ "types": "./dist/site/sniff.d.ts",
19
+ "import": "./dist/site/sniff.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md"
25
+ ],
26
+ "devDependencies": {
27
+ "@types/node": "^25.9.5",
28
+ "typescript": "^5.9.3",
29
+ "vitest": "^4.1.10"
30
+ },
31
+ "dependencies": {
32
+ "cheerio": "^1.2.0",
33
+ "@dogsbay/types": "0.2.0-beta.180",
34
+ "@dogsbay/format-dogsbay-md": "0.2.0-beta.180",
35
+ "@dogsbay/format-gitbook": "0.2.0-beta.180"
36
+ },
37
+ "license": "MIT",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/dogsbay/dogsbay.git",
41
+ "directory": "packages/format-html"
42
+ },
43
+ "homepage": "https://github.com/dogsbay/dogsbay/tree/main/packages/format-html",
44
+ "bugs": {
45
+ "url": "https://github.com/dogsbay/dogsbay/issues"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc",
49
+ "test": "vitest run",
50
+ "test:watch": "vitest"
51
+ }
6
52
  }