@knpkv/confluence-to-markdown 0.5.0 → 0.6.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 (108) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +45 -10
  3. package/dist/ConfluenceAuth.d.ts.map +1 -1
  4. package/dist/ConfluenceAuth.js +12 -22
  5. package/dist/ConfluenceAuth.js.map +1 -1
  6. package/dist/ConfluenceClient.d.ts +13 -3
  7. package/dist/ConfluenceClient.d.ts.map +1 -1
  8. package/dist/ConfluenceClient.js +34 -70
  9. package/dist/ConfluenceClient.js.map +1 -1
  10. package/dist/ConfluenceError.d.ts +12 -12
  11. package/dist/GitError.d.ts +5 -5
  12. package/dist/GitService.d.ts.map +1 -1
  13. package/dist/GitService.js +0 -3
  14. package/dist/GitService.js.map +1 -1
  15. package/dist/SchemaConverterError.d.ts +3 -3
  16. package/dist/ast/BlockNode.d.ts +48 -33
  17. package/dist/ast/BlockNode.d.ts.map +1 -1
  18. package/dist/ast/BlockNode.js +11 -2
  19. package/dist/ast/BlockNode.js.map +1 -1
  20. package/dist/ast/Document.d.ts +30 -2
  21. package/dist/ast/Document.d.ts.map +1 -1
  22. package/dist/parsers/ConfluenceParser.d.ts.map +1 -1
  23. package/dist/parsers/ConfluenceParser.js +7 -12
  24. package/dist/parsers/ConfluenceParser.js.map +1 -1
  25. package/dist/parsers/MarkdownParser.js +8 -117
  26. package/dist/parsers/MarkdownParser.js.map +1 -1
  27. package/dist/parsers/preprocessing/ConfluencePreprocessing.d.ts +23 -0
  28. package/dist/parsers/preprocessing/ConfluencePreprocessing.d.ts.map +1 -0
  29. package/dist/parsers/preprocessing/ConfluencePreprocessing.js +323 -0
  30. package/dist/parsers/preprocessing/ConfluencePreprocessing.js.map +1 -0
  31. package/dist/parsers/preprocessing/index.d.ts +7 -0
  32. package/dist/parsers/preprocessing/index.d.ts.map +1 -0
  33. package/dist/parsers/preprocessing/index.js +7 -0
  34. package/dist/parsers/preprocessing/index.js.map +1 -0
  35. package/dist/schemas/preprocessing/ConfluencePreprocessor.d.ts +29 -0
  36. package/dist/schemas/preprocessing/ConfluencePreprocessor.d.ts.map +1 -1
  37. package/dist/schemas/preprocessing/ConfluencePreprocessor.js +5 -15
  38. package/dist/schemas/preprocessing/ConfluencePreprocessor.js.map +1 -1
  39. package/dist/serializers/ConfluenceSerializer.js +0 -9
  40. package/dist/serializers/ConfluenceSerializer.js.map +1 -1
  41. package/dist/serializers/MarkdownSerializer.js +9 -49
  42. package/dist/serializers/MarkdownSerializer.js.map +1 -1
  43. package/package.json +35 -26
  44. package/src/AdfPlaceholders.ts +266 -0
  45. package/src/AdfSchemaValidator.ts +67 -0
  46. package/src/AdfWalker.ts +511 -0
  47. package/src/AtlaskitTransformers.ts +72 -0
  48. package/src/ConfluenceClient.ts +4 -4
  49. package/src/ConfluenceError.ts +65 -3
  50. package/src/MarkdownConverter.ts +106 -139
  51. package/src/Schemas.ts +4 -4
  52. package/src/SyncEngine.ts +130 -83
  53. package/src/atlaskit-adf-schema.d.ts +3 -0
  54. package/src/commands/clone.ts +8 -1
  55. package/src/commands/layers.ts +11 -4
  56. package/src/index.ts +3 -18
  57. package/test/AdfPlaceholders.test.ts +295 -0
  58. package/test/AdfSchemaValidator.test.ts +34 -0
  59. package/test/AdfWalker.test.ts +530 -0
  60. package/test/AtlaskitTransformers.test.ts +25 -0
  61. package/test/MarkdownConverter.test.ts +120 -105
  62. package/test/RoundTrip.test.ts +266 -0
  63. package/LICENSE +0 -21
  64. package/src/SchemaConverterError.ts +0 -108
  65. package/src/ast/BlockNode.ts +0 -469
  66. package/src/ast/Document.ts +0 -90
  67. package/src/ast/InlineNode.ts +0 -323
  68. package/src/ast/MacroNode.ts +0 -245
  69. package/src/ast/index.ts +0 -83
  70. package/src/parsers/ConfluenceParser.ts +0 -956
  71. package/src/parsers/MarkdownParser.ts +0 -1338
  72. package/src/parsers/index.ts +0 -8
  73. package/src/schemas/ConfluenceSchema.ts +0 -56
  74. package/src/schemas/ConversionSchema.ts +0 -318
  75. package/src/schemas/MarkdownSchema.ts +0 -56
  76. package/src/schemas/hast/HastFromHtml.ts +0 -153
  77. package/src/schemas/hast/HastSchema.ts +0 -274
  78. package/src/schemas/hast/index.ts +0 -35
  79. package/src/schemas/index.ts +0 -20
  80. package/src/schemas/mdast/MdastFromMarkdown.ts +0 -118
  81. package/src/schemas/mdast/MdastSchema.ts +0 -566
  82. package/src/schemas/mdast/index.ts +0 -59
  83. package/src/schemas/mdast/mdastToString.ts +0 -102
  84. package/src/schemas/nodes/block/BlockSchema.ts +0 -773
  85. package/src/schemas/nodes/block/index.ts +0 -13
  86. package/src/schemas/nodes/index.ts +0 -20
  87. package/src/schemas/nodes/inline/InlineSchema.ts +0 -523
  88. package/src/schemas/nodes/inline/index.ts +0 -14
  89. package/src/schemas/nodes/macro/MacroSchema.ts +0 -226
  90. package/src/schemas/nodes/macro/index.ts +0 -6
  91. package/src/schemas/preprocessing/ConfluencePreprocessor.ts +0 -455
  92. package/src/schemas/preprocessing/index.ts +0 -8
  93. package/src/serializers/ConfluenceSerializer.ts +0 -737
  94. package/src/serializers/MarkdownSerializer.ts +0 -543
  95. package/src/serializers/index.ts +0 -8
  96. package/test/ast/BlockNode.test.ts +0 -265
  97. package/test/ast/Document.test.ts +0 -126
  98. package/test/ast/InlineNode.test.ts +0 -161
  99. package/test/fixtures/integration-test.html.fixture +0 -103
  100. package/test/fixtures/integration-test.md.expected +0 -257
  101. package/test/parsers/ConfluenceParser.test.ts +0 -452
  102. package/test/schemas/ConfluencePreprocessor.test.ts +0 -180
  103. package/test/schemas/ConversionSchema.test.ts +0 -159
  104. package/test/schemas/HastSchema.test.ts +0 -138
  105. package/test/schemas/MdastSchema.test.ts +0 -145
  106. package/test/schemas/nodes/block/BlockSchema.test.ts +0 -173
  107. package/test/schemas/nodes/inline/InlineSchema.test.ts +0 -198
  108. package/test/schemas/nodes/macro/MacroSchema.test.ts +0 -142
