@wdprlib/render 0.1.0
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/index.cjs +4701 -0
- package/dist/index.d.cts +73 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +4668 -0
- package/package.json +44 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { SyntaxTree as SyntaxTree2 } from "@wdprlib/ast";
|
|
2
|
+
import { Element } from "@wdprlib/ast";
|
|
3
|
+
/**
|
|
4
|
+
* Page context for resolving links, images, etc.
|
|
5
|
+
*/
|
|
6
|
+
interface PageContext {
|
|
7
|
+
/** Current page's full name (e.g., "secret:test2") */
|
|
8
|
+
pageName: string;
|
|
9
|
+
/** Site slug (e.g., "scp-wiki") */
|
|
10
|
+
site?: string;
|
|
11
|
+
/** Site domain (e.g., "scp-wiki.wikidot.com") */
|
|
12
|
+
domain?: string;
|
|
13
|
+
/** Check if a page exists (for "newpage" class on links) */
|
|
14
|
+
pageExists?: (page: string) => boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolved user information for rendering
|
|
18
|
+
*/
|
|
19
|
+
interface ResolvedUser {
|
|
20
|
+
/** User's display name (defaults to username if not provided) */
|
|
21
|
+
name?: string;
|
|
22
|
+
/** User profile URL. If not provided, link becomes non-navigable */
|
|
23
|
+
url?: string;
|
|
24
|
+
/** Avatar image URL. If not provided, no avatar is rendered */
|
|
25
|
+
avatarUrl?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolver functions for dynamic content
|
|
29
|
+
*/
|
|
30
|
+
interface RenderResolvers {
|
|
31
|
+
/**
|
|
32
|
+
* Resolve user information from username.
|
|
33
|
+
* Returns user data for rendering, or null if user not found.
|
|
34
|
+
* If not provided, user elements are rendered as plain text.
|
|
35
|
+
*/
|
|
36
|
+
user?: (username: string) => ResolvedUser | null;
|
|
37
|
+
/**
|
|
38
|
+
* Returns URL for htmlBlock iframe src.
|
|
39
|
+
* Called with the index of the htmlBlock (0-based, matching tree["html-blocks"] order).
|
|
40
|
+
* If not provided or returns empty string, uses default pattern: /{pageName}/html/{hash}-{nonce}
|
|
41
|
+
*
|
|
42
|
+
* SECURITY NOTE: The returned URL is used directly in iframe src attribute.
|
|
43
|
+
* The application is responsible for validating the URL scheme (e.g., rejecting javascript:, data:).
|
|
44
|
+
*/
|
|
45
|
+
htmlBlockUrl?: (index: number) => string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options for HTML rendering
|
|
49
|
+
*/
|
|
50
|
+
interface RenderOptions {
|
|
51
|
+
/** Page context for resolving file paths, links, etc. */
|
|
52
|
+
page?: PageContext;
|
|
53
|
+
/** Pre-collected footnote elements from SyntaxTree.footnotes */
|
|
54
|
+
footnotes?: Element[][];
|
|
55
|
+
/** Resolver functions for dynamic content */
|
|
56
|
+
resolvers?: RenderResolvers;
|
|
57
|
+
/**
|
|
58
|
+
* Sandbox attribute value for htmlBlock iframes.
|
|
59
|
+
* - undefined/null: No sandbox attribute (Wikidot compatible, scripts can run)
|
|
60
|
+
* - string: Use as sandbox attribute value (e.g., "allow-scripts allow-same-origin")
|
|
61
|
+
*
|
|
62
|
+
* Examples:
|
|
63
|
+
* - No sandbox (Wikidot compatible): htmlBlockSandbox: null
|
|
64
|
+
* - Block scripts: htmlBlockSandbox: "allow-same-origin"
|
|
65
|
+
* - Allow scripts: htmlBlockSandbox: "allow-scripts allow-same-origin"
|
|
66
|
+
*/
|
|
67
|
+
htmlBlockSandbox?: string | null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Render a SyntaxTree to HTML string
|
|
71
|
+
*/
|
|
72
|
+
declare function renderToHtml(tree: SyntaxTree2, options?: RenderOptions): string;
|
|
73
|
+
export { renderToHtml, ResolvedUser, RenderResolvers, RenderOptions, PageContext };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { SyntaxTree as SyntaxTree2 } from "@wdprlib/ast";
|
|
2
|
+
import { Element } from "@wdprlib/ast";
|
|
3
|
+
/**
|
|
4
|
+
* Page context for resolving links, images, etc.
|
|
5
|
+
*/
|
|
6
|
+
interface PageContext {
|
|
7
|
+
/** Current page's full name (e.g., "secret:test2") */
|
|
8
|
+
pageName: string;
|
|
9
|
+
/** Site slug (e.g., "scp-wiki") */
|
|
10
|
+
site?: string;
|
|
11
|
+
/** Site domain (e.g., "scp-wiki.wikidot.com") */
|
|
12
|
+
domain?: string;
|
|
13
|
+
/** Check if a page exists (for "newpage" class on links) */
|
|
14
|
+
pageExists?: (page: string) => boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolved user information for rendering
|
|
18
|
+
*/
|
|
19
|
+
interface ResolvedUser {
|
|
20
|
+
/** User's display name (defaults to username if not provided) */
|
|
21
|
+
name?: string;
|
|
22
|
+
/** User profile URL. If not provided, link becomes non-navigable */
|
|
23
|
+
url?: string;
|
|
24
|
+
/** Avatar image URL. If not provided, no avatar is rendered */
|
|
25
|
+
avatarUrl?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolver functions for dynamic content
|
|
29
|
+
*/
|
|
30
|
+
interface RenderResolvers {
|
|
31
|
+
/**
|
|
32
|
+
* Resolve user information from username.
|
|
33
|
+
* Returns user data for rendering, or null if user not found.
|
|
34
|
+
* If not provided, user elements are rendered as plain text.
|
|
35
|
+
*/
|
|
36
|
+
user?: (username: string) => ResolvedUser | null;
|
|
37
|
+
/**
|
|
38
|
+
* Returns URL for htmlBlock iframe src.
|
|
39
|
+
* Called with the index of the htmlBlock (0-based, matching tree["html-blocks"] order).
|
|
40
|
+
* If not provided or returns empty string, uses default pattern: /{pageName}/html/{hash}-{nonce}
|
|
41
|
+
*
|
|
42
|
+
* SECURITY NOTE: The returned URL is used directly in iframe src attribute.
|
|
43
|
+
* The application is responsible for validating the URL scheme (e.g., rejecting javascript:, data:).
|
|
44
|
+
*/
|
|
45
|
+
htmlBlockUrl?: (index: number) => string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options for HTML rendering
|
|
49
|
+
*/
|
|
50
|
+
interface RenderOptions {
|
|
51
|
+
/** Page context for resolving file paths, links, etc. */
|
|
52
|
+
page?: PageContext;
|
|
53
|
+
/** Pre-collected footnote elements from SyntaxTree.footnotes */
|
|
54
|
+
footnotes?: Element[][];
|
|
55
|
+
/** Resolver functions for dynamic content */
|
|
56
|
+
resolvers?: RenderResolvers;
|
|
57
|
+
/**
|
|
58
|
+
* Sandbox attribute value for htmlBlock iframes.
|
|
59
|
+
* - undefined/null: No sandbox attribute (Wikidot compatible, scripts can run)
|
|
60
|
+
* - string: Use as sandbox attribute value (e.g., "allow-scripts allow-same-origin")
|
|
61
|
+
*
|
|
62
|
+
* Examples:
|
|
63
|
+
* - No sandbox (Wikidot compatible): htmlBlockSandbox: null
|
|
64
|
+
* - Block scripts: htmlBlockSandbox: "allow-same-origin"
|
|
65
|
+
* - Allow scripts: htmlBlockSandbox: "allow-scripts allow-same-origin"
|
|
66
|
+
*/
|
|
67
|
+
htmlBlockSandbox?: string | null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Render a SyntaxTree to HTML string
|
|
71
|
+
*/
|
|
72
|
+
declare function renderToHtml(tree: SyntaxTree2, options?: RenderOptions): string;
|
|
73
|
+
export { renderToHtml, ResolvedUser, RenderResolvers, RenderOptions, PageContext };
|