@knpkv/confluence-to-markdown 0.2.0 → 0.4.1
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 +60 -0
- package/LICENSE +21 -0
- package/README.md +282 -14
- package/dist/ConfluenceAuth.d.ts +76 -0
- package/dist/ConfluenceAuth.d.ts.map +1 -0
- package/dist/ConfluenceAuth.js +356 -0
- package/dist/ConfluenceAuth.js.map +1 -0
- package/dist/ConfluenceClient.d.ts +26 -2
- package/dist/ConfluenceClient.d.ts.map +1 -1
- package/dist/ConfluenceClient.js +98 -92
- package/dist/ConfluenceClient.js.map +1 -1
- package/dist/ConfluenceConfig.d.ts +4 -24
- package/dist/ConfluenceConfig.d.ts.map +1 -1
- package/dist/ConfluenceConfig.js +45 -7
- package/dist/ConfluenceConfig.js.map +1 -1
- package/dist/ConfluenceError.d.ts +89 -6
- package/dist/ConfluenceError.d.ts.map +1 -1
- package/dist/ConfluenceError.js +88 -5
- package/dist/ConfluenceError.js.map +1 -1
- package/dist/GitError.d.ts +103 -0
- package/dist/GitError.d.ts.map +1 -0
- package/dist/GitError.js +85 -0
- package/dist/GitError.js.map +1 -0
- package/dist/GitService.d.ts +175 -0
- package/dist/GitService.d.ts.map +1 -0
- package/dist/GitService.js +431 -0
- package/dist/GitService.js.map +1 -0
- package/dist/LocalFileSystem.d.ts +29 -4
- package/dist/LocalFileSystem.d.ts.map +1 -1
- package/dist/LocalFileSystem.js +80 -6
- package/dist/LocalFileSystem.js.map +1 -1
- package/dist/MarkdownConverter.d.ts +49 -2
- package/dist/MarkdownConverter.d.ts.map +1 -1
- package/dist/MarkdownConverter.js +73 -111
- package/dist/MarkdownConverter.js.map +1 -1
- package/dist/SchemaConverterError.d.ts +108 -0
- package/dist/SchemaConverterError.d.ts.map +1 -0
- package/dist/SchemaConverterError.js +84 -0
- package/dist/SchemaConverterError.js.map +1 -0
- package/dist/Schemas.d.ts +225 -1
- package/dist/Schemas.d.ts.map +1 -1
- package/dist/Schemas.js +155 -6
- package/dist/Schemas.js.map +1 -1
- package/dist/SyncEngine.d.ts +30 -20
- package/dist/SyncEngine.d.ts.map +1 -1
- package/dist/SyncEngine.js +566 -117
- package/dist/SyncEngine.js.map +1 -1
- package/dist/ast/BlockNode.d.ts +468 -0
- package/dist/ast/BlockNode.d.ts.map +1 -0
- package/dist/ast/BlockNode.js +319 -0
- package/dist/ast/BlockNode.js.map +1 -0
- package/dist/ast/Document.d.ts +244 -0
- package/dist/ast/Document.d.ts.map +1 -0
- package/dist/ast/Document.js +69 -0
- package/dist/ast/Document.js.map +1 -0
- package/dist/ast/InlineNode.d.ts +477 -0
- package/dist/ast/InlineNode.d.ts.map +1 -0
- package/dist/ast/InlineNode.js +263 -0
- package/dist/ast/InlineNode.js.map +1 -0
- package/dist/ast/MacroNode.d.ts +267 -0
- package/dist/ast/MacroNode.d.ts.map +1 -0
- package/dist/ast/MacroNode.js +164 -0
- package/dist/ast/MacroNode.js.map +1 -0
- package/dist/ast/index.d.ts +10 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/index.js +14 -0
- package/dist/ast/index.js.map +1 -0
- package/dist/bin.js +33 -149
- package/dist/bin.js.map +1 -1
- package/dist/commands/auth.d.ts +15 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +86 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/clone.d.ts +12 -0
- package/dist/commands/clone.d.ts.map +1 -0
- package/dist/commands/clone.js +93 -0
- package/dist/commands/clone.js.map +1 -0
- package/dist/commands/delete.d.ts +13 -0
- package/dist/commands/delete.d.ts.map +1 -0
- package/dist/commands/delete.js +48 -0
- package/dist/commands/delete.js.map +1 -0
- package/dist/commands/errorHandler.d.ts +14 -0
- package/dist/commands/errorHandler.d.ts.map +1 -0
- package/dist/commands/errorHandler.js +33 -0
- package/dist/commands/errorHandler.js.map +1 -0
- package/dist/commands/git.d.ts +22 -0
- package/dist/commands/git.d.ts.map +1 -0
- package/dist/commands/git.js +72 -0
- package/dist/commands/git.js.map +1 -0
- package/dist/commands/index.d.ts +11 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +11 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/layers.d.ts +31 -0
- package/dist/commands/layers.d.ts.map +1 -0
- package/dist/commands/layers.js +137 -0
- package/dist/commands/layers.js.map +1 -0
- package/dist/commands/new.d.ts +9 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +80 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/pageTree.d.ts +18 -0
- package/dist/commands/pageTree.d.ts.map +1 -0
- package/dist/commands/pageTree.js +20 -0
- package/dist/commands/pageTree.js.map +1 -0
- package/dist/commands/shared.d.ts +15 -0
- package/dist/commands/shared.d.ts.map +1 -0
- package/dist/commands/shared.js +27 -0
- package/dist/commands/shared.js.map +1 -0
- package/dist/commands/sync.d.ts +15 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +101 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/NodeLayers.d.ts +7 -0
- package/dist/internal/NodeLayers.d.ts.map +1 -0
- package/dist/internal/NodeLayers.js +19 -0
- package/dist/internal/NodeLayers.js.map +1 -0
- package/dist/internal/frontmatter.d.ts +10 -0
- package/dist/internal/frontmatter.d.ts.map +1 -1
- package/dist/internal/frontmatter.js +16 -0
- package/dist/internal/frontmatter.js.map +1 -1
- package/dist/internal/gitCommands.d.ts +78 -0
- package/dist/internal/gitCommands.d.ts.map +1 -0
- package/dist/internal/gitCommands.js +156 -0
- package/dist/internal/gitCommands.js.map +1 -0
- package/dist/internal/hashUtils.d.ts +42 -1
- package/dist/internal/hashUtils.d.ts.map +1 -1
- package/dist/internal/hashUtils.js +38 -2
- package/dist/internal/hashUtils.js.map +1 -1
- package/dist/internal/oauthServer.d.ts +55 -0
- package/dist/internal/oauthServer.d.ts.map +1 -0
- package/dist/internal/oauthServer.js +110 -0
- package/dist/internal/oauthServer.js.map +1 -0
- package/dist/internal/pathUtils.d.ts +21 -4
- package/dist/internal/pathUtils.d.ts.map +1 -1
- package/dist/internal/pathUtils.js +24 -13
- package/dist/internal/pathUtils.js.map +1 -1
- package/dist/internal/tokenStorage.d.ts +75 -0
- package/dist/internal/tokenStorage.d.ts.map +1 -0
- package/dist/internal/tokenStorage.js +149 -0
- package/dist/internal/tokenStorage.js.map +1 -0
- package/dist/internal/userCache.d.ts +42 -0
- package/dist/internal/userCache.d.ts.map +1 -0
- package/dist/internal/userCache.js +51 -0
- package/dist/internal/userCache.js.map +1 -0
- package/dist/parsers/ConfluenceParser.d.ts +26 -0
- package/dist/parsers/ConfluenceParser.d.ts.map +1 -0
- package/dist/parsers/ConfluenceParser.js +792 -0
- package/dist/parsers/ConfluenceParser.js.map +1 -0
- package/dist/parsers/MarkdownParser.d.ts +26 -0
- package/dist/parsers/MarkdownParser.d.ts.map +1 -0
- package/dist/parsers/MarkdownParser.js +873 -0
- package/dist/parsers/MarkdownParser.js.map +1 -0
- package/dist/parsers/index.d.ts +8 -0
- package/dist/parsers/index.d.ts.map +1 -0
- package/dist/parsers/index.js +8 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/schemas/ConfluenceSchema.d.ts +21 -0
- package/dist/schemas/ConfluenceSchema.d.ts.map +1 -0
- package/dist/schemas/ConfluenceSchema.js +38 -0
- package/dist/schemas/ConfluenceSchema.js.map +1 -0
- package/dist/schemas/ConversionSchema.d.ts +35 -0
- package/dist/schemas/ConversionSchema.d.ts.map +1 -0
- package/dist/schemas/ConversionSchema.js +208 -0
- package/dist/schemas/ConversionSchema.js.map +1 -0
- package/dist/schemas/MarkdownSchema.d.ts +21 -0
- package/dist/schemas/MarkdownSchema.d.ts.map +1 -0
- package/dist/schemas/MarkdownSchema.js +38 -0
- package/dist/schemas/MarkdownSchema.js.map +1 -0
- package/dist/schemas/hast/HastFromHtml.d.ts +27 -0
- package/dist/schemas/hast/HastFromHtml.d.ts.map +1 -0
- package/dist/schemas/hast/HastFromHtml.js +107 -0
- package/dist/schemas/hast/HastFromHtml.js.map +1 -0
- package/dist/schemas/hast/HastSchema.d.ts +195 -0
- package/dist/schemas/hast/HastSchema.d.ts.map +1 -0
- package/dist/schemas/hast/HastSchema.js +183 -0
- package/dist/schemas/hast/HastSchema.js.map +1 -0
- package/dist/schemas/hast/index.d.ts +9 -0
- package/dist/schemas/hast/index.d.ts.map +1 -0
- package/dist/schemas/hast/index.js +3 -0
- package/dist/schemas/hast/index.js.map +1 -0
- package/dist/schemas/index.d.ts +14 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +16 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/mdast/MdastFromMarkdown.d.ts +30 -0
- package/dist/schemas/mdast/MdastFromMarkdown.d.ts.map +1 -0
- package/dist/schemas/mdast/MdastFromMarkdown.js +79 -0
- package/dist/schemas/mdast/MdastFromMarkdown.js.map +1 -0
- package/dist/schemas/mdast/MdastSchema.d.ts +385 -0
- package/dist/schemas/mdast/MdastSchema.d.ts.map +1 -0
- package/dist/schemas/mdast/MdastSchema.js +266 -0
- package/dist/schemas/mdast/MdastSchema.js.map +1 -0
- package/dist/schemas/mdast/index.d.ts +10 -0
- package/dist/schemas/mdast/index.d.ts.map +1 -0
- package/dist/schemas/mdast/index.js +4 -0
- package/dist/schemas/mdast/index.js.map +1 -0
- package/dist/schemas/mdast/mdastToString.d.ts +13 -0
- package/dist/schemas/mdast/mdastToString.d.ts.map +1 -0
- package/dist/schemas/mdast/mdastToString.js +85 -0
- package/dist/schemas/mdast/mdastToString.js.map +1 -0
- package/dist/schemas/nodes/block/BlockSchema.d.ts +43 -0
- package/dist/schemas/nodes/block/BlockSchema.d.ts.map +1 -0
- package/dist/schemas/nodes/block/BlockSchema.js +634 -0
- package/dist/schemas/nodes/block/BlockSchema.js.map +1 -0
- package/dist/schemas/nodes/block/index.d.ts +7 -0
- package/dist/schemas/nodes/block/index.d.ts.map +1 -0
- package/dist/schemas/nodes/block/index.js +7 -0
- package/dist/schemas/nodes/block/index.js.map +1 -0
- package/dist/schemas/nodes/index.d.ts +9 -0
- package/dist/schemas/nodes/index.d.ts.map +1 -0
- package/dist/schemas/nodes/index.js +12 -0
- package/dist/schemas/nodes/index.js.map +1 -0
- package/dist/schemas/nodes/inline/InlineSchema.d.ts +48 -0
- package/dist/schemas/nodes/inline/InlineSchema.d.ts.map +1 -0
- package/dist/schemas/nodes/inline/InlineSchema.js +436 -0
- package/dist/schemas/nodes/inline/InlineSchema.js.map +1 -0
- package/dist/schemas/nodes/inline/index.d.ts +7 -0
- package/dist/schemas/nodes/inline/index.d.ts.map +1 -0
- package/dist/schemas/nodes/inline/index.js +7 -0
- package/dist/schemas/nodes/inline/index.js.map +1 -0
- package/dist/schemas/nodes/macro/MacroSchema.d.ts +27 -0
- package/dist/schemas/nodes/macro/MacroSchema.d.ts.map +1 -0
- package/dist/schemas/nodes/macro/MacroSchema.js +162 -0
- package/dist/schemas/nodes/macro/MacroSchema.js.map +1 -0
- package/dist/schemas/nodes/macro/index.d.ts +7 -0
- package/dist/schemas/nodes/macro/index.d.ts.map +1 -0
- package/dist/schemas/nodes/macro/index.js +7 -0
- package/dist/schemas/nodes/macro/index.js.map +1 -0
- package/dist/schemas/preprocessing/ConfluencePreprocessor.d.ts +24 -0
- package/dist/schemas/preprocessing/ConfluencePreprocessor.d.ts.map +1 -0
- package/dist/schemas/preprocessing/ConfluencePreprocessor.js +351 -0
- package/dist/schemas/preprocessing/ConfluencePreprocessor.js.map +1 -0
- package/dist/schemas/preprocessing/index.d.ts +8 -0
- package/dist/schemas/preprocessing/index.d.ts.map +1 -0
- package/dist/schemas/preprocessing/index.js +2 -0
- package/dist/schemas/preprocessing/index.js.map +1 -0
- package/dist/serializers/ConfluenceSerializer.d.ts +30 -0
- package/dist/serializers/ConfluenceSerializer.d.ts.map +1 -0
- package/dist/serializers/ConfluenceSerializer.js +551 -0
- package/dist/serializers/ConfluenceSerializer.js.map +1 -0
- package/dist/serializers/MarkdownSerializer.d.ts +34 -0
- package/dist/serializers/MarkdownSerializer.d.ts.map +1 -0
- package/dist/serializers/MarkdownSerializer.js +355 -0
- package/dist/serializers/MarkdownSerializer.js.map +1 -0
- package/dist/serializers/index.d.ts +8 -0
- package/dist/serializers/index.d.ts.map +1 -0
- package/dist/serializers/index.js +8 -0
- package/dist/serializers/index.js.map +1 -0
- package/package.json +27 -16
- package/src/ConfluenceAuth.ts +571 -0
- package/src/ConfluenceClient.ts +188 -156
- package/src/ConfluenceConfig.ts +63 -7
- package/src/ConfluenceError.ts +110 -14
- package/src/GitError.ts +92 -0
- package/src/GitService.ts +859 -0
- package/src/LocalFileSystem.ts +179 -9
- package/src/MarkdownConverter.ts +126 -122
- package/src/SchemaConverterError.ts +108 -0
- package/src/Schemas.ts +223 -6
- package/src/SyncEngine.ts +745 -162
- package/src/ast/BlockNode.ts +425 -0
- package/src/ast/Document.ts +90 -0
- package/src/ast/InlineNode.ts +323 -0
- package/src/ast/MacroNode.ts +245 -0
- package/src/ast/index.ts +83 -0
- package/src/bin.ts +50 -249
- package/src/commands/auth.ts +117 -0
- package/src/commands/clone.ts +145 -0
- package/src/commands/delete.ts +57 -0
- package/src/commands/errorHandler.ts +32 -0
- package/src/commands/git.ts +114 -0
- package/src/commands/index.ts +10 -0
- package/src/commands/layers.ts +211 -0
- package/src/commands/new.ts +99 -0
- package/src/commands/pageTree.ts +40 -0
- package/src/commands/shared.ts +35 -0
- package/src/commands/sync.ts +129 -0
- package/src/index.ts +21 -1
- package/src/internal/NodeLayers.ts +21 -0
- package/src/internal/frontmatter.ts +21 -0
- package/src/internal/gitCommands.ts +229 -0
- package/src/internal/hashUtils.ts +65 -3
- package/src/internal/oauthServer.ts +199 -0
- package/src/internal/pathUtils.ts +34 -17
- package/src/internal/tokenStorage.ts +240 -0
- package/src/internal/userCache.ts +90 -0
- package/src/parsers/ConfluenceParser.ts +950 -0
- package/src/parsers/MarkdownParser.ts +1198 -0
- package/src/parsers/index.ts +8 -0
- package/src/schemas/ConfluenceSchema.ts +56 -0
- package/src/schemas/ConversionSchema.ts +318 -0
- package/src/schemas/MarkdownSchema.ts +56 -0
- package/src/schemas/hast/HastFromHtml.ts +153 -0
- package/src/schemas/hast/HastSchema.ts +274 -0
- package/src/schemas/hast/index.ts +35 -0
- package/src/schemas/index.ts +20 -0
- package/src/schemas/mdast/MdastFromMarkdown.ts +118 -0
- package/src/schemas/mdast/MdastSchema.ts +566 -0
- package/src/schemas/mdast/index.ts +59 -0
- package/src/schemas/mdast/mdastToString.ts +102 -0
- package/src/schemas/nodes/block/BlockSchema.ts +773 -0
- package/src/schemas/nodes/block/index.ts +13 -0
- package/src/schemas/nodes/index.ts +20 -0
- package/src/schemas/nodes/inline/InlineSchema.ts +523 -0
- package/src/schemas/nodes/inline/index.ts +14 -0
- package/src/schemas/nodes/macro/MacroSchema.ts +226 -0
- package/src/schemas/nodes/macro/index.ts +6 -0
- package/src/schemas/preprocessing/ConfluencePreprocessor.ts +446 -0
- package/src/schemas/preprocessing/index.ts +8 -0
- package/src/serializers/ConfluenceSerializer.ts +717 -0
- package/src/serializers/MarkdownSerializer.ts +493 -0
- package/src/serializers/index.ts +8 -0
- package/test/GitService.test.ts +209 -0
- package/test/MarkdownConverter.test.ts +37 -3
- package/test/Schemas.test.ts +97 -2
- package/test/ast/BlockNode.test.ts +265 -0
- package/test/ast/Document.test.ts +126 -0
- package/test/ast/InlineNode.test.ts +161 -0
- package/test/fixtures/integration-test.html.fixture +103 -0
- package/test/fixtures/integration-test.md.expected +257 -0
- package/test/integration.test.ts +269 -0
- package/test/oauthServer.test.ts +50 -0
- package/test/parsers/ConfluenceParser.test.ts +283 -0
- package/test/schemas/ConfluencePreprocessor.test.ts +180 -0
- package/test/schemas/ConversionSchema.test.ts +159 -0
- package/test/schemas/HastSchema.test.ts +138 -0
- package/test/schemas/MdastSchema.test.ts +145 -0
- package/test/schemas/nodes/block/BlockSchema.test.ts +173 -0
- package/test/schemas/nodes/inline/InlineSchema.test.ts +198 -0
- package/test/schemas/nodes/macro/MacroSchema.test.ts +142 -0
- package/test/tokenStorage.test.ts +99 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block-level AST node types for structural content.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import * as Schema from "effect/Schema"
|
|
7
|
+
import { InlineNode, type InlineNode as InlineNodeType } from "./InlineNode.js"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Schema version for migration support.
|
|
11
|
+
*
|
|
12
|
+
* @category Version
|
|
13
|
+
*/
|
|
14
|
+
export const SchemaVersion = Schema.Number.pipe(
|
|
15
|
+
Schema.int(),
|
|
16
|
+
Schema.positive(),
|
|
17
|
+
Schema.optionalWith({ default: () => 1 })
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Optional raw Confluence HTML for exact roundtrip preservation.
|
|
22
|
+
* When present, the Confluence serializer will output this instead of reconstructing.
|
|
23
|
+
*
|
|
24
|
+
* @category BlockNode
|
|
25
|
+
*/
|
|
26
|
+
export const RawConfluence = Schema.optional(Schema.String)
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Heading element (h1-h6).
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { Heading, Text } from "@knpkv/confluence-to-markdown/ast"
|
|
34
|
+
*
|
|
35
|
+
* const h1 = new Heading({
|
|
36
|
+
* level: 1,
|
|
37
|
+
* children: [new Text({ value: "Introduction" })]
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @category BlockNode
|
|
42
|
+
*/
|
|
43
|
+
export class Heading extends Schema.TaggedClass<Heading>()("Heading", {
|
|
44
|
+
version: SchemaVersion,
|
|
45
|
+
level: Schema.Literal(1, 2, 3, 4, 5, 6),
|
|
46
|
+
children: Schema.Array(InlineNode),
|
|
47
|
+
rawConfluence: RawConfluence
|
|
48
|
+
}) {}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Text alignment options.
|
|
52
|
+
*
|
|
53
|
+
* @category BlockNode
|
|
54
|
+
*/
|
|
55
|
+
export const TextAlignment = Schema.Literal("left", "center", "right")
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Type for TextAlignment.
|
|
59
|
+
*
|
|
60
|
+
* @category Types
|
|
61
|
+
*/
|
|
62
|
+
export type TextAlignment = Schema.Schema.Type<typeof TextAlignment>
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Paragraph element with optional alignment and indentation.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { Paragraph, Text } from "@knpkv/confluence-to-markdown/ast"
|
|
70
|
+
*
|
|
71
|
+
* const para = new Paragraph({
|
|
72
|
+
* children: [new Text({ value: "Hello world" })]
|
|
73
|
+
* })
|
|
74
|
+
*
|
|
75
|
+
* // With alignment
|
|
76
|
+
* const centered = new Paragraph({
|
|
77
|
+
* alignment: "center",
|
|
78
|
+
* children: [new Text({ value: "Centered text" })]
|
|
79
|
+
* })
|
|
80
|
+
*
|
|
81
|
+
* // With indentation (in pixels)
|
|
82
|
+
* const indented = new Paragraph({
|
|
83
|
+
* indent: 30,
|
|
84
|
+
* children: [new Text({ value: "Indented text" })]
|
|
85
|
+
* })
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @category BlockNode
|
|
89
|
+
*/
|
|
90
|
+
export class Paragraph extends Schema.TaggedClass<Paragraph>()("Paragraph", {
|
|
91
|
+
version: SchemaVersion,
|
|
92
|
+
alignment: Schema.optional(TextAlignment),
|
|
93
|
+
indent: Schema.optional(Schema.Number),
|
|
94
|
+
children: Schema.Array(InlineNode),
|
|
95
|
+
rawConfluence: RawConfluence
|
|
96
|
+
}) {}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Code block with optional language.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* import { CodeBlock } from "@knpkv/confluence-to-markdown/ast"
|
|
104
|
+
*
|
|
105
|
+
* const code = new CodeBlock({
|
|
106
|
+
* language: "typescript",
|
|
107
|
+
* code: "const x = 1"
|
|
108
|
+
* })
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @category BlockNode
|
|
112
|
+
*/
|
|
113
|
+
export class CodeBlock extends Schema.TaggedClass<CodeBlock>()("CodeBlock", {
|
|
114
|
+
version: SchemaVersion,
|
|
115
|
+
language: Schema.optional(Schema.String),
|
|
116
|
+
code: Schema.String,
|
|
117
|
+
rawConfluence: RawConfluence
|
|
118
|
+
}) {}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Thematic break / horizontal rule.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* import { ThematicBreak } from "@knpkv/confluence-to-markdown/ast"
|
|
126
|
+
*
|
|
127
|
+
* const hr = new ThematicBreak({})
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @category BlockNode
|
|
131
|
+
*/
|
|
132
|
+
export class ThematicBreak extends Schema.TaggedClass<ThematicBreak>()("ThematicBreak", {
|
|
133
|
+
rawConfluence: RawConfluence
|
|
134
|
+
}) {}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Attachment reference for images stored in Confluence.
|
|
138
|
+
*
|
|
139
|
+
* @category BlockNode
|
|
140
|
+
*/
|
|
141
|
+
export const ImageAttachment = Schema.Struct({
|
|
142
|
+
filename: Schema.String,
|
|
143
|
+
version: Schema.optional(Schema.Number)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Type for ImageAttachment.
|
|
148
|
+
*
|
|
149
|
+
* @category Types
|
|
150
|
+
*/
|
|
151
|
+
export type ImageAttachment = Schema.Schema.Type<typeof ImageAttachment>
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Image element with support for both URL and Confluence attachments.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* import { Image } from "@knpkv/confluence-to-markdown/ast"
|
|
159
|
+
*
|
|
160
|
+
* // URL-based image
|
|
161
|
+
* const img = new Image({
|
|
162
|
+
* src: "https://example.com/image.png",
|
|
163
|
+
* alt: "Example image"
|
|
164
|
+
* })
|
|
165
|
+
*
|
|
166
|
+
* // Confluence attachment
|
|
167
|
+
* const attachment = new Image({
|
|
168
|
+
* attachment: { filename: "logo.svg" },
|
|
169
|
+
* align: "center",
|
|
170
|
+
* width: 250
|
|
171
|
+
* })
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @category BlockNode
|
|
175
|
+
*/
|
|
176
|
+
export class Image extends Schema.TaggedClass<Image>()("Image", {
|
|
177
|
+
version: SchemaVersion,
|
|
178
|
+
src: Schema.optional(Schema.String),
|
|
179
|
+
attachment: Schema.optional(ImageAttachment),
|
|
180
|
+
alt: Schema.optional(Schema.String),
|
|
181
|
+
title: Schema.optional(Schema.String),
|
|
182
|
+
align: Schema.optional(Schema.String),
|
|
183
|
+
width: Schema.optional(Schema.Number),
|
|
184
|
+
rawConfluence: RawConfluence
|
|
185
|
+
}) {}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Table cell element.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* import { TableCell, Text } from "@knpkv/confluence-to-markdown/ast"
|
|
193
|
+
*
|
|
194
|
+
* const cell = new TableCell({
|
|
195
|
+
* isHeader: true,
|
|
196
|
+
* children: [new Text({ value: "Header" })]
|
|
197
|
+
* })
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @category BlockNode
|
|
201
|
+
*/
|
|
202
|
+
export class TableCell extends Schema.TaggedClass<TableCell>()("TableCell", {
|
|
203
|
+
isHeader: Schema.optionalWith(Schema.Boolean, { default: () => false }),
|
|
204
|
+
children: Schema.Array(InlineNode),
|
|
205
|
+
rawConfluence: RawConfluence
|
|
206
|
+
}) {}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Table row element.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* import { TableRow, TableCell, Text } from "@knpkv/confluence-to-markdown/ast"
|
|
214
|
+
*
|
|
215
|
+
* const row = new TableRow({
|
|
216
|
+
* cells: [
|
|
217
|
+
* new TableCell({ children: [new Text({ value: "A" })] }),
|
|
218
|
+
* new TableCell({ children: [new Text({ value: "B" })] })
|
|
219
|
+
* ]
|
|
220
|
+
* })
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* @category BlockNode
|
|
224
|
+
*/
|
|
225
|
+
export class TableRow extends Schema.TaggedClass<TableRow>()("TableRow", {
|
|
226
|
+
cells: Schema.Array(TableCell),
|
|
227
|
+
rawConfluence: RawConfluence
|
|
228
|
+
}) {}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Table element with optional header row.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* import { Table, TableRow, TableCell, Text } from "@knpkv/confluence-to-markdown/ast"
|
|
236
|
+
*
|
|
237
|
+
* const table = new Table({
|
|
238
|
+
* header: new TableRow({
|
|
239
|
+
* cells: [new TableCell({ isHeader: true, children: [new Text({ value: "Col" })] })]
|
|
240
|
+
* }),
|
|
241
|
+
* rows: []
|
|
242
|
+
* })
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @category BlockNode
|
|
246
|
+
*/
|
|
247
|
+
export class Table extends Schema.TaggedClass<Table>()("Table", {
|
|
248
|
+
version: SchemaVersion,
|
|
249
|
+
header: Schema.optional(TableRow),
|
|
250
|
+
rows: Schema.Array(TableRow),
|
|
251
|
+
rawConfluence: RawConfluence
|
|
252
|
+
}) {}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Unsupported block element - preserves raw content for round-tripping.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* import { UnsupportedBlock } from "@knpkv/confluence-to-markdown/ast"
|
|
260
|
+
*
|
|
261
|
+
* const unknown = new UnsupportedBlock({
|
|
262
|
+
* rawHtml: "<custom-block>content</custom-block>",
|
|
263
|
+
* source: "confluence"
|
|
264
|
+
* })
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @category BlockNode
|
|
268
|
+
*/
|
|
269
|
+
export class UnsupportedBlock extends Schema.TaggedClass<UnsupportedBlock>()("UnsupportedBlock", {
|
|
270
|
+
rawHtml: Schema.optional(Schema.String),
|
|
271
|
+
rawMarkdown: Schema.optional(Schema.String),
|
|
272
|
+
source: Schema.Literal("confluence", "markdown")
|
|
273
|
+
}) {}
|
|
274
|
+
|
|
275
|
+
// Non-recursive block nodes
|
|
276
|
+
const SimpleBlockNode = Schema.Union(
|
|
277
|
+
Heading,
|
|
278
|
+
Paragraph,
|
|
279
|
+
CodeBlock,
|
|
280
|
+
ThematicBreak,
|
|
281
|
+
Image,
|
|
282
|
+
Table,
|
|
283
|
+
UnsupportedBlock
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Block quote element with nested block content.
|
|
288
|
+
*
|
|
289
|
+
* @category BlockNode
|
|
290
|
+
*/
|
|
291
|
+
export const BlockQuote = Schema.Struct({
|
|
292
|
+
_tag: Schema.Literal("BlockQuote"),
|
|
293
|
+
version: SchemaVersion,
|
|
294
|
+
children: Schema.Array(SimpleBlockNode),
|
|
295
|
+
rawConfluence: RawConfluence
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Type for BlockQuote.
|
|
300
|
+
*
|
|
301
|
+
* @category Types
|
|
302
|
+
*/
|
|
303
|
+
export type BlockQuote = Schema.Schema.Type<typeof BlockQuote>
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* List item with nested block content.
|
|
307
|
+
*
|
|
308
|
+
* @category BlockNode
|
|
309
|
+
*/
|
|
310
|
+
export const ListItem = Schema.Struct({
|
|
311
|
+
_tag: Schema.Literal("ListItem"),
|
|
312
|
+
checked: Schema.optional(Schema.Boolean),
|
|
313
|
+
children: Schema.Array(SimpleBlockNode),
|
|
314
|
+
rawConfluence: RawConfluence
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Type for ListItem.
|
|
319
|
+
*
|
|
320
|
+
* @category Types
|
|
321
|
+
*/
|
|
322
|
+
export type ListItem = Schema.Schema.Type<typeof ListItem>
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* List element (ordered or unordered).
|
|
326
|
+
*
|
|
327
|
+
* @category BlockNode
|
|
328
|
+
*/
|
|
329
|
+
export const List = Schema.Struct({
|
|
330
|
+
_tag: Schema.Literal("List"),
|
|
331
|
+
version: SchemaVersion,
|
|
332
|
+
ordered: Schema.Boolean,
|
|
333
|
+
start: Schema.optional(Schema.Number),
|
|
334
|
+
children: Schema.Array(ListItem),
|
|
335
|
+
rawConfluence: RawConfluence
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Type for List.
|
|
340
|
+
*
|
|
341
|
+
* @category Types
|
|
342
|
+
*/
|
|
343
|
+
export type List = Schema.Schema.Type<typeof List>
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Task item with status for Confluence task lists.
|
|
347
|
+
*
|
|
348
|
+
* @category BlockNode
|
|
349
|
+
*/
|
|
350
|
+
export const TaskItem = Schema.Struct({
|
|
351
|
+
_tag: Schema.Literal("TaskItem"),
|
|
352
|
+
id: Schema.String,
|
|
353
|
+
uuid: Schema.String,
|
|
354
|
+
status: Schema.Literal("incomplete", "complete"),
|
|
355
|
+
body: Schema.Array(InlineNode),
|
|
356
|
+
rawConfluence: RawConfluence
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Type for TaskItem.
|
|
361
|
+
*
|
|
362
|
+
* @category Types
|
|
363
|
+
*/
|
|
364
|
+
export type TaskItem = Schema.Schema.Type<typeof TaskItem>
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Task list (Confluence action items).
|
|
368
|
+
*
|
|
369
|
+
* @category BlockNode
|
|
370
|
+
*/
|
|
371
|
+
export const TaskList = Schema.Struct({
|
|
372
|
+
_tag: Schema.Literal("TaskList"),
|
|
373
|
+
version: SchemaVersion,
|
|
374
|
+
children: Schema.Array(TaskItem),
|
|
375
|
+
rawConfluence: RawConfluence
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Type for TaskList.
|
|
380
|
+
*
|
|
381
|
+
* @category Types
|
|
382
|
+
*/
|
|
383
|
+
export type TaskList = Schema.Schema.Type<typeof TaskList>
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Union of all block node types.
|
|
387
|
+
*
|
|
388
|
+
* @category BlockNode
|
|
389
|
+
*/
|
|
390
|
+
export const BlockNode = Schema.Union(
|
|
391
|
+
Heading,
|
|
392
|
+
Paragraph,
|
|
393
|
+
CodeBlock,
|
|
394
|
+
ThematicBreak,
|
|
395
|
+
BlockQuote,
|
|
396
|
+
Image,
|
|
397
|
+
Table,
|
|
398
|
+
List,
|
|
399
|
+
TaskList,
|
|
400
|
+
UnsupportedBlock
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Type for block nodes.
|
|
405
|
+
*
|
|
406
|
+
* @category Types
|
|
407
|
+
*/
|
|
408
|
+
export type BlockNode =
|
|
409
|
+
| Heading
|
|
410
|
+
| Paragraph
|
|
411
|
+
| CodeBlock
|
|
412
|
+
| ThematicBreak
|
|
413
|
+
| BlockQuote
|
|
414
|
+
| Image
|
|
415
|
+
| Table
|
|
416
|
+
| List
|
|
417
|
+
| TaskList
|
|
418
|
+
| UnsupportedBlock
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Type helper for inline node children in blocks.
|
|
422
|
+
*
|
|
423
|
+
* @category Types
|
|
424
|
+
*/
|
|
425
|
+
export type { InlineNodeType as InlineNode }
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document AST node - the root of the AST tree.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import * as Schema from "effect/Schema"
|
|
7
|
+
import { BlockNode, type BlockNode as BlockNodeType, RawConfluence, SchemaVersion } from "./BlockNode.js"
|
|
8
|
+
import { MacroNode, type MacroNode as MacroNodeType } from "./MacroNode.js"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Document node - represents a Block or Macro node.
|
|
12
|
+
*
|
|
13
|
+
* @category Document
|
|
14
|
+
*/
|
|
15
|
+
export const DocumentNode = Schema.Union(BlockNode, MacroNode)
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Type for document nodes.
|
|
19
|
+
*
|
|
20
|
+
* @category Types
|
|
21
|
+
*/
|
|
22
|
+
export type DocumentNode = BlockNodeType | MacroNodeType
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Document schema - the root AST node.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { Document, Heading, Paragraph, Text } from "@knpkv/confluence-to-markdown/ast"
|
|
30
|
+
* import * as Schema from "effect/Schema"
|
|
31
|
+
*
|
|
32
|
+
* const doc = {
|
|
33
|
+
* version: 1,
|
|
34
|
+
* children: [
|
|
35
|
+
* new Heading({ level: 1, children: [new Text({ value: "Title" })] }),
|
|
36
|
+
* new Paragraph({ children: [new Text({ value: "Content" })] })
|
|
37
|
+
* ]
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* const validated = Schema.decodeUnknownSync(Document)(doc)
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @category Document
|
|
44
|
+
*/
|
|
45
|
+
export const Document = Schema.Struct({
|
|
46
|
+
version: SchemaVersion,
|
|
47
|
+
children: Schema.Array(DocumentNode),
|
|
48
|
+
rawConfluence: RawConfluence
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Type for Document.
|
|
53
|
+
*
|
|
54
|
+
* @category Types
|
|
55
|
+
*/
|
|
56
|
+
export type Document = Schema.Schema.Type<typeof Document>
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Create a new Document with default version.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { makeDocument, Heading, Text } from "@knpkv/confluence-to-markdown/ast"
|
|
64
|
+
*
|
|
65
|
+
* const doc = makeDocument([
|
|
66
|
+
* new Heading({ level: 1, children: [new Text({ value: "Hello" })] })
|
|
67
|
+
* ])
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @category Constructors
|
|
71
|
+
*/
|
|
72
|
+
export const makeDocument = (
|
|
73
|
+
children: ReadonlyArray<DocumentNode>,
|
|
74
|
+
rawConfluence?: string
|
|
75
|
+
): Document => ({
|
|
76
|
+
version: 1,
|
|
77
|
+
children,
|
|
78
|
+
...(rawConfluence !== undefined ? { rawConfluence } : {})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Check if a node is a Document.
|
|
83
|
+
*
|
|
84
|
+
* @category Guards
|
|
85
|
+
*/
|
|
86
|
+
export const isDocument = (value: unknown): value is Document =>
|
|
87
|
+
typeof value === "object" &&
|
|
88
|
+
value !== null &&
|
|
89
|
+
"children" in value &&
|
|
90
|
+
Array.isArray((value as Document).children)
|