@ai-matrx/print 0.8.7 → 0.8.9
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/CHANGELOG.md +51 -0
- package/dist/document.cjs +256 -8
- package/dist/document.cjs.map +1 -1
- package/dist/document.d.cts +10 -2
- package/dist/document.d.ts +10 -2
- package/dist/document.js +256 -8
- package/dist/document.js.map +1 -1
- package/dist/markdown-html.cjs +4207 -0
- package/dist/markdown-html.cjs.map +1 -0
- package/dist/markdown-html.d.cts +87 -0
- package/dist/markdown-html.d.ts +87 -0
- package/dist/markdown-html.js +4176 -0
- package/dist/markdown-html.js.map +1 -0
- package/dist/markdown.cjs +146 -36
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.js +146 -36
- package/dist/markdown.js.map +1 -1
- package/dist/safe-html.cjs +299 -0
- package/dist/safe-html.cjs.map +1 -0
- package/dist/safe-html.d.cts +56 -0
- package/dist/safe-html.d.ts +56 -0
- package/dist/safe-html.js +278 -0
- package/dist/safe-html.js.map +1 -0
- package/package.json +27 -3
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { PrepareDocumentOptions, DocTree } from './document.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @ai-matrx/print/markdown-html — THE ONE Markdown→HTML engine (Matrx Alchemy
|
|
5
|
+
* CONTRACT §1.9, ALC-16).
|
|
6
|
+
*
|
|
7
|
+
* ONE parse:
|
|
8
|
+
* 1. The platform's one reading of our syntax (`@ai-matrx/content-ir/source`
|
|
9
|
+
* `tokenizeSource`) marks every kind island — a `__kind` JSON block, an
|
|
10
|
+
* inline `__kind` JSON span, and any XML element a projector is
|
|
11
|
+
* registered for. Each island is replaced IN PLACE by an opaque atom
|
|
12
|
+
* placeholder, so an inline island never splits a paragraph, a list item
|
|
13
|
+
* or a table cell.
|
|
14
|
+
* 2. mdast parses the whole text once (`prepareDocument`: the same tree PDF,
|
|
15
|
+
* DOCX and EPUB render from; math is typeset, citations resolved).
|
|
16
|
+
* 3. print's escape-by-construction renderer writes the HTML; each atom is
|
|
17
|
+
* rendered by the `KindHtmlProjector` registered for its kind, or — when
|
|
18
|
+
* none is — as escaped source with a notice.
|
|
19
|
+
* 4. EVERY string this module returns ends in the allow-list
|
|
20
|
+
* (`sanitizeEngineHtml`, `@ai-matrx/print/safe-html`): no raw author
|
|
21
|
+
* HTML, no author style, and each drop is announced by the parse.
|
|
22
|
+
*
|
|
23
|
+
* Skins: `document` / `article` keep print's class vocabulary (styled by the
|
|
24
|
+
* page CSS); `inline` writes every style onto the element (Google Docs and
|
|
25
|
+
* Word drop `<style>` and classes on paste). The inline styles are constants
|
|
26
|
+
* of this module and the allow-list admits exactly those values.
|
|
27
|
+
*
|
|
28
|
+
* Pure and DOM-free: runs in the browser, Node, a worker, the extension
|
|
29
|
+
* service worker and Tauri alike.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** A sentence a person reads, and what they can do about it. */
|
|
33
|
+
interface EngineNotice {
|
|
34
|
+
code: string;
|
|
35
|
+
sentence: string;
|
|
36
|
+
remedy: string;
|
|
37
|
+
}
|
|
38
|
+
/** Private or signed images → share-safe URLs before the HTML is sealed. */
|
|
39
|
+
interface EngineAssetResolver {
|
|
40
|
+
resolve(url: string, signal: AbortSignal): Promise<{
|
|
41
|
+
url: string;
|
|
42
|
+
} | null>;
|
|
43
|
+
}
|
|
44
|
+
/** A kind renders into the HTML through its projector; none = escaped source + notice. */
|
|
45
|
+
interface KindHtmlProjector {
|
|
46
|
+
kindKey: string;
|
|
47
|
+
toHtml(value: unknown, escape: (s: string) => string): string;
|
|
48
|
+
toPlainText(value: unknown): string;
|
|
49
|
+
}
|
|
50
|
+
type EngineSkin = "document" | "article" | "inline";
|
|
51
|
+
type EngineProfile = "generic" | "google-docs" | "word";
|
|
52
|
+
/** One parse. Opaque to callers; hand it back to `fragment` / `document` / `plainText`. */
|
|
53
|
+
interface EngineTree {
|
|
54
|
+
readonly doc: DocTree;
|
|
55
|
+
readonly atoms: readonly EngineAtom[];
|
|
56
|
+
readonly images: ReadonlyMap<string, string | null>;
|
|
57
|
+
readonly notices: readonly EngineNotice[];
|
|
58
|
+
}
|
|
59
|
+
interface EngineAtom {
|
|
60
|
+
kindKey: string;
|
|
61
|
+
raw: string;
|
|
62
|
+
inline: boolean;
|
|
63
|
+
value: unknown;
|
|
64
|
+
projector: KindHtmlProjector | null;
|
|
65
|
+
}
|
|
66
|
+
interface EngineParseOptions extends Omit<PrepareDocumentOptions, "onNotice"> {
|
|
67
|
+
onNotice?(notice: EngineNotice): void;
|
|
68
|
+
assets?: EngineAssetResolver;
|
|
69
|
+
signal?: AbortSignal;
|
|
70
|
+
}
|
|
71
|
+
interface MarkdownHtmlEngine {
|
|
72
|
+
parse(markdown: string, options?: EngineParseOptions): Promise<EngineTree>;
|
|
73
|
+
fragment(tree: EngineTree, options?: {
|
|
74
|
+
skin?: EngineSkin;
|
|
75
|
+
profile?: EngineProfile;
|
|
76
|
+
}): string;
|
|
77
|
+
document(tree: EngineTree, options?: {
|
|
78
|
+
title?: string;
|
|
79
|
+
}): string;
|
|
80
|
+
plainText(tree: EngineTree): string;
|
|
81
|
+
}
|
|
82
|
+
/** Create the engine. Projectors are keyed by kind; a second one for the same kind is refused. */
|
|
83
|
+
declare function createMarkdownHtmlEngine(options?: {
|
|
84
|
+
projectors?: readonly KindHtmlProjector[];
|
|
85
|
+
}): MarkdownHtmlEngine;
|
|
86
|
+
|
|
87
|
+
export { type EngineAssetResolver, type EngineNotice, type EngineParseOptions, type EngineProfile, type EngineSkin, type EngineTree, type KindHtmlProjector, type MarkdownHtmlEngine, createMarkdownHtmlEngine };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { PrepareDocumentOptions, DocTree } from './document.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @ai-matrx/print/markdown-html — THE ONE Markdown→HTML engine (Matrx Alchemy
|
|
5
|
+
* CONTRACT §1.9, ALC-16).
|
|
6
|
+
*
|
|
7
|
+
* ONE parse:
|
|
8
|
+
* 1. The platform's one reading of our syntax (`@ai-matrx/content-ir/source`
|
|
9
|
+
* `tokenizeSource`) marks every kind island — a `__kind` JSON block, an
|
|
10
|
+
* inline `__kind` JSON span, and any XML element a projector is
|
|
11
|
+
* registered for. Each island is replaced IN PLACE by an opaque atom
|
|
12
|
+
* placeholder, so an inline island never splits a paragraph, a list item
|
|
13
|
+
* or a table cell.
|
|
14
|
+
* 2. mdast parses the whole text once (`prepareDocument`: the same tree PDF,
|
|
15
|
+
* DOCX and EPUB render from; math is typeset, citations resolved).
|
|
16
|
+
* 3. print's escape-by-construction renderer writes the HTML; each atom is
|
|
17
|
+
* rendered by the `KindHtmlProjector` registered for its kind, or — when
|
|
18
|
+
* none is — as escaped source with a notice.
|
|
19
|
+
* 4. EVERY string this module returns ends in the allow-list
|
|
20
|
+
* (`sanitizeEngineHtml`, `@ai-matrx/print/safe-html`): no raw author
|
|
21
|
+
* HTML, no author style, and each drop is announced by the parse.
|
|
22
|
+
*
|
|
23
|
+
* Skins: `document` / `article` keep print's class vocabulary (styled by the
|
|
24
|
+
* page CSS); `inline` writes every style onto the element (Google Docs and
|
|
25
|
+
* Word drop `<style>` and classes on paste). The inline styles are constants
|
|
26
|
+
* of this module and the allow-list admits exactly those values.
|
|
27
|
+
*
|
|
28
|
+
* Pure and DOM-free: runs in the browser, Node, a worker, the extension
|
|
29
|
+
* service worker and Tauri alike.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** A sentence a person reads, and what they can do about it. */
|
|
33
|
+
interface EngineNotice {
|
|
34
|
+
code: string;
|
|
35
|
+
sentence: string;
|
|
36
|
+
remedy: string;
|
|
37
|
+
}
|
|
38
|
+
/** Private or signed images → share-safe URLs before the HTML is sealed. */
|
|
39
|
+
interface EngineAssetResolver {
|
|
40
|
+
resolve(url: string, signal: AbortSignal): Promise<{
|
|
41
|
+
url: string;
|
|
42
|
+
} | null>;
|
|
43
|
+
}
|
|
44
|
+
/** A kind renders into the HTML through its projector; none = escaped source + notice. */
|
|
45
|
+
interface KindHtmlProjector {
|
|
46
|
+
kindKey: string;
|
|
47
|
+
toHtml(value: unknown, escape: (s: string) => string): string;
|
|
48
|
+
toPlainText(value: unknown): string;
|
|
49
|
+
}
|
|
50
|
+
type EngineSkin = "document" | "article" | "inline";
|
|
51
|
+
type EngineProfile = "generic" | "google-docs" | "word";
|
|
52
|
+
/** One parse. Opaque to callers; hand it back to `fragment` / `document` / `plainText`. */
|
|
53
|
+
interface EngineTree {
|
|
54
|
+
readonly doc: DocTree;
|
|
55
|
+
readonly atoms: readonly EngineAtom[];
|
|
56
|
+
readonly images: ReadonlyMap<string, string | null>;
|
|
57
|
+
readonly notices: readonly EngineNotice[];
|
|
58
|
+
}
|
|
59
|
+
interface EngineAtom {
|
|
60
|
+
kindKey: string;
|
|
61
|
+
raw: string;
|
|
62
|
+
inline: boolean;
|
|
63
|
+
value: unknown;
|
|
64
|
+
projector: KindHtmlProjector | null;
|
|
65
|
+
}
|
|
66
|
+
interface EngineParseOptions extends Omit<PrepareDocumentOptions, "onNotice"> {
|
|
67
|
+
onNotice?(notice: EngineNotice): void;
|
|
68
|
+
assets?: EngineAssetResolver;
|
|
69
|
+
signal?: AbortSignal;
|
|
70
|
+
}
|
|
71
|
+
interface MarkdownHtmlEngine {
|
|
72
|
+
parse(markdown: string, options?: EngineParseOptions): Promise<EngineTree>;
|
|
73
|
+
fragment(tree: EngineTree, options?: {
|
|
74
|
+
skin?: EngineSkin;
|
|
75
|
+
profile?: EngineProfile;
|
|
76
|
+
}): string;
|
|
77
|
+
document(tree: EngineTree, options?: {
|
|
78
|
+
title?: string;
|
|
79
|
+
}): string;
|
|
80
|
+
plainText(tree: EngineTree): string;
|
|
81
|
+
}
|
|
82
|
+
/** Create the engine. Projectors are keyed by kind; a second one for the same kind is refused. */
|
|
83
|
+
declare function createMarkdownHtmlEngine(options?: {
|
|
84
|
+
projectors?: readonly KindHtmlProjector[];
|
|
85
|
+
}): MarkdownHtmlEngine;
|
|
86
|
+
|
|
87
|
+
export { type EngineAssetResolver, type EngineNotice, type EngineParseOptions, type EngineProfile, type EngineSkin, type EngineTree, type KindHtmlProjector, type MarkdownHtmlEngine, createMarkdownHtmlEngine };
|