@dogsbay/render-html 0.0.0-stage → 0.2.0-beta.116
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/README.md +50 -2
- package/assets/favicon.svg +28 -0
- package/css/code-rich.css +88 -0
- package/css/docs.css +207 -0
- package/css/steps.css +149 -0
- package/css/theme-default.css +239 -0
- package/css/theme-mintlify.css +243 -0
- package/dist/alert-icons.d.ts +6 -0
- package/dist/alert-icons.js +22 -0
- package/dist/badge-variants.d.ts +19 -0
- package/dist/badge-variants.js +33 -0
- package/dist/code-markers.d.ts +29 -0
- package/dist/code-markers.js +66 -0
- package/dist/css-tools.d.ts +12 -0
- package/dist/css-tools.js +75 -0
- package/dist/favicon.d.ts +13 -0
- package/dist/favicon.js +13 -0
- package/dist/file-tree.d.ts +14 -0
- package/dist/file-tree.js +20 -0
- package/dist/html.d.ts +17 -0
- package/dist/html.js +53 -0
- package/dist/icons.d.ts +8 -0
- package/dist/icons.js +65 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/kbd-variants.d.ts +2 -0
- package/dist/kbd-variants.js +3 -0
- package/dist/lines.d.ts +62 -0
- package/dist/lines.js +119 -0
- package/dist/math.d.ts +1 -0
- package/dist/math.js +13 -0
- package/dist/render.d.ts +114 -0
- package/dist/render.js +830 -0
- package/dist/sanitize.d.ts +13 -0
- package/dist/sanitize.js +230 -0
- package/dist/tone-classes.d.ts +1 -0
- package/dist/tone-classes.js +15 -0
- package/dist/url.d.ts +10 -0
- package/dist/url.js +29 -0
- package/package.json +61 -3
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TreeNode → HTML. Emits plain semantic HTML plus light-DOM custom
|
|
3
|
+
* elements (`db-tabs`, `db-accordion`, `db-code-block`) whose markup
|
|
4
|
+
* contract comes from `@dogsbay/elements`. Everything is a string, so
|
|
5
|
+
* rendering is synchronous and runs anywhere.
|
|
6
|
+
*/
|
|
7
|
+
import type { InlineNode, TreeNode } from "@dogsbay/types";
|
|
8
|
+
import { FOREIGN_END, FOREIGN_START } from "./html.js";
|
|
9
|
+
import { type Highlighter } from "./lines.js";
|
|
10
|
+
import { scriptUrl } from "./url.js";
|
|
11
|
+
export interface Heading {
|
|
12
|
+
depth: number;
|
|
13
|
+
id: string;
|
|
14
|
+
text: string;
|
|
15
|
+
}
|
|
16
|
+
export interface RenderContext {
|
|
17
|
+
/** Rewrite a link target (root-relative, relative, `.md`) to its published URL. */
|
|
18
|
+
link(href: string): string;
|
|
19
|
+
/** Rewrite an image or asset path. */
|
|
20
|
+
asset(src: string): string;
|
|
21
|
+
/** Script links and images refused on this page (scriptUrl), for the caller to report. */
|
|
22
|
+
unsafeUrls?: Set<string>;
|
|
23
|
+
/** Syntax highlighting (highlight.ts). Without one, code renders as plain text with the same markup. */
|
|
24
|
+
highlighter?: Highlighter;
|
|
25
|
+
/** Collected h2/h3 for the table of contents. */
|
|
26
|
+
headings: Heading[];
|
|
27
|
+
/** Ids already used on the page; keeps generated ids unique. */
|
|
28
|
+
ids: Set<string>;
|
|
29
|
+
/** Node types the renderer did not recognise (for build warnings). */
|
|
30
|
+
unknown: Set<string>;
|
|
31
|
+
/** Page-local counter for generated ids. */
|
|
32
|
+
seq: number;
|
|
33
|
+
/** Localised UI strings. */
|
|
34
|
+
t(key: string): string;
|
|
35
|
+
/** References seen per footnote label (repeat references get distinct ids). */
|
|
36
|
+
fnRefs?: Map<string, number>;
|
|
37
|
+
/** LaTeX → HTML (`katexMath` from `@dogsbay/render-html/math`, or your own); without it, math stays LaTeX in code. */
|
|
38
|
+
math?: (latex: string, display: boolean) => string;
|
|
39
|
+
/** Set when the page rendered math with KaTeX, so it links the KaTeX stylesheet. */
|
|
40
|
+
usedMath?: boolean;
|
|
41
|
+
/** content.codeBlockTitle: true shows a header for a title or a language, "auto" for a title only, false never. */
|
|
42
|
+
codeBlockTitle?: boolean | "auto";
|
|
43
|
+
/**
|
|
44
|
+
* Resolves an icon name (`rocket`, `lucide:book-open`, `material:tune`) to SVG markup or an emoji,
|
|
45
|
+
* as @dogsbay/icons does for the Astro pipeline. The Node CLI passes one; without it only the
|
|
46
|
+
* built-in Lucide set in icons.ts is available.
|
|
47
|
+
*/
|
|
48
|
+
icons?: (name: string) => string | undefined;
|
|
49
|
+
/** Icon names that could not be resolved; the build warns about them. */
|
|
50
|
+
missingIcons?: Set<string>;
|
|
51
|
+
/** The SVG for a diagram's source, when the caller rendered it (dogsbay-ssg: src/core/diagrams.ts); otherwise the diagram stays a code block. */
|
|
52
|
+
diagram?: (lang: string, code: string) => string | undefined;
|
|
53
|
+
/** Tag images for click-to-zoom (the image zoom plugin); "outside-links" skips images inside links. */
|
|
54
|
+
imageZoom?: "all" | "outside-links";
|
|
55
|
+
/** A paragraph that is one titled image → a figure captioned by the title (content.imageCaptions). */
|
|
56
|
+
imageCaptions?: "title" | false;
|
|
57
|
+
/** Rendering inside a link's text. */
|
|
58
|
+
inLink?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* A filter for raw HTML (html and html-inline nodes, and HTML found in props such
|
|
61
|
+
* as a callout title), applied where it is written. @dogsbay/render passes its
|
|
62
|
+
* sanitizer here; without one, raw HTML is written as authored.
|
|
63
|
+
*/
|
|
64
|
+
rawHtml?: (html: string) => string;
|
|
65
|
+
}
|
|
66
|
+
export { FOREIGN_END, FOREIGN_START };
|
|
67
|
+
export { scriptUrl };
|
|
68
|
+
/** ctx.link, unless the target is a script link: then "#", and it is reported. */
|
|
69
|
+
export declare function linkUrl(href: string, ctx: RenderContext): string;
|
|
70
|
+
/** ctx.asset, unless the source is a script URL: then empty, and it is reported. */
|
|
71
|
+
export declare function assetUrl(src: string, ctx: RenderContext): string;
|
|
72
|
+
/**
|
|
73
|
+
* LaTeX → HTML with MathML for screen readers, at build time: no script on
|
|
74
|
+
* the page. As `@dogsbay/ui`'s MathKatex; a formula KaTeX cannot parse is
|
|
75
|
+
* shown in the error colour instead of failing the build.
|
|
76
|
+
*/
|
|
77
|
+
export declare function renderMath(latex: string, display: boolean, ctx: RenderContext): string | undefined;
|
|
78
|
+
export declare function uniqueId(ctx: RenderContext, base: string): string;
|
|
79
|
+
export declare function renderInline(nodes: InlineNode[] | undefined, ctx: RenderContext): string;
|
|
80
|
+
/** Plain text of inline nodes (for TOC entries, titles and search). */
|
|
81
|
+
export declare function inlineText(nodes: InlineNode[] | undefined): string;
|
|
82
|
+
/**
|
|
83
|
+
* Rewrite href/src attributes of tags in raw HTML so root-relative links follow
|
|
84
|
+
* the site layout. Only attributes inside a start tag are touched (not text such
|
|
85
|
+
* as an escaped code example, nor data-href), and values are entity-decoded
|
|
86
|
+
* before resolving so `&` is not escaped twice.
|
|
87
|
+
*/
|
|
88
|
+
export declare function rewriteHtml(raw: string, ctx: RenderContext): string;
|
|
89
|
+
export declare function renderBlocks(nodes: TreeNode[] | undefined, ctx: RenderContext): string;
|
|
90
|
+
/** What highlighting a code node asks of the highlighter; the look-ahead in `build` uses it to highlight blocks ahead of their page. */
|
|
91
|
+
export interface CodeRequest {
|
|
92
|
+
code: string;
|
|
93
|
+
lang: string | undefined;
|
|
94
|
+
opts: {
|
|
95
|
+
highlights: number[];
|
|
96
|
+
lineNumbers: boolean;
|
|
97
|
+
diffAdd: number[];
|
|
98
|
+
diffRemove: number[];
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export declare function codeRequest(n: TreeNode): CodeRequest;
|
|
102
|
+
/**
|
|
103
|
+
* Every block (language tag as written, and code) a tree's rendering may ask
|
|
104
|
+
* the highlighter for, so a highlighter that loads grammars per language
|
|
105
|
+
* (`Highlighter.load`) can load them before rendering: code nodes, and
|
|
106
|
+
* diagrams, which fall back to a code block when not rendered. The code is
|
|
107
|
+
* part of it: a markdown block needs the grammars its fences name. Looks
|
|
108
|
+
* through props as well as children, so a node a component nests elsewhere
|
|
109
|
+
* is found.
|
|
110
|
+
*/
|
|
111
|
+
export declare function highlightInputs(tree: unknown): Array<{
|
|
112
|
+
lang: string | undefined;
|
|
113
|
+
code: string;
|
|
114
|
+
}>;
|