@standard-reader/renderer-core 0.2.0 → 0.4.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.
Files changed (105) hide show
  1. package/README.md +30 -4
  2. package/dist/build.d.ts +2 -2
  3. package/dist/build.d.ts.map +1 -1
  4. package/dist/build.js +109 -30
  5. package/dist/build.js.map +1 -1
  6. package/dist/document/content-formats.d.ts +10 -1
  7. package/dist/document/content-formats.d.ts.map +1 -1
  8. package/dist/document/content-formats.js +44 -8
  9. package/dist/document/content-formats.js.map +1 -1
  10. package/dist/document/structured-content/blocknote.d.ts +1 -1
  11. package/dist/document/structured-content/blocknote.d.ts.map +1 -1
  12. package/dist/document/structured-content/blocknote.js +29 -16
  13. package/dist/document/structured-content/blocknote.js.map +1 -1
  14. package/dist/document/structured-content/callouts.d.ts +42 -0
  15. package/dist/document/structured-content/callouts.d.ts.map +1 -0
  16. package/dist/document/structured-content/callouts.js +82 -0
  17. package/dist/document/structured-content/callouts.js.map +1 -0
  18. package/dist/document/structured-content/fables.d.ts +1 -1
  19. package/dist/document/structured-content/fables.d.ts.map +1 -1
  20. package/dist/document/structured-content/fables.js +1 -1
  21. package/dist/document/structured-content/fables.js.map +1 -1
  22. package/dist/document/structured-content/gutenberg.d.ts +30 -0
  23. package/dist/document/structured-content/gutenberg.d.ts.map +1 -0
  24. package/dist/document/structured-content/gutenberg.js +312 -0
  25. package/dist/document/structured-content/gutenberg.js.map +1 -0
  26. package/dist/document/structured-content/image.d.ts +1 -1
  27. package/dist/document/structured-content/image.d.ts.map +1 -1
  28. package/dist/document/structured-content/image.js +2 -2
  29. package/dist/document/structured-content/image.js.map +1 -1
  30. package/dist/document/structured-content/item-blocks.d.ts +1 -1
  31. package/dist/document/structured-content/item-blocks.d.ts.map +1 -1
  32. package/dist/document/structured-content/item-blocks.js +8 -5
  33. package/dist/document/structured-content/item-blocks.js.map +1 -1
  34. package/dist/document/structured-content/markdown.d.ts +27 -1
  35. package/dist/document/structured-content/markdown.d.ts.map +1 -1
  36. package/dist/document/structured-content/markdown.js +269 -34
  37. package/dist/document/structured-content/markdown.js.map +1 -1
  38. package/dist/document/structured-content/markpub.d.ts +78 -0
  39. package/dist/document/structured-content/markpub.d.ts.map +1 -0
  40. package/dist/document/structured-content/markpub.js +338 -0
  41. package/dist/document/structured-content/markpub.js.map +1 -0
  42. package/dist/document/structured-content/mochott.d.ts +63 -0
  43. package/dist/document/structured-content/mochott.d.ts.map +1 -0
  44. package/dist/document/structured-content/mochott.js +493 -0
  45. package/dist/document/structured-content/mochott.js.map +1 -0
  46. package/dist/document/structured-content/oxa.d.ts +1 -1
  47. package/dist/document/structured-content/oxa.d.ts.map +1 -1
  48. package/dist/document/structured-content/oxa.js +1 -1
  49. package/dist/document/structured-content/oxa.js.map +1 -1
  50. package/dist/document/structured-content/prosemirror.d.ts +1 -1
  51. package/dist/document/structured-content/prosemirror.d.ts.map +1 -1
  52. package/dist/document/structured-content/prosemirror.js +32 -10
  53. package/dist/document/structured-content/prosemirror.js.map +1 -1
  54. package/dist/document/structured-content/text-runs.d.ts +1 -1
  55. package/dist/document/structured-content/text-runs.d.ts.map +1 -1
  56. package/dist/document/structured-content/text-runs.js +2 -2
  57. package/dist/document/structured-content/text-runs.js.map +1 -1
  58. package/dist/document/structured-content/types.d.ts +25 -2
  59. package/dist/document/structured-content/types.d.ts.map +1 -1
  60. package/dist/document/structured-content/types.js.map +1 -1
  61. package/dist/image.d.ts +3 -3
  62. package/dist/image.d.ts.map +1 -1
  63. package/dist/image.js +13 -2
  64. package/dist/image.js.map +1 -1
  65. package/dist/index.d.ts +31 -22
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +23 -15
  68. package/dist/index.js.map +1 -1
  69. package/dist/inline.d.ts +1 -1
  70. package/dist/inline.d.ts.map +1 -1
  71. package/dist/inline.js +2 -2
  72. package/dist/inline.js.map +1 -1
  73. package/dist/internal.js +1 -1
  74. package/dist/internal.js.map +1 -1
  75. package/dist/leaflet/blocks.d.ts +1 -1
  76. package/dist/leaflet/blocks.d.ts.map +1 -1
  77. package/dist/leaflet/blocks.js +3 -3
  78. package/dist/leaflet/blocks.js.map +1 -1
  79. package/dist/leaflet/facets.d.ts +1 -1
  80. package/dist/leaflet/facets.d.ts.map +1 -1
  81. package/dist/leaflet/facets.js +2 -2
  82. package/dist/leaflet/facets.js.map +1 -1
  83. package/dist/leaflet/footnotes.d.ts +1 -1
  84. package/dist/leaflet/footnotes.d.ts.map +1 -1
  85. package/dist/leaflet/footnotes.js +3 -3
  86. package/dist/leaflet/footnotes.js.map +1 -1
  87. package/dist/leaflet/image.d.ts +1 -1
  88. package/dist/leaflet/image.d.ts.map +1 -1
  89. package/dist/leaflet/image.js +2 -2
  90. package/dist/leaflet/image.js.map +1 -1
  91. package/dist/nodes.d.ts +49 -1
  92. package/dist/nodes.d.ts.map +1 -1
  93. package/dist/offprint/blocks.d.ts +1 -1
  94. package/dist/offprint/blocks.d.ts.map +1 -1
  95. package/dist/offprint/blocks.js +8 -5
  96. package/dist/offprint/blocks.js.map +1 -1
  97. package/dist/pckt/blocks.d.ts +1 -1
  98. package/dist/pckt/blocks.d.ts.map +1 -1
  99. package/dist/pckt/blocks.js +5 -5
  100. package/dist/pckt/blocks.js.map +1 -1
  101. package/dist/pckt/image.d.ts +1 -1
  102. package/dist/pckt/image.d.ts.map +1 -1
  103. package/dist/pckt/image.js +3 -3
  104. package/dist/pckt/image.js.map +1 -1
  105. package/package.json +4 -2
