@wdprlib/ast 2.3.0 → 4.0.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/README.md CHANGED
@@ -20,6 +20,21 @@ const tree: SyntaxTree = {
20
20
  };
21
21
  ```
22
22
 
23
+ ## Security-sensitive settings
24
+
25
+ `createSettings(mode)` supplies safe defaults for parser and renderer capabilities. In every mode,
26
+ including `"page"`, `allowStyleElements` defaults to `false` because `[[module CSS]]` affects the
27
+ entire host page. Callers may override it to `true` only for trusted CSS:
28
+
29
+ ```ts
30
+ import { createSettings } from "@wdprlib/ast";
31
+
32
+ const settings = {
33
+ ...createSettings("page"),
34
+ allowStyleElements: true,
35
+ };
36
+ ```
37
+
23
38
  ## Exports
24
39
 
25
40
  Types: `SyntaxTree`, `Element`, `ElementName`, `ContainerType`, `AttributeMap`, `LinkType`, `ListType`, `Module`, etc.
package/dist/index.cjs CHANGED
@@ -54,6 +54,7 @@ __export(exports_src, {
54
54
  container: () => container,
55
55
  bold: () => bold,
56
56
  STYLE_SLOT_PREFIX: () => STYLE_SLOT_PREFIX,
57
+ STYLE_ANCHOR_PREFIX: () => STYLE_ANCHOR_PREFIX,
57
58
  DEFAULT_SETTINGS: () => DEFAULT_SETTINGS,
58
59
  CSS_LENGTH_UNITS: () => CSS_LENGTH_UNITS
59
60
  });
@@ -254,6 +255,7 @@ function isParagraphSafe(element) {
254
255
  }
255
256
  // packages/ast/src/constants.ts
256
257
  var STYLE_SLOT_PREFIX = "\x00__IFTAGS_SLOT__";
258
+ var STYLE_ANCHOR_PREFIX = "\x00__STYLE_ANCHOR__";
257
259
  // packages/ast/src/css.ts
258
260
  var CSS_LENGTH_UNITS = [
259
261
  "cqmax",
@@ -704,7 +706,7 @@ function createSettings(mode) {
704
706
  enablePageSyntax: true,
705
707
  allowLocalPaths: true,
706
708
  useTrueIds: true,
707
- allowStyleElements: true,
709
+ allowStyleElements: false,
708
710
  allowHtmlBlocks: true
709
711
  };
710
712
  case "draft":
package/dist/index.d.cts CHANGED
@@ -1233,6 +1233,13 @@ interface ParseResult {
1233
1233
  */
1234
1234
  declare const STYLE_SLOT_PREFIX = "\0__IFTAGS_SLOT__";
1235
1235
  /**
1236
+ * Sentinel prefix for invisible style-position anchors retained in the AST.
1237
+ *
1238
+ * The suffix is the previously collected CSS text. Renderers must not emit
1239
+ * these synthetic style elements.
1240
+ */
1241
+ declare const STYLE_ANCHOR_PREFIX = "\0__STYLE_ANCHOR__";
1242
+ /**
1236
1243
  * Context-dependent settings for the Wikidot parser and renderer.
1237
1244
  *
1238
1245
  * Wikidot content appears in several different contexts — full wiki pages,
@@ -1255,7 +1262,7 @@ declare const STYLE_SLOT_PREFIX = "\0__IFTAGS_SLOT__";
1255
1262
  *
1256
1263
  * | Mode | Page syntax | Local paths | True IDs | Style elements | HTML blocks |
1257
1264
  * |--------------------|:-----------:|:-----------:|:--------:|:--------------:|:-----------:|
1258
- * | `"page"` | yes | yes | yes | yes | yes |
1265
+ * | `"page"` | yes | yes | yes | no | yes |
1259
1266
  * | `"draft"` | yes | yes | no | no | no |
1260
1267
  * | `"forum-post"` | no | no | no | no | no |
1261
1268
  * | `"direct-message"` | no | no | no | no | no |
@@ -1304,9 +1311,9 @@ interface WikitextSettings {
1304
1311
  /**
1305
1312
  * Whether `[[module CSS]]` blocks are rendered as `<style>` tags.
1306
1313
  *
1307
- * User-authored CSS can break page layout, so it is allowed only on
1308
- * full wiki pages. In draft previews, forum posts, and direct messages
1309
- * the CSS module is silently ignored.
1314
+ * User-authored CSS can break page layout and leak page data, so it is
1315
+ * disabled by default in every mode. Callers may explicitly enable it
1316
+ * only for trusted CSS.
1310
1317
  */
1311
1318
  allowStyleElements: boolean;
1312
1319
  /**
@@ -1394,6 +1401,28 @@ declare function formatExprValue(n: number): string;
1394
1401
  * @returns A success result with a numeric value, or an error result with a message.
1395
1402
  */
1396
1403
  declare function evaluateExpression(expr: string): ExprResult;
1404
+ /** Attachment metadata used by page-contextual gallery rendering. */
1405
+ interface WikitextPageFile {
1406
+ name: string;
1407
+ createdAt?: number;
1408
+ }
1409
+ /**
1410
+ * Page data shared by high-level parser and renderer APIs.
1411
+ *
1412
+ * `fullName` is the category-qualified Wikidot page name. `unixName`, when
1413
+ * available, is the separately named URL-safe page identifier.
1414
+ */
1415
+ interface WikitextPageContext {
1416
+ fullName: string;
1417
+ unixName?: string;
1418
+ tags: string[];
1419
+ urlPath?: string;
1420
+ site?: string;
1421
+ domain?: string;
1422
+ siteDomains?: Record<string, string>;
1423
+ resolveSiteDomain?: (site: string) => string | null | undefined;
1424
+ files?: WikitextPageFile[];
1425
+ }
1397
1426
  /**
1398
1427
  * Identifies the source markup dialect.
1399
1428
  *
@@ -1403,4 +1432,4 @@ declare function evaluateExpression(expr: string): ExprResult;
1403
1432
  * @group Core
1404
1433
  */
1405
1434
  type Version = "wikidot";
1406
- export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isTruthy, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, formatExprValue, evaluateExpression, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, GallerySize, GalleryOrder, GalleryItem, GalleryData, GalleryContent, FootnoteBlockData, FloatAlignment, ExprResult, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, CssLengthUnit, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, CSS_LENGTH_UNITS, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
1435
+ export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isTruthy, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, formatExprValue, evaluateExpression, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextPageFile, WikitextPageContext, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, STYLE_ANCHOR_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, GallerySize, GalleryOrder, GalleryItem, GalleryData, GalleryContent, FootnoteBlockData, FloatAlignment, ExprResult, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, CssLengthUnit, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, CSS_LENGTH_UNITS, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
package/dist/index.d.ts CHANGED
@@ -1233,6 +1233,13 @@ interface ParseResult {
1233
1233
  */
1234
1234
  declare const STYLE_SLOT_PREFIX = "\0__IFTAGS_SLOT__";
1235
1235
  /**
1236
+ * Sentinel prefix for invisible style-position anchors retained in the AST.
1237
+ *
1238
+ * The suffix is the previously collected CSS text. Renderers must not emit
1239
+ * these synthetic style elements.
1240
+ */
1241
+ declare const STYLE_ANCHOR_PREFIX = "\0__STYLE_ANCHOR__";
1242
+ /**
1236
1243
  * Context-dependent settings for the Wikidot parser and renderer.
1237
1244
  *
1238
1245
  * Wikidot content appears in several different contexts — full wiki pages,
@@ -1255,7 +1262,7 @@ declare const STYLE_SLOT_PREFIX = "\0__IFTAGS_SLOT__";
1255
1262
  *
1256
1263
  * | Mode | Page syntax | Local paths | True IDs | Style elements | HTML blocks |
1257
1264
  * |--------------------|:-----------:|:-----------:|:--------:|:--------------:|:-----------:|
1258
- * | `"page"` | yes | yes | yes | yes | yes |
1265
+ * | `"page"` | yes | yes | yes | no | yes |
1259
1266
  * | `"draft"` | yes | yes | no | no | no |
1260
1267
  * | `"forum-post"` | no | no | no | no | no |
1261
1268
  * | `"direct-message"` | no | no | no | no | no |
@@ -1304,9 +1311,9 @@ interface WikitextSettings {
1304
1311
  /**
1305
1312
  * Whether `[[module CSS]]` blocks are rendered as `<style>` tags.
1306
1313
  *
1307
- * User-authored CSS can break page layout, so it is allowed only on
1308
- * full wiki pages. In draft previews, forum posts, and direct messages
1309
- * the CSS module is silently ignored.
1314
+ * User-authored CSS can break page layout and leak page data, so it is
1315
+ * disabled by default in every mode. Callers may explicitly enable it
1316
+ * only for trusted CSS.
1310
1317
  */
1311
1318
  allowStyleElements: boolean;
1312
1319
  /**
@@ -1394,6 +1401,28 @@ declare function formatExprValue(n: number): string;
1394
1401
  * @returns A success result with a numeric value, or an error result with a message.
1395
1402
  */
1396
1403
  declare function evaluateExpression(expr: string): ExprResult;
1404
+ /** Attachment metadata used by page-contextual gallery rendering. */
1405
+ interface WikitextPageFile {
1406
+ name: string;
1407
+ createdAt?: number;
1408
+ }
1409
+ /**
1410
+ * Page data shared by high-level parser and renderer APIs.
1411
+ *
1412
+ * `fullName` is the category-qualified Wikidot page name. `unixName`, when
1413
+ * available, is the separately named URL-safe page identifier.
1414
+ */
1415
+ interface WikitextPageContext {
1416
+ fullName: string;
1417
+ unixName?: string;
1418
+ tags: string[];
1419
+ urlPath?: string;
1420
+ site?: string;
1421
+ domain?: string;
1422
+ siteDomains?: Record<string, string>;
1423
+ resolveSiteDomain?: (site: string) => string | null | undefined;
1424
+ files?: WikitextPageFile[];
1425
+ }
1397
1426
  /**
1398
1427
  * Identifies the source markup dialect.
1399
1428
  *
@@ -1403,4 +1432,4 @@ declare function evaluateExpression(expr: string): ExprResult;
1403
1432
  * @group Core
1404
1433
  */
1405
1434
  type Version = "wikidot";
1406
- export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isTruthy, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, formatExprValue, evaluateExpression, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, GallerySize, GalleryOrder, GalleryItem, GalleryData, GalleryContent, FootnoteBlockData, FloatAlignment, ExprResult, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, CssLengthUnit, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, CSS_LENGTH_UNITS, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
1435
+ export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isTruthy, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, formatExprValue, evaluateExpression, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextPageFile, WikitextPageContext, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, STYLE_ANCHOR_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, GallerySize, GalleryOrder, GalleryItem, GalleryData, GalleryContent, FootnoteBlockData, FloatAlignment, ExprResult, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, CssLengthUnit, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, CSS_LENGTH_UNITS, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
package/dist/index.js CHANGED
@@ -193,6 +193,7 @@ function isParagraphSafe(element) {
193
193
  }
194
194
  // packages/ast/src/constants.ts
195
195
  var STYLE_SLOT_PREFIX = "\x00__IFTAGS_SLOT__";
196
+ var STYLE_ANCHOR_PREFIX = "\x00__STYLE_ANCHOR__";
196
197
  // packages/ast/src/css.ts
197
198
  var CSS_LENGTH_UNITS = [
198
199
  "cqmax",
@@ -643,7 +644,7 @@ function createSettings(mode) {
643
644
  enablePageSyntax: true,
644
645
  allowLocalPaths: true,
645
646
  useTrueIds: true,
646
- allowStyleElements: true,
647
+ allowStyleElements: false,
647
648
  allowHtmlBlocks: true
648
649
  };
649
650
  case "draft":
@@ -693,6 +694,7 @@ export {
693
694
  container,
694
695
  bold,
695
696
  STYLE_SLOT_PREFIX,
697
+ STYLE_ANCHOR_PREFIX,
696
698
  DEFAULT_SETTINGS,
697
699
  CSS_LENGTH_UNITS
698
700
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdprlib/ast",
3
- "version": "2.3.0",
3
+ "version": "4.0.0",
4
4
  "description": "AST types for Wikidot markup",
5
5
  "keywords": [
6
6
  "ast",
package/src/constants.ts CHANGED
@@ -10,3 +10,11 @@
10
10
  * A null-byte prefix ensures no collision with valid CSS content.
11
11
  */
12
12
  export const STYLE_SLOT_PREFIX = "\0__IFTAGS_SLOT__";
13
+
14
+ /**
15
+ * Sentinel prefix for invisible style-position anchors retained in the AST.
16
+ *
17
+ * The suffix is the previously collected CSS text. Renderers must not emit
18
+ * these synthetic style elements.
19
+ */
20
+ export const STYLE_ANCHOR_PREFIX = "\0__STYLE_ANCHOR__";
package/src/index.ts CHANGED
@@ -113,7 +113,7 @@ export {
113
113
  export type { Diagnostic, DiagnosticSeverity, ParseResult } from "./diagnostic";
114
114
 
115
115
  // Constants
116
- export { STYLE_SLOT_PREFIX } from "./constants";
116
+ export { STYLE_ANCHOR_PREFIX, STYLE_SLOT_PREFIX } from "./constants";
117
117
 
118
118
  // CSS value definitions
119
119
  export type { CssLengthUnit } from "./css";
@@ -126,3 +126,6 @@ export type { WikitextMode, WikitextSettings } from "./settings";
126
126
  export { evaluateExpression, isTruthy, formatExprValue } from "./expr-eval";
127
127
  export type { ExprResult } from "./expr-eval";
128
128
  export { createSettings, DEFAULT_SETTINGS } from "./settings";
129
+
130
+ // Shared high-level pipeline page context
131
+ export type { WikitextPageContext, WikitextPageFile } from "./page-context";
@@ -0,0 +1,23 @@
1
+ /** Attachment metadata used by page-contextual gallery rendering. */
2
+ export interface WikitextPageFile {
3
+ name: string;
4
+ createdAt?: number;
5
+ }
6
+
7
+ /**
8
+ * Page data shared by high-level parser and renderer APIs.
9
+ *
10
+ * `fullName` is the category-qualified Wikidot page name. `unixName`, when
11
+ * available, is the separately named URL-safe page identifier.
12
+ */
13
+ export interface WikitextPageContext {
14
+ fullName: string;
15
+ unixName?: string;
16
+ tags: string[];
17
+ urlPath?: string;
18
+ site?: string;
19
+ domain?: string;
20
+ siteDomains?: Record<string, string>;
21
+ resolveSiteDomain?: (site: string) => string | null | undefined;
22
+ files?: WikitextPageFile[];
23
+ }
package/src/settings.ts CHANGED
@@ -22,7 +22,7 @@
22
22
  *
23
23
  * | Mode | Page syntax | Local paths | True IDs | Style elements | HTML blocks |
24
24
  * |--------------------|:-----------:|:-----------:|:--------:|:--------------:|:-----------:|
25
- * | `"page"` | yes | yes | yes | yes | yes |
25
+ * | `"page"` | yes | yes | yes | no | yes |
26
26
  * | `"draft"` | yes | yes | no | no | no |
27
27
  * | `"forum-post"` | no | no | no | no | no |
28
28
  * | `"direct-message"` | no | no | no | no | no |
@@ -76,9 +76,9 @@ export interface WikitextSettings {
76
76
  /**
77
77
  * Whether `[[module CSS]]` blocks are rendered as `<style>` tags.
78
78
  *
79
- * User-authored CSS can break page layout, so it is allowed only on
80
- * full wiki pages. In draft previews, forum posts, and direct messages
81
- * the CSS module is silently ignored.
79
+ * User-authored CSS can break page layout and leak page data, so it is
80
+ * disabled by default in every mode. Callers may explicitly enable it
81
+ * only for trusted CSS.
82
82
  */
83
83
  allowStyleElements: boolean;
84
84
 
@@ -121,7 +121,7 @@ export function createSettings(mode: WikitextMode): WikitextSettings {
121
121
  enablePageSyntax: true,
122
122
  allowLocalPaths: true,
123
123
  useTrueIds: true,
124
- allowStyleElements: true,
124
+ allowStyleElements: false,
125
125
  allowHtmlBlocks: true,
126
126
  };
127
127
  case "draft":