@@ -1,543 +0,0 @@
1
- /**
2
- * Serializer for AST to Markdown.
3
- *
4
- * @module
5
- */
6
- import * as Effect from "effect/Effect"
7
- import type { CodeBlock, Heading, Image, Paragraph, Table, ThematicBreak, UnsupportedBlock } from "../ast/BlockNode.js"
8
- import type { Document, DocumentNode } from "../ast/Document.js"
9
- import type { InlineNode } from "../ast/InlineNode.js"
10
- import type { SerializeError } from "../SchemaConverterError.js"
11
-
12
- /**
13
- * Serialize Document AST to Markdown.
14
- *
15
- * @example
16
- * ```typescript
17
- * import { serializeToMarkdown } from "@knpkv/confluence-to-markdown/serializers/MarkdownSerializer"
18
- * import { makeDocument, Heading, Text } from "@knpkv/confluence-to-markdown/ast"
19
- * import { Effect } from "effect"
20
- *
21
- * Effect.gen(function* () {
22
- * const doc = makeDocument([
23
- * new Heading({ level: 1, children: [new Text({ value: "Title" })] })
24
- * ])
25
- * const md = yield* serializeToMarkdown(doc)
26
- * console.log(md) // # Title
27
- * })
28
- * ```
29
- *
30
- * @category Serializers
31
- */
32
- export interface SerializeOptions {
33
- /** Include raw Confluence HTML for lossless roundtrip. Default: true */
34
- readonly includeRawSource?: boolean
35
- }
36
-
37
- export const serializeToMarkdown = (
38
- doc: Document,
39
- options: SerializeOptions = {}
40
- ): Effect.Effect<string, SerializeError> =>
41
- Effect.gen(function*() {
42
- const { includeRawSource = true } = options
43
- const parts: Array<string> = []
44
- for (const node of doc.children) {
45
- const serialized = yield* serializeDocumentNode(node)
46
- parts.push(serialized)
47
- }
48
-
49
- const content = parts.join("\n\n")
50
-
51
- // Embed rawConfluence in comment for 1-to-1 roundtrip preservation
52
- if (includeRawSource && doc.rawConfluence !== undefined) {
53
- // Encode entire raw HTML for roundtrip
54
- const encoded = Buffer.from(doc.rawConfluence, "utf-8").toString("base64")
55
- return `${content}\n\n<!--cf:raw:${encoded}-->`
56
- }
57
-
58
- return content
59
- })
60
-
61
- /**
62
- * Serialize a document node to Markdown.
63
- */
64
- const serializeDocumentNode = (node: DocumentNode): Effect.Effect<string, SerializeError> =>
65
- Effect.gen(function*() {
66
- switch (node._tag) {
67
- // Block nodes
68
- case "Heading":
69
- return yield* serializeHeading(node)
70
- case "Paragraph":
71
- return yield* serializeParagraph({
72
- children: node.children,
73
- alignment: node.alignment,
74
- indent: node.indent
75
- })
76
- case "CodeBlock":
77
- return serializeCodeBlock(node)
78
- case "ThematicBreak":
79
- return "---"
80
- case "Image":
81
- return serializeImage(node)
82
- case "Table":
83
- return yield* serializeTable(node)
84
- case "List":
85
- return yield* serializeList(node)
86
- case "BlockQuote":
87
- return yield* serializeBlockQuote(node)
88
- case "UnsupportedBlock":
89
- return node.rawMarkdown || node.rawHtml || ""
90
-
91
- // Macro nodes
92
- case "InfoPanel":
93
- return yield* serializeInfoPanel(node)
94
- case "ExpandMacro":
95
- return yield* serializeExpandMacro(node)
96
- case "TocMacro":
97
- return serializeTocMacro(node)
98
- case "CodeMacro":
99
- return serializeCodeMacro(node)
100
- case "StatusMacro":
101
- return serializeStatusMacro(node)
102
- case "TaskList":
103
- return yield* serializeTaskList(node.children)
104
-
105
- default:
106
- return ""
107
- }
108
- })
109
-
110
- /**
111
- * Serialize heading.
112
- */
113
- const serializeHeading = (
114
- node: { level: 1 | 2 | 3 | 4 | 5 | 6; children: ReadonlyArray<InlineNode> }
115
- ): Effect.Effect<string, SerializeError> =>
116
- Effect.gen(function*() {
117
- const prefix = "#".repeat(node.level)
118
- const content = yield* serializeInlineNodes(node.children)
119
- return `${prefix} ${content}`
120
- })
121
-
122
- /**
123
- * Serialize paragraph.
124
- */
125
- const serializeParagraph = (
126
- node: {
127
- children: ReadonlyArray<InlineNode>
128
- alignment?: "left" | "center" | "right" | undefined
129
- indent?: number | undefined
130
- }
131
- ): Effect.Effect<string, SerializeError> =>
132
- Effect.gen(function*() {
133
- const content = yield* serializeInlineNodes(node.children)
134
- // If has alignment or indent, wrap in HTML div for roundtrip
135
- if (node.alignment || node.indent) {
136
- const styles: Array<string> = []
137
- if (node.alignment) styles.push(`text-align: ${node.alignment};`)
138
- if (node.indent) styles.push(`margin-left: ${node.indent}px;`)
139
- return `<p style="${styles.join(" ")}">${content}</p>`
140
- }
141
- return content
142
- })
143
-
144
- /**
145
- * Serialize code block.
146
- */
147
- const serializeCodeBlock = (node: { code: string; language?: string | undefined }): string => {
148
- const lang = node.language || ""
149
- return `\`\`\`${lang}\n${node.code}\n\`\`\``
150
- }
151
-
152
- /**
153
- * Serialize image (supports both URL and Confluence attachments).
154
- * Uses comment-encoding for attachments to preserve roundtrip fidelity.
155
- */
156
- const serializeImage = (node: {
157
- src?: string | undefined
158
- attachment?: { filename: string; version?: number | undefined } | undefined
159
- alt?: string | undefined
160
- title?: string | undefined
161
- align?: string | undefined
162
- width?: number | undefined
163
- }): string => {
164
- // If image has attachment or align/width, use comment encoding for roundtrip
165
- if (node.attachment || node.align || node.width) {
166
- const parts: Array<string> = []
167
- if (node.attachment) {
168
- parts.push(`f=${encodeURIComponent(node.attachment.filename)}`)
169
- if (node.attachment.version) parts.push(`v=${node.attachment.version}`)
170
- }
171
- if (node.src) parts.push(`s=${encodeURIComponent(node.src)}`)
172
- if (node.alt) parts.push(`a=${encodeURIComponent(node.alt)}`)
173
- if (node.title) parts.push(`t=${encodeURIComponent(node.title)}`)
174
- if (node.align) parts.push(`al=${node.align}`)
175
- if (node.width) parts.push(`w=${node.width}`)
176
- return `<!--cf:image:${parts.join("|")}-->`
177
- }
178
-
179
- // Simple external image - use markdown syntax
180
- const alt = node.alt || ""
181
- const title = node.title ? ` "${node.title}"` : ""
182
- const src = node.src || ""
183
- return `![${alt}](${src}${title})`
184
- }
185
-
186
- /**
187
- * Serialize table.
188
- */
189
- const serializeTable = (
190
- node: {
191
- header?: { cells: ReadonlyArray<{ children: ReadonlyArray<InlineNode> }> } | undefined
192
- rows: ReadonlyArray<{ cells: ReadonlyArray<{ children: ReadonlyArray<InlineNode> }> }>
193
- }
194
- ): Effect.Effect<string, SerializeError> =>
195
- Effect.gen(function*() {
196
- const lines: Array<string> = []
197
-
198
- // Markdown tables require a header divider. When the source had no <thead>,
199
- // emit a synthetic empty header so the table still renders. A leading
200
- // <!--cf:synth-thead--> marker discriminates it from a legitimate empty
201
- // header — MarkdownParser strips the marker and drops only that synthetic row,
202
- // so a real Confluence <thead> with empty <th>s round-trips intact.
203
- const columnCount = node.header?.cells.length ?? node.rows[0]?.cells.length ?? 0
204
- const synthMarker = "<!--cf:synth-thead-->"
205
- let prefix = ""
206
-
207
- if (node.header) {
208
- const headerCells: Array<string> = []
209
- for (const cell of node.header.cells) {
210
- headerCells.push(yield* serializeInlineNodes(cell.children))
211
- }
212
- lines.push(`| ${headerCells.join(" | ")} |`)
213
- lines.push(`| ${headerCells.map(() => "---").join(" | ")} |`)
214
- } else if (columnCount > 0) {
215
- prefix = `${synthMarker}\n\n`
216
- lines.push(`| ${Array(columnCount).fill("").join(" | ")} |`)
217
- lines.push(`| ${Array(columnCount).fill("---").join(" | ")} |`)
218
- }
219
-
220
- // Body rows
221
- for (const row of node.rows) {
222
- const cells: Array<string> = []
223
- for (const cell of row.cells) {
224
- cells.push(yield* serializeInlineNodes(cell.children))
225
- }
226
- lines.push(`| ${cells.join(" | ")} |`)
227
- }
228
-
229
- return `${prefix}${lines.join("\n")}`
230
- })
231
-
232
- // Simple block type for list items (allows nested Lists for sub-bullets).
233
- type SimpleBlock =
234
- | Heading
235
- | Paragraph
236
- | CodeBlock
237
- | ThematicBreak
238
- | Image
239
- | Table
240
- | UnsupportedBlock
241
- | NestedList
242
-
243
- // Structural shape of a nested list inside a list item.
244
- type NestedList = {
245
- readonly _tag: "List"
246
- readonly ordered: boolean
247
- readonly start?: number | undefined
248
- readonly children: ReadonlyArray<ListItemType>
249
- }
250
-
251
- // List item type
252
- type ListItemType = {
253
- readonly _tag: "ListItem"
254
- readonly checked?: boolean | undefined
255
- readonly children: ReadonlyArray<SimpleBlock>
256
- }
257
-
258
- /**
259
- * Serialize list.
260
- */
261
- const serializeList = (
262
- node: { ordered: boolean; start?: number | undefined; children: ReadonlyArray<ListItemType> }
263
- ): Effect.Effect<string, SerializeError> =>
264
- Effect.gen(function*() {
265
- const lines: Array<string> = []
266
- let counter = node.start || 1
267
-
268
- for (const item of node.children) {
269
- const prefix = node.ordered ? `${counter}.` : "-"
270
- const checkbox = item.checked !== undefined ? (item.checked ? "[x] " : "[ ] ") : ""
271
-
272
- // Serialize item content
273
- const itemParts: Array<string> = []
274
- for (const child of item.children) {
275
- const serialized = yield* serializeSimpleBlock(child)
276
- itemParts.push(serialized)
277
- }
278
-
279
- const content = itemParts.join("\n")
280
- const indentedContent = content
281
- .split("\n")
282
- .map((line, i) => (i === 0 ? `${prefix} ${checkbox}${line}` : ` ${line}`))
283
- .join("\n")
284
-
285
- lines.push(indentedContent)
286
- counter++
287
- }
288
-
289
- return lines.join("\n")
290
- })
291
-
292
- /**
293
- * Serialize simple block (for nested content).
294
- */
295
- const serializeSimpleBlock = (node: SimpleBlock): Effect.Effect<string, SerializeError> =>
296
- Effect.gen(function*() {
297
- switch (node._tag) {
298
- case "Heading":
299
- return yield* serializeHeading(
300
- node as unknown as { level: 1 | 2 | 3 | 4 | 5 | 6; children: ReadonlyArray<InlineNode> }
301
- )
302
- case "Paragraph":
303
- return yield* serializeParagraph(node as unknown as { children: ReadonlyArray<InlineNode> })
304
- case "CodeBlock":
305
- return serializeCodeBlock(node as unknown as { code: string; language?: string | undefined })
306
- case "ThematicBreak":
307
- return "---"
308
- case "Image":
309
- return serializeImage(node as unknown as { src: string; alt?: string | undefined; title?: string | undefined })
310
- case "Table":
311
- return yield* serializeTable(
312
- node as unknown as {
313
- header?: { cells: ReadonlyArray<{ children: ReadonlyArray<InlineNode> }> } | undefined
314
- rows: ReadonlyArray<{ cells: ReadonlyArray<{ children: ReadonlyArray<InlineNode> }> }>
315
- }
316
- )
317
- case "UnsupportedBlock": {
318
- const unsupported = node as unknown as { rawMarkdown?: string; rawHtml?: string }
319
- return unsupported.rawMarkdown || unsupported.rawHtml || ""
320
- }
321
- case "List":
322
- return yield* serializeList(node)
323
- default:
324
- return ""
325
- }
326
- })
327
-
328
- /**
329
- * Serialize block quote.
330
- */
331
- const serializeBlockQuote = (
332
- node: { children: ReadonlyArray<SimpleBlock> }
333
- ): Effect.Effect<string, SerializeError> =>
334
- Effect.gen(function*() {
335
- const lines: Array<string> = []
336
- for (const child of node.children) {
337
- const serialized = yield* serializeSimpleBlock(child as SimpleBlock)
338
- const quoted = serialized.split("\n").map((line) => `> ${line}`).join("\n")
339
- lines.push(quoted)
340
- }
341
- return lines.join("\n>\n")
342
- })
343
-
344
- /**
345
- * Serialize info panel to container syntax.
346
- */
347
- const serializeInfoPanel = (
348
- node: { panelType: string; title?: string | undefined; children: ReadonlyArray<SimpleBlock> }
349
- ): Effect.Effect<string, SerializeError> =>
350
- Effect.gen(function*() {
351
- const type = node.panelType
352
- const title = node.title ? ` ${node.title}` : ""
353
- const lines: Array<string> = [`:::${type}${title}`]
354
-
355
- for (const child of node.children) {
356
- const serialized = yield* serializeSimpleBlock(child as SimpleBlock)
357
- lines.push(serialized)
358
- }
359
-
360
- lines.push(":::")
361
- return lines.join("\n")
362
- })
363
-
364
- /**
365
- * Serialize expand macro as a GFM-compatible <details> block.
366
- *
367
- * The opening and closing HTML tags are recognised on round-trip by
368
- * MarkdownParser to rebuild the ExpandMacro AST node. Body content is rendered
369
- * as ordinary markdown so it shows up in viewers (Obsidian, GitHub, etc.).
370
- */
371
- const serializeExpandMacro = (
372
- node: { title?: string | undefined; children: ReadonlyArray<SimpleBlock> }
373
- ): Effect.Effect<string, SerializeError> =>
374
- Effect.gen(function*() {
375
- const title = node.title || ""
376
- const contentParts: Array<string> = []
377
-
378
- for (const child of node.children) {
379
- const serialized = yield* serializeSimpleBlock(child as SimpleBlock)
380
- contentParts.push(serialized)
381
- }
382
-
383
- const body = contentParts.join("\n\n")
384
- const summary = `<summary>${escapeHtml(title)}</summary>`
385
- return `<details>\n${summary}\n\n${body}\n\n</details>`
386
- })
387
-
388
- const escapeHtml = (s: string): string => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
389
-
390
- /**
391
- * Serialize TOC macro.
392
- */
393
- const serializeTocMacro = (_node: { minLevel?: number | undefined; maxLevel?: number | undefined }): string => {
394
- return "[[toc]]"
395
- }
396
-
397
- /**
398
- * Serialize code macro (similar to code block but may have title).
399
- */
400
- const serializeCodeMacro = (
401
- node: { language?: string | undefined; title?: string | undefined; code: string }
402
- ): string => {
403
- const lang = node.language || ""
404
- const title = node.title ? ` title="${node.title}"` : ""
405
- return `\`\`\`${lang}${title}\n${node.code}\n\`\`\``
406
- }
407
-
408
- /**
409
- * Serialize status macro.
410
- */
411
- const serializeStatusMacro = (node: { text: string; color: string }): string => {
412
- return `**[${node.text}]**`
413
- }
414
-
415
- /**
416
- * Serialize task list - preserve as comment-encoded for roundtrip (single line).
417
- */
418
- const serializeTaskList = (
419
- children: ReadonlyArray<{
420
- _tag: "TaskItem"
421
- id: string
422
- uuid: string
423
- status: "incomplete" | "complete"
424
- body: ReadonlyArray<InlineNode>
425
- }>
426
- ): Effect.Effect<string, SerializeError> =>
427
- Effect.gen(function*() {
428
- const items: Array<string> = []
429
- for (const item of children) {
430
- const body = yield* serializeInlineNodes(item.body)
431
- // Encode task item - use | separator to avoid : in content issues
432
- items.push(`${item.id}|${item.uuid}|${item.status}|${encodeURIComponent(body)}`)
433
- }
434
- // Single line comment to prevent remark from splitting
435
- return `<!--cf:tasklist:${items.join(";")}-->`
436
- })
437
-
438
- /**
439
- * Serialize inline nodes to Markdown.
440
- */
441
- const serializeInlineNodes = (
442
- nodes: ReadonlyArray<InlineNode>
443
- ): Effect.Effect<string, SerializeError> =>
444
- Effect.gen(function*() {
445
- const parts: Array<string> = []
446
- for (const node of nodes) {
447
- parts.push(yield* serializeInlineNode(node))
448
- }
449
- return parts.join("")
450
- })
451
-
452
- /**
453
- * Serialize inline node to Markdown.
454
- */
455
- const serializeInlineNode = (node: InlineNode): Effect.Effect<string, SerializeError> =>
456
- Effect.gen(function*() {
457
- switch (node._tag) {
458
- case "Text":
459
- return node.value
460
- case "Strong": {
461
- const content = yield* serializeInlineNodes(node.children)
462
- return `**${content}**`
463
- }
464
- case "Emphasis": {
465
- const content = yield* serializeInlineNodes(node.children)
466
- return `*${content}*`
467
- }
468
- case "Underline": {
469
- // No native markdown support, use HTML
470
- const content = yield* serializeInlineNodes(node.children)
471
- return `<u>${content}</u>`
472
- }
473
- case "Strikethrough": {
474
- const content = yield* serializeInlineNodes(node.children)
475
- return `~~${content}~~`
476
- }
477
- case "Subscript": {
478
- // No native markdown support, use HTML
479
- const content = yield* serializeInlineNodes(node.children)
480
- return `<sub>${content}</sub>`
481
- }
482
- case "Superscript": {
483
- // No native markdown support, use HTML
484
- const content = yield* serializeInlineNodes(node.children)
485
- return `<sup>${content}</sup>`
486
- }
487
- case "InlineCode":
488
- return `\`${node.value}\``
489
- case "Link": {
490
- const content = yield* serializeInlineNodes(node.children)
491
- const title = node.title ? ` "${node.title}"` : ""
492
- return `[${content}](${node.href}${title})`
493
- }
494
- case "LineBreak":
495
- return " \n"
496
- case "Emoticon":
497
- // Wrap in HTML comment with URL-encoded values
498
- return `<!--cf:emoticon:${encodeURIComponent(node.shortname)}|${encodeURIComponent(node.emojiId)}|${
499
- encodeURIComponent(node.fallback)
500
- }-->`
501
- case "UserMention":
502
- // Render as a markdown link so the mention is visible in viewers.
503
- // The #cf-user: URL fragment is the round-trip carrier — MarkdownParser
504
- // rebuilds the UserMention node when it sees a link with that prefix.
505
- return `[@${node.accountId}](#cf-user:${encodeURIComponent(node.accountId)})`
506
- case "DateTime":
507
- // Wrap in HTML comment to prevent remark from parsing
508
- return `<!--cf:date:${node.datetime}-->`
509
- case "ColoredText": {
510
- // Preserve as HTML for roundtrip
511
- const content = yield* serializeInlineNodes(node.children)
512
- return `<span style="color: ${node.color};">${content}</span>`
513
- }
514
- case "Highlight": {
515
- // Preserve as HTML for roundtrip
516
- const content = yield* serializeInlineNodes(node.children)
517
- return `<span style="background-color: ${node.backgroundColor};">${content}</span>`
518
- }
519
- case "UnsupportedInline": {
520
- // Some inline macros are stored as UnsupportedInline carrying a comment-
521
- // encoded round-trip marker. Rewrite the round-trippable ones as visible
522
- // markdown links so they show up in viewers; MarkdownParser reverses this.
523
- // The raw payload is already URL-encoded (ConfluenceParser uses
524
- // encodeURIComponent), so we decode the title for human-readable link
525
- // text and pass the encoded value through to the URL fragment as-is.
526
- const statusMatch = node.raw.match(/^<!--cf:status:([^;]*);([^;]*)-->$/)
527
- if (statusMatch) {
528
- const text = decodeURIComponent(statusMatch[1] ?? "")
529
- const color = statusMatch[2] ?? ""
530
- return `[${text}](#cf-status:${color})`
531
- }
532
- const tocMatch = node.raw.match(/^<!--cf:toc:([^;]*);([^;]*)-->$/)
533
- if (tocMatch) {
534
- const min = tocMatch[1] ?? ""
535
- const max = tocMatch[2] ?? ""
536
- return `[Table of Contents](#cf-toc:${min}:${max})`
537
- }
538
- return node.raw
539
- }
540
- default:
541
- return ""
542
- }
543
- })
@@ -1,8 +0,0 @@
1
- /**
2
- * Serializers for AST to Confluence HTML and Markdown.
3
- *
4
- * @module
5
- */
6
-
7
- export { serializeToConfluence } from "./ConfluenceSerializer.js"
8
- export { serializeToMarkdown } from "./MarkdownSerializer.js"