@@ -1,7 +1,7 @@
1
- import { isRecord } from "../../internal";
2
- import { utf8ByteLength } from "../../leaflet/utf8";
3
- import { normalizeImageAlt } from "./image";
4
- import { mergeTextRuns, syntheticFacet } from "./text-runs";
1
+ import { isRecord } from "../../internal.js";
2
+ import { utf8ByteLength } from "../../leaflet/utf8.js";
3
+ import { normalizeImageAlt } from "./image.js";
4
+ import { mergeTextRuns, syntheticFacet } from "./text-runs.js";
5
5
  export const BLOCKNOTE_CONTENT = "org.blocknote.document#content";
6
6
  const STYLE_KINDS = {
7
7
  bold: "bold",
@@ -123,20 +123,34 @@ export function blocknoteBlocks(content, contentFormat) {
123
123
  const format = typeof content.$type === "string" ? content.$type : contentFormat;
124
124
  if (format !== BLOCKNOTE_CONTENT)
125
125
  return [];
126
- const blocks = Array.isArray(content.blocks) ? content.blocks : [];
126
+ return blocksFrom(Array.isArray(content.blocks) ? content.blocks : []);
127
+ }
128
+ /**
129
+ * BlockNote nests by hanging a `children` array off the parent block rather
130
+ * than inside the list, so a sub-list is a child of the item above it. Parsing
131
+ * only the top level (as this did before `StructuredListItem` grew `children`)
132
+ * dropped every indented branch.
133
+ */
134
+ function blocksFrom(entries) {
127
135
  const result = [];
128
- for (const entry of blocks) {
136
+ for (const entry of entries) {
129
137
  if (!isRecord(entry))
130
138
  continue;
131
139
  const type = typeof entry.type === "string" ? entry.type : "";
132
140
  const kind = listKind(type);
141
+ const children = blocksFrom(Array.isArray(entry.children) ? entry.children : []);
133
142
  // Group consecutive items of the same list kind into one list block.
134
143
  if (kind) {
135
144
  const text = inlineText(entry);
136
- if (!text)
145
+ if (!text) {
146
+ // An empty item still carries its subtree — keep the content.
147
+ result.push(...children);
137
148
  continue;
149
+ }
138
150
  const previous = result.at(-1);
139
151
  if (kind === "taskList") {
152
+ // `taskList` items have no `children` in the vocabulary, so a subtree
153
+ // under a checklist item follows the list instead of nesting in it.
140
154
  const item = {
141
155
  checked: isRecord(entry.props) && entry.props.checked === true,
142
156
  text,
@@ -145,24 +159,23 @@ export function blocknoteBlocks(content, contentFormat) {
145
159
  previous.items.push(item);
146
160
  else
147
161
  result.push({ items: [item], kind: "taskList" });
148
- }
149
- else if (kind === "bulletList") {
150
- if (previous?.kind === "bulletList")
151
- previous.items.push(text);
152
- else
153
- result.push({ items: [text], kind: "bulletList" });
162
+ result.push(...children);
154
163
  }
155
164
  else {
156
- if (previous?.kind === "orderedList")
157
- previous.items.push(text);
165
+ const item = { text };
166
+ if (children.length > 0)
167
+ item.children = children;
168
+ if (previous?.kind === kind)
169
+ previous.items.push(item);
158
170
  else
159
- result.push({ items: [text], kind: "orderedList" });
171
+ result.push({ items: [item], kind });
160
172
  }
161
173
  continue;
162
174
  }
163
175
  const block = singleBlock(entry);
164
176
  if (block)
165
177
  result.push(block);
178
+ result.push(...children);
166
179
  }
167
180
  return result;
168
181
  }
@@ -1 +1 @@
1
- {"version":3,"file":"blocknote.js","sourceRoot":"","sources":["../../../src/document/structured-content/blocknote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAS5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,gCAAgC,CAAC;AAElE,MAAM,WAAW,GAA2B;IAC1C,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,eAAe;IACvB,SAAS,EAAE,WAAW;CACvB,CAAC;AAEF,SAAS,UAAU,CAAC,MAAe;IACjC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CAC3D,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CACrC,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,GAA4B,EAAE,OAAgB;IAC7D,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC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,IAAI;oBAC9D,IAAI;iBACL,CAAC;gBACF,IAAI,QAAQ,EAAE,IAAI,KAAK,UAAU;oBAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;oBACxD,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;gBACtD,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,GAAuB,EAAE,IAAI,EAAE,CAAC;gBAC1C,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;oBAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;gBAClD,IAAI,QAAQ,EAAE,IAAI,KAAK,IAAI;oBAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;oBAClD,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5C,CAAC;YACD,SAAS;QACX,CAAC;QAED,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,KAAK;YAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * GFM- and Obsidian-style callouts (alerts / admonitions).
3
+ *
4
+ * A callout is a blockquote whose first line is a type marker:
5
+ *
6
+ * ```
7
+ * > [!NOTE]
8
+ * > Body text.
9
+ * ```
10
+ *
11
+ * Obsidian extends it with a fold indicator and a custom title on the marker
12
+ * line — `> [!warning]- Collapsed by default` — where `-` starts closed and `+`
13
+ * starts open.
14
+ *
15
+ * The type keyword is normalized to a small set of visual kinds here rather
16
+ * than in each renderer, so every consumer styles the same twenty-odd aliases
17
+ * the same way.
18
+ *
19
+ * @see https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
20
+ * @see https://help.obsidian.md/callouts
21
+ */
22
+ /** The visual families a callout type can map to; each drives a colour + icon. */
23
+ export type CalloutKind = "note" | "abstract" | "info" | "todo" | "tip" | "success" | "question" | "warning" | "failure" | "danger" | "bug" | "example" | "quote";
24
+ /** Resolve a type keyword to its visual kind (defaults to `note`). */
25
+ export declare function calloutKindForType(type: string): CalloutKind;
26
+ export interface CalloutMarker {
27
+ /** The normalized type keyword, always lowercase (e.g. `note`). */
28
+ type: string;
29
+ kind: CalloutKind;
30
+ /** Author-supplied title from the marker line, when there was one. */
31
+ title?: string;
32
+ /** Set only when a `-`/`+` fold indicator made the callout collapsible. */
33
+ fold?: "open" | "closed";
34
+ /** Length of the matched marker, for slicing it off the body. */
35
+ matchLength: number;
36
+ }
37
+ /**
38
+ * Read a callout marker off the start of a blockquote's leading text, or null
39
+ * when the blockquote is an ordinary quote.
40
+ */
41
+ export declare function parseCalloutMarker(text: string): CalloutMarker | null;
42
+ //# sourceMappingURL=callouts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callouts.d.ts","sourceRoot":"","sources":["../../../src/document/structured-content/callouts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,kFAAkF;AAClF,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,UAAU,GACV,MAAM,GACN,MAAM,GACN,KAAK,GACL,SAAS,GACT,UAAU,GACV,SAAS,GACT,SAAS,GACT,QAAQ,GACR,KAAK,GACL,SAAS,GACT,OAAO,CAAC;AAqCZ,sEAAsE;AACtE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAE5D;AAED,MAAM,WAAW,aAAa;IAC5B,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;IAClB,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IACzB,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAC;CACrB;AAMD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAarE"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * GFM- and Obsidian-style callouts (alerts / admonitions).
3
+ *
4
+ * A callout is a blockquote whose first line is a type marker:
5
+ *
6
+ * ```
7
+ * > [!NOTE]
8
+ * > Body text.
9
+ * ```
10
+ *
11
+ * Obsidian extends it with a fold indicator and a custom title on the marker
12
+ * line — `> [!warning]- Collapsed by default` — where `-` starts closed and `+`
13
+ * starts open.
14
+ *
15
+ * The type keyword is normalized to a small set of visual kinds here rather
16
+ * than in each renderer, so every consumer styles the same twenty-odd aliases
17
+ * the same way.
18
+ *
19
+ * @see https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
20
+ * @see https://help.obsidian.md/callouts
21
+ */
22
+ /**
23
+ * Every recognized keyword (GFM's five plus Obsidian's aliases) mapped to its
24
+ * kind. GFM's `important` renders purple on GitHub, so it maps to `example`;
25
+ * `caution` renders red, so it maps to `danger`.
26
+ */
27
+ const TYPE_TO_KIND = {
28
+ abstract: "abstract",
29
+ attention: "warning",
30
+ bug: "bug",
31
+ caution: "danger",
32
+ check: "success",
33
+ cite: "quote",
34
+ danger: "danger",
35
+ done: "success",
36
+ error: "danger",
37
+ example: "example",
38
+ fail: "failure",
39
+ failure: "failure",
40
+ faq: "question",
41
+ help: "question",
42
+ hint: "tip",
43
+ important: "example",
44
+ info: "info",
45
+ missing: "failure",
46
+ note: "note",
47
+ question: "question",
48
+ quote: "quote",
49
+ success: "success",
50
+ summary: "abstract",
51
+ tip: "tip",
52
+ tldr: "abstract",
53
+ todo: "todo",
54
+ warning: "warning",
55
+ };
56
+ /** Resolve a type keyword to its visual kind (defaults to `note`). */
57
+ export function calloutKindForType(type) {
58
+ return TYPE_TO_KIND[type.toLowerCase()] ?? "note";
59
+ }
60
+ // `[!TYPE]`, an optional -/+ fold indicator, an optional inline title, and the
61
+ // rest of that one line. Anchored to the start of the blockquote's text.
62
+ const MARKER = /^[ \t]*\[!([A-Za-z][\w-]*)\]([+-]?)[ \t]*([^\n]*)(\n|$)/;
63
+ /**
64
+ * Read a callout marker off the start of a blockquote's leading text, or null
65
+ * when the blockquote is an ordinary quote.
66
+ */
67
+ export function parseCalloutMarker(text) {
68
+ const match = MARKER.exec(text);
69
+ if (!match)
70
+ return null;
71
+ const [matched, rawType = "", foldFlag = "", rawTitle = ""] = match;
72
+ const type = rawType.toLowerCase();
73
+ const title = rawTitle.trim();
74
+ return {
75
+ kind: calloutKindForType(type),
76
+ matchLength: matched.length,
77
+ type,
78
+ ...(title ? { title } : {}),
79
+ ...(foldFlag ? { fold: foldFlag === "+" ? "open" : "closed" } : {}),
80
+ };
81
+ }
82
+ //# sourceMappingURL=callouts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callouts.js","sourceRoot":"","sources":["../../../src/document/structured-content/callouts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAkBH;;;;GAIG;AACH,MAAM,YAAY,GAAgC;IAChD,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,SAAS;IACpB,GAAG,EAAE,KAAK;IACV,OAAO,EAAE,QAAQ;IACjB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,OAAO;IACb,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,SAAS;IAClB,GAAG,EAAE,UAAU;IACf,IAAI,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,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpE,CAAC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { StructuredRenderableBlock } from "./types";
1
+ import type { StructuredRenderableBlock } from "./types.js";
2
2
  export declare const FABLES_CONTENT = "ca.justexe.fables.blocks";
3
3
  /** Renderable blocks for a `ca.justexe.fables.blocks` payload. */
4
4
  export declare function fablesBlocks(content: unknown, contentFormat?: string | null): Array<StructuredRenderableBlock>;
@@ -1 +1 @@
1
- {"version":3,"file":"fables.d.ts","sourceRoot":"","sources":["../../../src/document/structured-content/fables.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEzD,eAAO,MAAM,cAAc,6BAA6B,CAAC;AAuCzD,kEAAkE;AAClE,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,EAChB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,GAC5B,KAAK,CAAC,yBAAyB,CAAC,CAalC"}
1
+ {"version":3,"file":"fables.d.ts","sourceRoot":"","sources":["../../../src/document/structured-content/fables.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D,eAAO,MAAM,cAAc,6BAA6B,CAAC;AAuCzD,kEAAkE;AAClE,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,EAChB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,GAC5B,KAAK,CAAC,yBAAyB,CAAC,CAalC"}
@@ -4,7 +4,7 @@
4
4
  * Per-block visual styling (`style`) is intentionally dropped; the reader
5
5
  * applies its own typography.
6
6
  */
7
- import { isRecord } from "../../internal";
7
+ import { isRecord } from "../../internal.js";
8
8
  export const FABLES_CONTENT = "ca.justexe.fables.blocks";
9
9
  function asBlock(value) {
10
10
  if (!isRecord(value) || typeof value.type !== "string")
@@ -1 +1 @@
1
- {"version":3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C,CAAC,CAAC;YACf,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC;QACpC,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,OAAO,OAAO;gBACZ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;gBAChD,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACjD,CAAC;IACH,CAAC;AACH,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,YAAY,CAC1B,OAAgB,EAChB,aAA6B;IAE7B,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC;IAClC,MAAM,MAAM,GACV,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC;IACpE,IAAI,MAAM,KAAK,cAAc;QAAE,OAAO,EAAE,CAAC;IACzC,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAEnE,MAAM,MAAM,GAAqC,EAAE,CAAC;IACpD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,KAAK;YAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * SkyPress (`blog.skypress.content.gutenberg`) — WordPress Gutenberg blocks.
3
+ *
4
+ * A Gutenberg block is `{ name, attributes, innerBlocks }`, where the inline
5
+ * body lives in `attributes.content` as an **HTML fragment** (`<strong>`,
6
+ * `<em>`, `<a href>`, `<code>`, `<br>`, entities).
7
+ *
8
+ * Rather than reassemble that into an HTML string — which would force every
9
+ * framework renderer to ship a sanitizer before it could touch the DOM — the
10
+ * block names map onto the shared {@link StructuredRenderableBlock} vocabulary
11
+ * and the inline HTML is *parsed away* into plaintext plus byte-indexed
12
+ * facets, exactly like the ProseMirror and BlockNote parsers do. No markup
13
+ * survives this module, so there is nothing downstream to sanitize.
14
+ *
15
+ * Blocks whose whole point is arbitrary embedded markup (`core/html`) fall
16
+ * through to their text content; `<script>`/`<style>`/`<template>` subtrees are
17
+ * dropped rather than flattened into visible text.
18
+ */
19
+ import type { StructuredRenderableBlock, StructuredText } from "./types.js";
20
+ export declare const GUTENBERG_CONTENT = "blog.skypress.content.gutenberg";
21
+ /** Rich text for a Gutenberg inline HTML fragment. */
22
+ export declare function gutenbergInlineText(html: string): StructuredText;
23
+ /**
24
+ * Renderable blocks for a `blog.skypress.content.gutenberg` payload, or null
25
+ * when the format doesn't match or the body is empty. Registered in
26
+ * `STRUCTURED_FORMAT_PARSERS` so `buildRenderTree` handles SkyPress like any
27
+ * other structured format.
28
+ */
29
+ export declare function gutenbergBlocks(content: unknown, contentFormat?: string | null): Array<StructuredRenderableBlock> | null;
30
+ //# sourceMappingURL=gutenberg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gutenberg.d.ts","sourceRoot":"","sources":["../../../src/document/structured-content/gutenberg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5E,eAAO,MAAM,iBAAiB,oCAAoC,CAAC;AAkKnE,sDAAsD;AACtD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAehE;AA+JD;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,GAC5B,KAAK,CAAC,yBAAyB,CAAC,GAAG,IAAI,CAUzC"}
@@ -0,0 +1,312 @@
1
+ /**
2
+ * SkyPress (`blog.skypress.content.gutenberg`) — WordPress Gutenberg blocks.
3
+ *
4
+ * A Gutenberg block is `{ name, attributes, innerBlocks }`, where the inline
5
+ * body lives in `attributes.content` as an **HTML fragment** (`<strong>`,
6
+ * `<em>`, `<a href>`, `<code>`, `<br>`, entities).
7
+ *
8
+ * Rather than reassemble that into an HTML string — which would force every
9
+ * framework renderer to ship a sanitizer before it could touch the DOM — the
10
+ * block names map onto the shared {@link StructuredRenderableBlock} vocabulary
11
+ * and the inline HTML is *parsed away* into plaintext plus byte-indexed
12
+ * facets, exactly like the ProseMirror and BlockNote parsers do. No markup
13
+ * survives this module, so there is nothing downstream to sanitize.
14
+ *
15
+ * Blocks whose whole point is arbitrary embedded markup (`core/html`) fall
16
+ * through to their text content; `<script>`/`<style>`/`<template>` subtrees are
17
+ * dropped rather than flattened into visible text.
18
+ */
19
+ import { isRecord } from "../../internal.js";
20
+ import { utf8ByteLength } from "../../leaflet/utf8.js";
21
+ import { syntheticFacet } from "./text-runs.js";
22
+ export const GUTENBERG_CONTENT = "blog.skypress.content.gutenberg";
23
+ // ---------------------------------------------------------------------------
24
+ // Inline HTML → plaintext + facets
25
+ // ---------------------------------------------------------------------------
26
+ /** Inline tags that carry a formatting mark, keyed to its facet suffix. */
27
+ const INLINE_MARKS = {
28
+ b: "bold",
29
+ code: "code",
30
+ del: "strikethrough",
31
+ em: "italic",
32
+ i: "italic",
33
+ ins: "underline",
34
+ kbd: "code",
35
+ mark: "highlight",
36
+ s: "strikethrough",
37
+ strike: "strikethrough",
38
+ strong: "bold",
39
+ u: "underline",
40
+ };
41
+ /** Tags that never have a closing partner, so they must not open a frame. */
42
+ const VOID_TAGS = new Set([
43
+ "area",
44
+ "base",
45
+ "br",
46
+ "col",
47
+ "embed",
48
+ "hr",
49
+ "img",
50
+ "input",
51
+ "link",
52
+ "meta",
53
+ "source",
54
+ "track",
55
+ "wbr",
56
+ ]);
57
+ const NAMED_ENTITIES = {
58
+ amp: "&",
59
+ apos: "'",
60
+ gt: ">",
61
+ lt: "<",
62
+ nbsp: " ",
63
+ quot: '"',
64
+ };
65
+ function decodeEntities(text) {
66
+ return text.replaceAll(/&(#x?[\da-f]+|[a-z]+);/gi, (match, entity) => {
67
+ if (entity.startsWith("#x") || entity.startsWith("#X")) {
68
+ const code = Number.parseInt(entity.slice(2), 16);
69
+ return Number.isNaN(code) ? match : String.fromCodePoint(code);
70
+ }
71
+ if (entity.startsWith("#")) {
72
+ const code = Number.parseInt(entity.slice(1), 10);
73
+ return Number.isNaN(code) ? match : String.fromCodePoint(code);
74
+ }
75
+ return NAMED_ENTITIES[entity.toLowerCase()] ?? match;
76
+ });
77
+ }
78
+ /** Strip comments and non-content subtrees before any tag walking. */
79
+ function stripNonContent(html) {
80
+ return html
81
+ .replaceAll(/<(script|style|template)\b[\S\s]*?<\/\1>/gi, "")
82
+ .replaceAll(/<!--[\S\s]*?-->/g, "");
83
+ }
84
+ const ATTR_PATTERN = String.raw `("([^"]*)"|'([^']*)'|([^\s"'>]+))`;
85
+ function attrValue(attrs, name) {
86
+ const match = new RegExp(`\\b${name}\\s*=\\s*${ATTR_PATTERN}`, "i").exec(attrs);
87
+ if (!match)
88
+ return undefined;
89
+ const raw = match[2] ?? match[3] ?? match[4];
90
+ const value = raw ? decodeEntities(raw).trim() : "";
91
+ return value || undefined;
92
+ }
93
+ const TAG_PATTERN = /<(\/?)([a-z][\da-z]*)\b((?:"[^"]*"|'[^']*'|[^>])*?)\/?>/gi;
94
+ /** Flatten an inline HTML fragment into styled runs. */
95
+ function collectInlineRuns(html) {
96
+ const runs = [];
97
+ const openKinds = [];
98
+ const openLinks = [];
99
+ const stack = [];
100
+ const source = stripNonContent(html);
101
+ const push = (text) => {
102
+ if (!text)
103
+ return;
104
+ runs.push({ kinds: [...openKinds], link: openLinks.at(-1), text });
105
+ };
106
+ const pattern = new RegExp(TAG_PATTERN.source, TAG_PATTERN.flags);
107
+ let cursor = 0;
108
+ let match = pattern.exec(source);
109
+ while (match !== null) {
110
+ push(decodeEntities(source.slice(cursor, match.index)));
111
+ cursor = pattern.lastIndex;
112
+ const tag = (match[2] ?? "").toLowerCase();
113
+ if (match[1] === "/") {
114
+ closeTag(tag, stack, openKinds, openLinks);
115
+ }
116
+ else if (tag === "br") {
117
+ push("\n");
118
+ }
119
+ else if (!VOID_TAGS.has(tag)) {
120
+ const kind = INLINE_MARKS[tag];
121
+ const href = tag === "a" ? attrValue(match[3] ?? "", "href") : undefined;
122
+ if (kind)
123
+ openKinds.push(kind);
124
+ if (href)
125
+ openLinks.push(href);
126
+ stack.push({ href, kind, tag });
127
+ }
128
+ match = pattern.exec(source);
129
+ }
130
+ push(decodeEntities(source.slice(cursor)));
131
+ return runs;
132
+ }
133
+ /** Unwind to the most recent matching open tag (unbalanced closers ignored). */
134
+ function closeTag(tag, stack, openKinds, openLinks) {
135
+ const index = stack.findLastIndex((frame) => frame.tag === tag);
136
+ if (index === -1)
137
+ return;
138
+ for (const frame of stack.slice(index)) {
139
+ if (frame.kind) {
140
+ const at = openKinds.lastIndexOf(frame.kind);
141
+ if (at !== -1)
142
+ openKinds.splice(at, 1);
143
+ }
144
+ if (frame.href) {
145
+ const at = openLinks.lastIndexOf(frame.href);
146
+ if (at !== -1)
147
+ openLinks.splice(at, 1);
148
+ }
149
+ }
150
+ stack.length = index;
151
+ }
152
+ /** Rich text for a Gutenberg inline HTML fragment. */
153
+ export function gutenbergInlineText(html) {
154
+ let plaintext = "";
155
+ const facets = [];
156
+ for (const run of collectInlineRuns(html)) {
157
+ const byteStart = utf8ByteLength(plaintext);
158
+ plaintext += run.text;
159
+ const facet = syntheticFacet(byteStart, utf8ByteLength(plaintext), run.kinds, run.link);
160
+ if (facet)
161
+ facets.push(facet);
162
+ }
163
+ return facets.length > 0 ? { facets, plaintext } : { plaintext };
164
+ }
165
+ /** Plaintext only — for code blocks, where marks would be meaningless. */
166
+ function gutenbergPlaintext(html) {
167
+ return collectInlineRuns(html)
168
+ .map((run) => run.text)
169
+ .join("");
170
+ }
171
+ // ---------------------------------------------------------------------------
172
+ // Blocks
173
+ // ---------------------------------------------------------------------------
174
+ function attributesOf(block) {
175
+ return isRecord(block.attributes) ? block.attributes : {};
176
+ }
177
+ function childrenOf(block) {
178
+ return Array.isArray(block.innerBlocks)
179
+ ? block.innerBlocks.filter((child) => isRecord(child))
180
+ : [];
181
+ }
182
+ function stringAttr(attributes, key) {
183
+ const value = attributes[key];
184
+ return typeof value === "string" ? value : "";
185
+ }
186
+ function textBlock(html) {
187
+ const text = gutenbergInlineText(html);
188
+ return text.plaintext.trim() ? [{ kind: "text", text }] : [];
189
+ }
190
+ /** `<li>…</li>` items from the legacy `core/list` `values` attribute. */
191
+ function legacyListItems(values) {
192
+ return [...values.matchAll(/<li\b[^>]*>([\S\s]*?)<\/li>/gi)]
193
+ .map((match) => gutenbergInlineText(match[1] ?? ""))
194
+ .filter((text) => text.plaintext.trim());
195
+ }
196
+ function listBlock(block) {
197
+ const attributes = attributesOf(block);
198
+ const items = childrenOf(block)
199
+ .filter((child) => child.name === "core/list-item")
200
+ .map((child) => gutenbergInlineText(stringAttr(attributesOf(child), "content")))
201
+ .filter((text) => text.plaintext.trim());
202
+ const resolved = items.length > 0
203
+ ? items
204
+ : legacyListItems(stringAttr(attributes, "values"));
205
+ if (resolved.length === 0)
206
+ return [];
207
+ const listItems = resolved.map((text) => ({ text }));
208
+ if (attributes.ordered === true) {
209
+ const start = attributes.start;
210
+ return [
211
+ {
212
+ items: listItems,
213
+ kind: "orderedList",
214
+ start: typeof start === "number" ? start : undefined,
215
+ },
216
+ ];
217
+ }
218
+ return [{ items: listItems, kind: "bulletList" }];
219
+ }
220
+ function quoteBlock(block, content) {
221
+ const attributes = attributesOf(block);
222
+ const inner = childrenOf(block).flatMap((child) => gutenbergBlock(child));
223
+ const blocks = inner.length > 0
224
+ ? inner
225
+ : textBlock(content || stringAttr(attributes, "value"));
226
+ return blocks.length > 0 ? [{ blocks, kind: "blockquote" }] : [];
227
+ }
228
+ function imageBlock(attributes) {
229
+ const url = stringAttr(attributes, "url").trim();
230
+ if (!url)
231
+ return [];
232
+ const caption = gutenbergInlineText(stringAttr(attributes, "caption")).plaintext.trim();
233
+ const alt = stringAttr(attributes, "alt").trim();
234
+ return [
235
+ {
236
+ alt: alt || undefined,
237
+ caption: caption || undefined,
238
+ externalSrc: url,
239
+ kind: "image",
240
+ },
241
+ ];
242
+ }
243
+ function headingLevel(attributes) {
244
+ const level = attributes.level;
245
+ return typeof level === "number" && level >= 1 && level <= 6 ? level : 2;
246
+ }
247
+ /** Map one Gutenberg block (and its children) onto the shared vocabulary. */
248
+ function gutenbergBlock(block) {
249
+ const name = typeof block.name === "string" ? block.name : "";
250
+ const attributes = attributesOf(block);
251
+ const content = stringAttr(attributes, "content");
252
+ switch (name) {
253
+ case "core/paragraph":
254
+ case "core/list-item": {
255
+ return textBlock(content);
256
+ }
257
+ case "core/heading": {
258
+ const text = gutenbergInlineText(content);
259
+ return text.plaintext.trim()
260
+ ? [{ kind: "heading", level: headingLevel(attributes), text }]
261
+ : [];
262
+ }
263
+ case "core/list": {
264
+ return listBlock(block);
265
+ }
266
+ case "core/quote":
267
+ case "core/pullquote": {
268
+ return quoteBlock(block, content);
269
+ }
270
+ case "core/code":
271
+ case "core/preformatted": {
272
+ const plaintext = gutenbergPlaintext(content);
273
+ return plaintext.trim() ? [{ kind: "code", plaintext }] : [];
274
+ }
275
+ case "core/separator": {
276
+ return [{ kind: "horizontalRule" }];
277
+ }
278
+ case "core/image": {
279
+ return imageBlock(attributes);
280
+ }
281
+ case "core/embed": {
282
+ const src = stringAttr(attributes, "url").trim();
283
+ return src ? [{ kind: "website", src }] : [];
284
+ }
285
+ default: {
286
+ // Layout wrappers (group, columns, …) and unknown blocks: keep whatever
287
+ // body they carry rather than dropping the subtree.
288
+ if (content.trim())
289
+ return textBlock(content);
290
+ return childrenOf(block).flatMap((child) => gutenbergBlock(child));
291
+ }
292
+ }
293
+ }
294
+ /**
295
+ * Renderable blocks for a `blog.skypress.content.gutenberg` payload, or null
296
+ * when the format doesn't match or the body is empty. Registered in
297
+ * `STRUCTURED_FORMAT_PARSERS` so `buildRenderTree` handles SkyPress like any
298
+ * other structured format.
299
+ */
300
+ export function gutenbergBlocks(content, contentFormat) {
301
+ if (!isRecord(content))
302
+ return null;
303
+ const format = typeof content.$type === "string" ? content.$type : contentFormat;
304
+ if (format !== GUTENBERG_CONTENT)
305
+ return null;
306
+ const blocks = Array.isArray(content.blocks)
307
+ ? content.blocks.filter((block) => isRecord(block))
308
+ : [];
309
+ const mapped = blocks.flatMap((block) => gutenbergBlock(block));
310
+ return mapped.length > 0 ? mapped : null;
311
+ }
312
+ //# sourceMappingURL=gutenberg.js.map