@knpkv/confluence-to-markdown 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/README.md +58 -14
- package/dist/AdfPlaceholders.d.ts +42 -0
- package/dist/AdfPlaceholders.d.ts.map +1 -0
- package/dist/AdfPlaceholders.js +547 -0
- package/dist/AdfPlaceholders.js.map +1 -0
- package/dist/AdfSchemaValidator.d.ts +37 -0
- package/dist/AdfSchemaValidator.d.ts.map +1 -0
- package/dist/AdfSchemaValidator.js +37 -0
- package/dist/AdfSchemaValidator.js.map +1 -0
- package/dist/AdfWalker.d.ts +39 -0
- package/dist/AdfWalker.d.ts.map +1 -0
- package/dist/AdfWalker.js +527 -0
- package/dist/AdfWalker.js.map +1 -0
- package/dist/AtlaskitTransformers.d.ts +35 -0
- package/dist/AtlaskitTransformers.d.ts.map +1 -0
- package/dist/AtlaskitTransformers.js +48 -0
- package/dist/AtlaskitTransformers.js.map +1 -0
- package/dist/Brand.d.ts +6 -6
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +8 -6
- package/dist/Brand.js.map +1 -1
- package/dist/ConfluenceAuth.d.ts +4 -4
- package/dist/ConfluenceAuth.d.ts.map +1 -1
- package/dist/ConfluenceAuth.js +15 -27
- package/dist/ConfluenceAuth.js.map +1 -1
- package/dist/ConfluenceClient.d.ts +4 -4
- package/dist/ConfluenceClient.d.ts.map +1 -1
- package/dist/ConfluenceClient.js +21 -14
- package/dist/ConfluenceClient.js.map +1 -1
- package/dist/ConfluenceConfig.d.ts +3 -3
- package/dist/ConfluenceConfig.d.ts.map +1 -1
- package/dist/ConfluenceConfig.js +13 -11
- package/dist/ConfluenceConfig.js.map +1 -1
- package/dist/ConfluenceError.d.ts +56 -4
- package/dist/ConfluenceError.d.ts.map +1 -1
- package/dist/ConfluenceError.js +30 -1
- package/dist/ConfluenceError.js.map +1 -1
- package/dist/GitService.d.ts +11 -3
- package/dist/GitService.d.ts.map +1 -1
- package/dist/GitService.js +19 -27
- package/dist/GitService.js.map +1 -1
- package/dist/LocalFileSystem.d.ts +3 -3
- package/dist/LocalFileSystem.d.ts.map +1 -1
- package/dist/LocalFileSystem.js +6 -6
- package/dist/LocalFileSystem.js.map +1 -1
- package/dist/MarkdownConverter.d.ts +16 -65
- package/dist/MarkdownConverter.d.ts.map +1 -1
- package/dist/MarkdownConverter.js +64 -85
- package/dist/MarkdownConverter.js.map +1 -1
- package/dist/Schemas.d.ts +128 -141
- package/dist/Schemas.d.ts.map +1 -1
- package/dist/Schemas.js +21 -23
- package/dist/Schemas.js.map +1 -1
- package/dist/SyncEngine.d.ts +8 -5
- package/dist/SyncEngine.d.ts.map +1 -1
- package/dist/SyncEngine.js +189 -113
- package/dist/SyncEngine.js.map +1 -1
- package/dist/bin.js +23 -35
- package/dist/bin.js.map +1 -1
- package/dist/commands/auth.d.ts +2 -14
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +11 -16
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/clone.d.ts +4 -6
- package/dist/commands/clone.d.ts.map +1 -1
- package/dist/commands/clone.js +34 -32
- package/dist/commands/clone.js.map +1 -1
- package/dist/commands/delete.d.ts +2 -10
- package/dist/commands/delete.d.ts.map +1 -1
- package/dist/commands/delete.js +5 -4
- package/dist/commands/delete.js.map +1 -1
- package/dist/commands/errorHandler.d.ts +2 -1
- package/dist/commands/errorHandler.d.ts.map +1 -1
- package/dist/commands/errorHandler.js +22 -15
- package/dist/commands/errorHandler.js.map +1 -1
- package/dist/commands/fetch.d.ts +27 -0
- package/dist/commands/fetch.d.ts.map +1 -0
- package/dist/commands/fetch.js +48 -0
- package/dist/commands/fetch.js.map +1 -0
- package/dist/commands/git.d.ts +7 -10
- package/dist/commands/git.d.ts.map +1 -1
- package/dist/commands/git.js +6 -6
- package/dist/commands/git.js.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +1 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/layers.d.ts +10 -9
- package/dist/commands/layers.d.ts.map +1 -1
- package/dist/commands/layers.js +41 -30
- package/dist/commands/layers.js.map +1 -1
- package/dist/commands/new.d.ts +2 -6
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +5 -4
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/pageInput.d.ts +19 -0
- package/dist/commands/pageInput.d.ts.map +1 -0
- package/dist/commands/pageInput.js +68 -0
- package/dist/commands/pageInput.js.map +1 -0
- package/dist/commands/root.d.ts +8 -0
- package/dist/commands/root.d.ts.map +1 -0
- package/dist/commands/root.js +29 -0
- package/dist/commands/root.js.map +1 -0
- package/dist/commands/sync.d.ts +6 -9
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +5 -6
- package/dist/commands/sync.js.map +1 -1
- package/dist/index.d.ts +3 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -13
- package/dist/index.js.map +1 -1
- package/dist/internal/NodeLayers.d.ts.map +1 -1
- package/dist/internal/NodeLayers.js +1 -2
- package/dist/internal/NodeLayers.js.map +1 -1
- package/dist/internal/adfMetadata.d.ts +30 -0
- package/dist/internal/adfMetadata.d.ts.map +1 -0
- package/dist/internal/adfMetadata.js +126 -0
- package/dist/internal/adfMetadata.js.map +1 -0
- package/dist/internal/cleanMarkdown.d.ts +5 -0
- package/dist/internal/cleanMarkdown.d.ts.map +1 -0
- package/dist/internal/cleanMarkdown.js +13 -0
- package/dist/internal/cleanMarkdown.js.map +1 -0
- package/dist/internal/frontmatter.d.ts.map +1 -1
- package/dist/internal/frontmatter.js +41 -8
- package/dist/internal/frontmatter.js.map +1 -1
- package/dist/internal/gitCommands.d.ts +9 -3
- package/dist/internal/gitCommands.d.ts.map +1 -1
- package/dist/internal/gitCommands.js +18 -9
- package/dist/internal/gitCommands.js.map +1 -1
- package/dist/internal/hashUtils.d.ts +1 -1
- package/dist/internal/hashUtils.d.ts.map +1 -1
- package/dist/internal/hashUtils.js +1 -1
- package/dist/internal/hashUtils.js.map +1 -1
- package/dist/internal/oauthServer.d.ts +10 -5
- package/dist/internal/oauthServer.d.ts.map +1 -1
- package/dist/internal/oauthServer.js +19 -40
- package/dist/internal/oauthServer.js.map +1 -1
- package/dist/internal/pathUtils.d.ts +1 -1
- package/dist/internal/pathUtils.d.ts.map +1 -1
- package/dist/internal/pathUtils.js +1 -1
- package/dist/internal/pathUtils.js.map +1 -1
- package/dist/internal/process.d.ts +15 -0
- package/dist/internal/process.d.ts.map +1 -0
- package/dist/internal/process.js +10 -0
- package/dist/internal/process.js.map +1 -0
- package/dist/internal/stdio.d.ts +6 -0
- package/dist/internal/stdio.d.ts.map +1 -0
- package/dist/internal/stdio.js +15 -0
- package/dist/internal/stdio.js.map +1 -0
- package/dist/internal/tokenStorage.d.ts +3 -13
- package/dist/internal/tokenStorage.d.ts.map +1 -1
- package/dist/internal/tokenStorage.js +26 -24
- package/dist/internal/tokenStorage.js.map +1 -1
- package/dist/internal/userCache.d.ts +1 -1
- package/dist/internal/userCache.d.ts.map +1 -1
- package/dist/internal/userCache.js +1 -1
- package/dist/internal/userCache.js.map +1 -1
- package/package.json +29 -20
- package/skills/confluence/SKILL.md +143 -0
- package/skills/confluence/agents/openai.yaml +4 -0
- package/src/AdfPlaceholders.ts +563 -0
- package/src/AdfSchemaValidator.ts +65 -0
- package/src/AdfWalker.ts +591 -0
- package/src/AtlaskitTransformers.ts +70 -0
- package/src/Brand.ts +11 -16
- package/src/ConfluenceAuth.ts +22 -30
- package/src/ConfluenceClient.ts +28 -24
- package/src/ConfluenceConfig.ts +14 -14
- package/src/ConfluenceError.ts +65 -3
- package/src/GitService.ts +39 -49
- package/src/LocalFileSystem.ts +7 -9
- package/src/MarkdownConverter.ts +108 -143
- package/src/Schemas.ts +17 -16
- package/src/SyncEngine.ts +272 -127
- package/src/atlaskit-adf-schema.d.ts +3 -0
- package/src/bin.ts +30 -56
- package/src/commands/auth.ts +21 -18
- package/src/commands/clone.ts +46 -38
- package/src/commands/delete.ts +5 -4
- package/src/commands/errorHandler.ts +25 -18
- package/src/commands/fetch.ts +90 -0
- package/src/commands/git.ts +6 -6
- package/src/commands/index.ts +1 -0
- package/src/commands/layers.ts +64 -37
- package/src/commands/new.ts +5 -4
- package/src/commands/pageInput.ts +103 -0
- package/src/commands/root.ts +59 -0
- package/src/commands/sync.ts +7 -6
- package/src/index.ts +3 -18
- package/src/internal/NodeLayers.ts +1 -2
- package/src/internal/adfMetadata.ts +145 -0
- package/src/internal/cleanMarkdown.ts +15 -0
- package/src/internal/frontmatter.ts +45 -8
- package/src/internal/gitCommands.ts +23 -17
- package/src/internal/hashUtils.ts +2 -2
- package/src/internal/oauthServer.ts +84 -105
- package/src/internal/pathUtils.ts +1 -1
- package/src/internal/process.ts +15 -0
- package/src/internal/stdio.ts +22 -0
- package/src/internal/tokenStorage.ts +39 -29
- package/src/internal/userCache.ts +2 -2
- package/test/AdfPlaceholders.test.ts +508 -0
- package/test/AdfSchemaValidator.test.ts +34 -0
- package/test/AdfWalker.test.ts +676 -0
- package/test/AtlaskitTransformers.test.ts +25 -0
- package/test/Brand.test.ts +11 -11
- package/test/GitService.test.ts +6 -2
- package/test/MarkdownConverter.test.ts +121 -105
- package/test/RoundTrip.test.ts +521 -0
- package/test/Schemas.test.ts +40 -40
- package/test/adfMetadata.test.ts +110 -0
- package/test/cleanMarkdown.test.ts +36 -0
- package/test/commandHarness.test.ts +79 -0
- package/test/commandHarness.ts +147 -0
- package/test/fetch.test.ts +61 -0
- package/test/frontmatter.test.ts +41 -0
- package/test/integration.test.ts +569 -156
- package/test/layers.test.ts +12 -0
- package/test/oauthServer.test.ts +4 -5
- package/test/pageInput.test.ts +83 -0
- package/test/tokenStorage.test.ts +17 -17
- package/dist/SchemaConverterError.d.ts +0 -108
- package/dist/SchemaConverterError.d.ts.map +0 -1
- package/dist/SchemaConverterError.js +0 -84
- package/dist/SchemaConverterError.js.map +0 -1
- package/dist/ast/BlockNode.d.ts +0 -453
- package/dist/ast/BlockNode.d.ts.map +0 -1
- package/dist/ast/BlockNode.js +0 -310
- package/dist/ast/BlockNode.js.map +0 -1
- package/dist/ast/Document.d.ts +0 -216
- package/dist/ast/Document.d.ts.map +0 -1
- package/dist/ast/Document.js +0 -69
- package/dist/ast/Document.js.map +0 -1
- package/dist/ast/InlineNode.d.ts +0 -477
- package/dist/ast/InlineNode.d.ts.map +0 -1
- package/dist/ast/InlineNode.js +0 -263
- package/dist/ast/InlineNode.js.map +0 -1
- package/dist/ast/MacroNode.d.ts +0 -267
- package/dist/ast/MacroNode.d.ts.map +0 -1
- package/dist/ast/MacroNode.js +0 -164
- package/dist/ast/MacroNode.js.map +0 -1
- package/dist/ast/index.d.ts +0 -10
- package/dist/ast/index.d.ts.map +0 -1
- package/dist/ast/index.js +0 -14
- package/dist/ast/index.js.map +0 -1
- package/dist/parsers/ConfluenceParser.d.ts +0 -26
- package/dist/parsers/ConfluenceParser.d.ts.map +0 -1
- package/dist/parsers/ConfluenceParser.js +0 -797
- package/dist/parsers/ConfluenceParser.js.map +0 -1
- package/dist/parsers/MarkdownParser.d.ts +0 -26
- package/dist/parsers/MarkdownParser.d.ts.map +0 -1
- package/dist/parsers/MarkdownParser.js +0 -982
- package/dist/parsers/MarkdownParser.js.map +0 -1
- package/dist/parsers/index.d.ts +0 -8
- package/dist/parsers/index.d.ts.map +0 -1
- package/dist/parsers/index.js +0 -8
- package/dist/parsers/index.js.map +0 -1
- package/dist/schemas/ConfluenceSchema.d.ts +0 -21
- package/dist/schemas/ConfluenceSchema.d.ts.map +0 -1
- package/dist/schemas/ConfluenceSchema.js +0 -38
- package/dist/schemas/ConfluenceSchema.js.map +0 -1
- package/dist/schemas/ConversionSchema.d.ts +0 -35
- package/dist/schemas/ConversionSchema.d.ts.map +0 -1
- package/dist/schemas/ConversionSchema.js +0 -208
- package/dist/schemas/ConversionSchema.js.map +0 -1
- package/dist/schemas/MarkdownSchema.d.ts +0 -21
- package/dist/schemas/MarkdownSchema.d.ts.map +0 -1
- package/dist/schemas/MarkdownSchema.js +0 -38
- package/dist/schemas/MarkdownSchema.js.map +0 -1
- package/dist/schemas/hast/HastFromHtml.d.ts +0 -27
- package/dist/schemas/hast/HastFromHtml.d.ts.map +0 -1
- package/dist/schemas/hast/HastFromHtml.js +0 -107
- package/dist/schemas/hast/HastFromHtml.js.map +0 -1
- package/dist/schemas/hast/HastSchema.d.ts +0 -195
- package/dist/schemas/hast/HastSchema.d.ts.map +0 -1
- package/dist/schemas/hast/HastSchema.js +0 -183
- package/dist/schemas/hast/HastSchema.js.map +0 -1
- package/dist/schemas/hast/index.d.ts +0 -9
- package/dist/schemas/hast/index.d.ts.map +0 -1
- package/dist/schemas/hast/index.js +0 -3
- package/dist/schemas/hast/index.js.map +0 -1
- package/dist/schemas/index.d.ts +0 -14
- package/dist/schemas/index.d.ts.map +0 -1
- package/dist/schemas/index.js +0 -16
- package/dist/schemas/index.js.map +0 -1
- package/dist/schemas/mdast/MdastFromMarkdown.d.ts +0 -30
- package/dist/schemas/mdast/MdastFromMarkdown.d.ts.map +0 -1
- package/dist/schemas/mdast/MdastFromMarkdown.js +0 -79
- package/dist/schemas/mdast/MdastFromMarkdown.js.map +0 -1
- package/dist/schemas/mdast/MdastSchema.d.ts +0 -385
- package/dist/schemas/mdast/MdastSchema.d.ts.map +0 -1
- package/dist/schemas/mdast/MdastSchema.js +0 -266
- package/dist/schemas/mdast/MdastSchema.js.map +0 -1
- package/dist/schemas/mdast/index.d.ts +0 -10
- package/dist/schemas/mdast/index.d.ts.map +0 -1
- package/dist/schemas/mdast/index.js +0 -4
- package/dist/schemas/mdast/index.js.map +0 -1
- package/dist/schemas/mdast/mdastToString.d.ts +0 -13
- package/dist/schemas/mdast/mdastToString.d.ts.map +0 -1
- package/dist/schemas/mdast/mdastToString.js +0 -85
- package/dist/schemas/mdast/mdastToString.js.map +0 -1
- package/dist/schemas/nodes/block/BlockSchema.d.ts +0 -43
- package/dist/schemas/nodes/block/BlockSchema.d.ts.map +0 -1
- package/dist/schemas/nodes/block/BlockSchema.js +0 -634
- package/dist/schemas/nodes/block/BlockSchema.js.map +0 -1
- package/dist/schemas/nodes/block/index.d.ts +0 -7
- package/dist/schemas/nodes/block/index.d.ts.map +0 -1
- package/dist/schemas/nodes/block/index.js +0 -7
- package/dist/schemas/nodes/block/index.js.map +0 -1
- package/dist/schemas/nodes/index.d.ts +0 -9
- package/dist/schemas/nodes/index.d.ts.map +0 -1
- package/dist/schemas/nodes/index.js +0 -12
- package/dist/schemas/nodes/index.js.map +0 -1
- package/dist/schemas/nodes/inline/InlineSchema.d.ts +0 -48
- package/dist/schemas/nodes/inline/InlineSchema.d.ts.map +0 -1
- package/dist/schemas/nodes/inline/InlineSchema.js +0 -436
- package/dist/schemas/nodes/inline/InlineSchema.js.map +0 -1
- package/dist/schemas/nodes/inline/index.d.ts +0 -7
- package/dist/schemas/nodes/inline/index.d.ts.map +0 -1
- package/dist/schemas/nodes/inline/index.js +0 -7
- package/dist/schemas/nodes/inline/index.js.map +0 -1
- package/dist/schemas/nodes/macro/MacroSchema.d.ts +0 -27
- package/dist/schemas/nodes/macro/MacroSchema.d.ts.map +0 -1
- package/dist/schemas/nodes/macro/MacroSchema.js +0 -162
- package/dist/schemas/nodes/macro/MacroSchema.js.map +0 -1
- package/dist/schemas/nodes/macro/index.d.ts +0 -7
- package/dist/schemas/nodes/macro/index.d.ts.map +0 -1
- package/dist/schemas/nodes/macro/index.js +0 -7
- package/dist/schemas/nodes/macro/index.js.map +0 -1
- package/dist/schemas/preprocessing/ConfluencePreprocessor.d.ts +0 -24
- package/dist/schemas/preprocessing/ConfluencePreprocessor.d.ts.map +0 -1
- package/dist/schemas/preprocessing/ConfluencePreprocessor.js +0 -359
- package/dist/schemas/preprocessing/ConfluencePreprocessor.js.map +0 -1
- package/dist/schemas/preprocessing/index.d.ts +0 -8
- package/dist/schemas/preprocessing/index.d.ts.map +0 -1
- package/dist/schemas/preprocessing/index.js +0 -2
- package/dist/schemas/preprocessing/index.js.map +0 -1
- package/dist/serializers/ConfluenceSerializer.d.ts +0 -30
- package/dist/serializers/ConfluenceSerializer.d.ts.map +0 -1
- package/dist/serializers/ConfluenceSerializer.js +0 -560
- package/dist/serializers/ConfluenceSerializer.js.map +0 -1
- package/dist/serializers/MarkdownSerializer.d.ts +0 -34
- package/dist/serializers/MarkdownSerializer.d.ts.map +0 -1
- package/dist/serializers/MarkdownSerializer.js +0 -395
- package/dist/serializers/MarkdownSerializer.js.map +0 -1
- package/dist/serializers/index.d.ts +0 -8
- package/dist/serializers/index.d.ts.map +0 -1
- package/dist/serializers/index.js +0 -8
- package/dist/serializers/index.js.map +0 -1
- package/src/SchemaConverterError.ts +0 -108
- package/src/ast/BlockNode.ts +0 -469
- package/src/ast/Document.ts +0 -90
- package/src/ast/InlineNode.ts +0 -323
- package/src/ast/MacroNode.ts +0 -245
- package/src/ast/index.ts +0 -83
- package/src/parsers/ConfluenceParser.ts +0 -956
- package/src/parsers/MarkdownParser.ts +0 -1338
- package/src/parsers/index.ts +0 -8
- package/src/schemas/ConfluenceSchema.ts +0 -56
- package/src/schemas/ConversionSchema.ts +0 -318
- package/src/schemas/MarkdownSchema.ts +0 -56
- package/src/schemas/hast/HastFromHtml.ts +0 -153
- package/src/schemas/hast/HastSchema.ts +0 -274
- package/src/schemas/hast/index.ts +0 -35
- package/src/schemas/index.ts +0 -20
- package/src/schemas/mdast/MdastFromMarkdown.ts +0 -118
- package/src/schemas/mdast/MdastSchema.ts +0 -566
- package/src/schemas/mdast/index.ts +0 -59
- package/src/schemas/mdast/mdastToString.ts +0 -102
- package/src/schemas/nodes/block/BlockSchema.ts +0 -773
- package/src/schemas/nodes/block/index.ts +0 -13
- package/src/schemas/nodes/index.ts +0 -20
- package/src/schemas/nodes/inline/InlineSchema.ts +0 -523
- package/src/schemas/nodes/inline/index.ts +0 -14
- package/src/schemas/nodes/macro/MacroSchema.ts +0 -226
- package/src/schemas/nodes/macro/index.ts +0 -6
- package/src/schemas/preprocessing/ConfluencePreprocessor.ts +0 -455
- package/src/schemas/preprocessing/index.ts +0 -8
- package/src/serializers/ConfluenceSerializer.ts +0 -737
- package/src/serializers/MarkdownSerializer.ts +0 -543
- package/src/serializers/index.ts +0 -8
- package/test/ast/BlockNode.test.ts +0 -265
- package/test/ast/Document.test.ts +0 -126
- package/test/ast/InlineNode.test.ts +0 -161
- package/test/fixtures/integration-test.html.fixture +0 -103
- package/test/fixtures/integration-test.md.expected +0 -257
- package/test/parsers/ConfluenceParser.test.ts +0 -452
- package/test/schemas/ConfluencePreprocessor.test.ts +0 -180
- package/test/schemas/ConversionSchema.test.ts +0 -159
- package/test/schemas/HastSchema.test.ts +0 -138
- package/test/schemas/MdastSchema.test.ts +0 -145
- package/test/schemas/nodes/block/BlockSchema.test.ts +0 -173
- package/test/schemas/nodes/inline/InlineSchema.test.ts +0 -198
- package/test/schemas/nodes/macro/MacroSchema.test.ts +0 -142
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
-
import { Effect, Schema } from "effect"
|
|
3
|
-
import { ConfluenceToMarkdown, DocumentFromHast, DocumentFromMdast } from "../../src/schemas/ConversionSchema.js"
|
|
4
|
-
import { HastFromHtml } from "../../src/schemas/hast/index.js"
|
|
5
|
-
import { MdastFromMarkdown } from "../../src/schemas/mdast/index.js"
|
|
6
|
-
|
|
7
|
-
describe("ConversionSchema", () => {
|
|
8
|
-
describe("DocumentFromHast", () => {
|
|
9
|
-
it.effect("converts simple HAST root to Document", () =>
|
|
10
|
-
Effect.gen(function*() {
|
|
11
|
-
const html = "<h1>Title</h1><p>Hello world</p>"
|
|
12
|
-
const hast = yield* Schema.decode(HastFromHtml)(html)
|
|
13
|
-
const doc = yield* Schema.decode(DocumentFromHast)(hast)
|
|
14
|
-
|
|
15
|
-
expect(doc.version).toBe(1)
|
|
16
|
-
expect(doc.children.length).toBe(2)
|
|
17
|
-
expect(doc.children[0]?._tag).toBe("Heading")
|
|
18
|
-
expect(doc.children[1]?._tag).toBe("Paragraph")
|
|
19
|
-
}))
|
|
20
|
-
|
|
21
|
-
it.effect("handles code blocks", () =>
|
|
22
|
-
Effect.gen(function*() {
|
|
23
|
-
const html = "<pre><code>const x = 1</code></pre>"
|
|
24
|
-
const hast = yield* Schema.decode(HastFromHtml)(html)
|
|
25
|
-
const doc = yield* Schema.decode(DocumentFromHast)(hast)
|
|
26
|
-
|
|
27
|
-
expect(doc.children[0]?._tag).toBe("CodeBlock")
|
|
28
|
-
}))
|
|
29
|
-
|
|
30
|
-
it.effect("handles empty input", () =>
|
|
31
|
-
Effect.gen(function*() {
|
|
32
|
-
const html = ""
|
|
33
|
-
const hast = yield* Schema.decode(HastFromHtml)(html)
|
|
34
|
-
const doc = yield* Schema.decode(DocumentFromHast)(hast)
|
|
35
|
-
|
|
36
|
-
expect(doc.children.length).toBe(0)
|
|
37
|
-
}))
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
describe("DocumentFromMdast", () => {
|
|
41
|
-
it.effect("converts simple MDAST root to Document", () =>
|
|
42
|
-
Effect.gen(function*() {
|
|
43
|
-
const md = "# Title\n\nHello world"
|
|
44
|
-
const mdast = yield* Schema.decode(MdastFromMarkdown)(md)
|
|
45
|
-
const doc = yield* Schema.decode(DocumentFromMdast)(mdast)
|
|
46
|
-
|
|
47
|
-
expect(doc.version).toBe(1)
|
|
48
|
-
expect(doc.children.length).toBe(2)
|
|
49
|
-
expect(doc.children[0]?._tag).toBe("Heading")
|
|
50
|
-
expect(doc.children[1]?._tag).toBe("Paragraph")
|
|
51
|
-
}))
|
|
52
|
-
|
|
53
|
-
it.effect("handles code blocks", () =>
|
|
54
|
-
Effect.gen(function*() {
|
|
55
|
-
const md = "```ts\nconst x = 1\n```"
|
|
56
|
-
const mdast = yield* Schema.decode(MdastFromMarkdown)(md)
|
|
57
|
-
const doc = yield* Schema.decode(DocumentFromMdast)(mdast)
|
|
58
|
-
|
|
59
|
-
expect(doc.children[0]?._tag).toBe("CodeBlock")
|
|
60
|
-
}))
|
|
61
|
-
|
|
62
|
-
it.effect("handles lists", () =>
|
|
63
|
-
Effect.gen(function*() {
|
|
64
|
-
const md = "- Item 1\n- Item 2"
|
|
65
|
-
const mdast = yield* Schema.decode(MdastFromMarkdown)(md)
|
|
66
|
-
const doc = yield* Schema.decode(DocumentFromMdast)(mdast)
|
|
67
|
-
|
|
68
|
-
expect(doc.children[0]?._tag).toBe("List")
|
|
69
|
-
}))
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
describe("ConfluenceToMarkdown", () => {
|
|
73
|
-
it.effect("decodes simple Confluence HTML to Markdown", () =>
|
|
74
|
-
Effect.gen(function*() {
|
|
75
|
-
const html = "<h1>Title</h1><p>Hello world</p>"
|
|
76
|
-
const md = yield* Schema.decode(ConfluenceToMarkdown)(html)
|
|
77
|
-
|
|
78
|
-
expect(md).toContain("# Title")
|
|
79
|
-
expect(md).toContain("Hello world")
|
|
80
|
-
}))
|
|
81
|
-
|
|
82
|
-
it.effect("decodes code blocks", () =>
|
|
83
|
-
Effect.gen(function*() {
|
|
84
|
-
const html = "<pre><code class=\"language-ts\">const x = 1</code></pre>"
|
|
85
|
-
const md = yield* Schema.decode(ConfluenceToMarkdown)(html)
|
|
86
|
-
|
|
87
|
-
expect(md).toContain("```")
|
|
88
|
-
expect(md).toContain("const x = 1")
|
|
89
|
-
}))
|
|
90
|
-
|
|
91
|
-
it.effect("decodes inline formatting", () =>
|
|
92
|
-
Effect.gen(function*() {
|
|
93
|
-
const html = "<p><strong>bold</strong> and <em>italic</em></p>"
|
|
94
|
-
const md = yield* Schema.decode(ConfluenceToMarkdown)(html)
|
|
95
|
-
|
|
96
|
-
expect(md).toContain("**bold**")
|
|
97
|
-
expect(md).toContain("_italic_")
|
|
98
|
-
}))
|
|
99
|
-
|
|
100
|
-
it.effect("encodes Markdown to basic HTML (structure only)", () =>
|
|
101
|
-
Effect.gen(function*() {
|
|
102
|
-
const md = "# Title\n\nHello world"
|
|
103
|
-
const html = yield* Schema.encode(ConfluenceToMarkdown)(md)
|
|
104
|
-
|
|
105
|
-
// Note: basic HTML encoding only preserves structure, not content
|
|
106
|
-
expect(html).toContain("<h1>")
|
|
107
|
-
expect(html).toContain("<p>")
|
|
108
|
-
}))
|
|
109
|
-
|
|
110
|
-
it.effect("handles links", () =>
|
|
111
|
-
Effect.gen(function*() {
|
|
112
|
-
const html = "<p><a href=\"https://example.com\">Click here</a></p>"
|
|
113
|
-
const md = yield* Schema.decode(ConfluenceToMarkdown)(html)
|
|
114
|
-
|
|
115
|
-
expect(md).toContain("[Click here](https://example.com)")
|
|
116
|
-
}))
|
|
117
|
-
|
|
118
|
-
it.effect("handles horizontal rules", () =>
|
|
119
|
-
Effect.gen(function*() {
|
|
120
|
-
const html = "<hr />"
|
|
121
|
-
const md = yield* Schema.decode(ConfluenceToMarkdown)(html)
|
|
122
|
-
|
|
123
|
-
expect(md).toContain("---")
|
|
124
|
-
}))
|
|
125
|
-
|
|
126
|
-
it.effect("handles lists", () =>
|
|
127
|
-
Effect.gen(function*() {
|
|
128
|
-
const html = "<ul><li><p>Item 1</p></li><li><p>Item 2</p></li></ul>"
|
|
129
|
-
const md = yield* Schema.decode(ConfluenceToMarkdown)(html)
|
|
130
|
-
|
|
131
|
-
expect(md).toContain("- ")
|
|
132
|
-
expect(md).toContain("Item 1")
|
|
133
|
-
expect(md).toContain("Item 2")
|
|
134
|
-
}))
|
|
135
|
-
|
|
136
|
-
it.effect("handles tables", () =>
|
|
137
|
-
Effect.gen(function*() {
|
|
138
|
-
const html = "<table><tr><th>A</th></tr><tr><td>1</td></tr></table>"
|
|
139
|
-
const md = yield* Schema.decode(ConfluenceToMarkdown)(html)
|
|
140
|
-
|
|
141
|
-
expect(md).toContain("|")
|
|
142
|
-
expect(md).toContain("---")
|
|
143
|
-
}))
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
describe("roundtrip", () => {
|
|
147
|
-
it.effect("HTML -> Markdown -> HTML preserves structure", () =>
|
|
148
|
-
Effect.gen(function*() {
|
|
149
|
-
// Start from HTML since that direction is fully supported
|
|
150
|
-
const originalHtml = "<h1>Hello</h1><p>World</p>"
|
|
151
|
-
const md = yield* Schema.decode(ConfluenceToMarkdown)(originalHtml)
|
|
152
|
-
const html = yield* Schema.encode(ConfluenceToMarkdown)(md)
|
|
153
|
-
|
|
154
|
-
// Structure is preserved
|
|
155
|
-
expect(html).toContain("<h1>")
|
|
156
|
-
expect(html).toContain("<p>")
|
|
157
|
-
}))
|
|
158
|
-
})
|
|
159
|
-
})
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
-
import * as Effect from "effect/Effect"
|
|
3
|
-
import * as Either from "effect/Either"
|
|
4
|
-
import * as Schema from "effect/Schema"
|
|
5
|
-
import {
|
|
6
|
-
getTextContent,
|
|
7
|
-
HastFromHtml,
|
|
8
|
-
HastNodeSchema,
|
|
9
|
-
HastRootSchema,
|
|
10
|
-
isHastElement,
|
|
11
|
-
isHastText,
|
|
12
|
-
makeHastElement,
|
|
13
|
-
makeHastRoot,
|
|
14
|
-
makeHastText
|
|
15
|
-
} from "../../src/schemas/hast/index.js"
|
|
16
|
-
|
|
17
|
-
describe("HastSchema", () => {
|
|
18
|
-
describe("constructors", () => {
|
|
19
|
-
it("creates text node", () => {
|
|
20
|
-
const node = makeHastText("hello")
|
|
21
|
-
expect(node._tag).toBe("text")
|
|
22
|
-
expect(node.value).toBe("hello")
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it("creates element node", () => {
|
|
26
|
-
const node = makeHastElement("div", { class: "test" }, [makeHastText("child")])
|
|
27
|
-
expect(node._tag).toBe("element")
|
|
28
|
-
expect(node.tagName).toBe("div")
|
|
29
|
-
expect(node.properties.class).toBe("test")
|
|
30
|
-
expect(node.children).toHaveLength(1)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it("creates root node", () => {
|
|
34
|
-
const root = makeHastRoot([makeHastElement("p", {}, [makeHastText("text")])])
|
|
35
|
-
expect(root._tag).toBe("root")
|
|
36
|
-
expect(root.children).toHaveLength(1)
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
describe("type guards", () => {
|
|
41
|
-
it("isHastText returns true for text node", () => {
|
|
42
|
-
expect(isHastText(makeHastText("hello"))).toBe(true)
|
|
43
|
-
expect(isHastText(makeHastElement("div"))).toBe(false)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it("isHastElement returns true for element node", () => {
|
|
47
|
-
expect(isHastElement(makeHastElement("div"))).toBe(true)
|
|
48
|
-
expect(isHastElement(makeHastText("hello"))).toBe(false)
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
describe("getTextContent", () => {
|
|
53
|
-
it("extracts text from text node", () => {
|
|
54
|
-
expect(getTextContent(makeHastText("hello"))).toBe("hello")
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it("extracts text from nested elements", () => {
|
|
58
|
-
const el = makeHastElement("div", {}, [
|
|
59
|
-
makeHastText("hello "),
|
|
60
|
-
makeHastElement("strong", {}, [makeHastText("world")])
|
|
61
|
-
])
|
|
62
|
-
expect(getTextContent(el)).toBe("hello world")
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
describe("HastNodeSchema", () => {
|
|
67
|
-
it("validates text node", () => {
|
|
68
|
-
const result = Schema.decodeUnknownEither(HastNodeSchema)(makeHastText("test"))
|
|
69
|
-
expect(Either.isRight(result)).toBe(true)
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it("validates element node", () => {
|
|
73
|
-
const result = Schema.decodeUnknownEither(HastNodeSchema)(makeHastElement("p"))
|
|
74
|
-
expect(Either.isRight(result)).toBe(true)
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
describe("HastRootSchema", () => {
|
|
79
|
-
it("validates root node", () => {
|
|
80
|
-
const root = makeHastRoot([makeHastElement("p", {}, [makeHastText("text")])])
|
|
81
|
-
const result = Schema.decodeUnknownEither(HastRootSchema)(root)
|
|
82
|
-
expect(Either.isRight(result)).toBe(true)
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
describe("HastFromHtml", () => {
|
|
88
|
-
describe("decode (HTML -> HAST)", () => {
|
|
89
|
-
it.effect("parses simple HTML", () =>
|
|
90
|
-
Effect.gen(function*() {
|
|
91
|
-
const hast = yield* Schema.decode(HastFromHtml)("<p>Hello</p>")
|
|
92
|
-
expect(hast._tag).toBe("root")
|
|
93
|
-
expect(hast.children).toHaveLength(1)
|
|
94
|
-
const p = hast.children[0]
|
|
95
|
-
expect(isHastElement(p) && p.tagName).toBe("p")
|
|
96
|
-
}))
|
|
97
|
-
|
|
98
|
-
it.effect("parses nested HTML", () =>
|
|
99
|
-
Effect.gen(function*() {
|
|
100
|
-
const hast = yield* Schema.decode(HastFromHtml)("<div><p>Text</p></div>")
|
|
101
|
-
expect(hast.children).toHaveLength(1)
|
|
102
|
-
const div = hast.children[0]
|
|
103
|
-
if (isHastElement(div)) {
|
|
104
|
-
expect(div.tagName).toBe("div")
|
|
105
|
-
expect(div.children).toHaveLength(1)
|
|
106
|
-
}
|
|
107
|
-
}))
|
|
108
|
-
|
|
109
|
-
it.effect("parses HTML with attributes", () =>
|
|
110
|
-
Effect.gen(function*() {
|
|
111
|
-
const hast = yield* Schema.decode(HastFromHtml)("<a href=\"https://example.com\">Link</a>")
|
|
112
|
-
const a = hast.children[0]
|
|
113
|
-
if (isHastElement(a)) {
|
|
114
|
-
expect(a.properties.href).toBe("https://example.com")
|
|
115
|
-
}
|
|
116
|
-
}))
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
describe("encode (HAST -> HTML)", () => {
|
|
120
|
-
it.effect("stringifies HAST to HTML", () =>
|
|
121
|
-
Effect.gen(function*() {
|
|
122
|
-
const hast = makeHastRoot([
|
|
123
|
-
makeHastElement("p", {}, [makeHastText("Hello")])
|
|
124
|
-
])
|
|
125
|
-
const html = yield* Schema.encode(HastFromHtml)(hast)
|
|
126
|
-
expect(html).toContain("<p>")
|
|
127
|
-
expect(html).toContain("Hello")
|
|
128
|
-
}))
|
|
129
|
-
|
|
130
|
-
it.effect("roundtrips HTML", () =>
|
|
131
|
-
Effect.gen(function*() {
|
|
132
|
-
const original = "<p>Test paragraph</p>"
|
|
133
|
-
const hast = yield* Schema.decode(HastFromHtml)(original)
|
|
134
|
-
const html = yield* Schema.encode(HastFromHtml)(hast)
|
|
135
|
-
expect(html.replace(/\s/g, "")).toBe(original.replace(/\s/g, ""))
|
|
136
|
-
}))
|
|
137
|
-
})
|
|
138
|
-
})
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
-
import * as Effect from "effect/Effect"
|
|
3
|
-
import * as Either from "effect/Either"
|
|
4
|
-
import * as Schema from "effect/Schema"
|
|
5
|
-
import {
|
|
6
|
-
isMdastHeading,
|
|
7
|
-
isMdastParagraph,
|
|
8
|
-
isMdastText,
|
|
9
|
-
makeMdastHeading,
|
|
10
|
-
makeMdastParagraph,
|
|
11
|
-
makeMdastRoot,
|
|
12
|
-
makeMdastText,
|
|
13
|
-
MdastFromMarkdown,
|
|
14
|
-
MdastRootSchema,
|
|
15
|
-
MdastTextSchema
|
|
16
|
-
} from "../../src/schemas/mdast/index.js"
|
|
17
|
-
|
|
18
|
-
describe("MdastSchema", () => {
|
|
19
|
-
describe("constructors", () => {
|
|
20
|
-
it("creates text node", () => {
|
|
21
|
-
const node = makeMdastText("hello")
|
|
22
|
-
expect(node.type).toBe("text")
|
|
23
|
-
expect(node.value).toBe("hello")
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it("creates heading node", () => {
|
|
27
|
-
const node = makeMdastHeading(2, [makeMdastText("Title")])
|
|
28
|
-
expect(node.type).toBe("heading")
|
|
29
|
-
expect(node.depth).toBe(2)
|
|
30
|
-
expect(node.children).toHaveLength(1)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it("creates paragraph node", () => {
|
|
34
|
-
const node = makeMdastParagraph([makeMdastText("content")])
|
|
35
|
-
expect(node.type).toBe("paragraph")
|
|
36
|
-
expect(node.children).toHaveLength(1)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it("creates root node", () => {
|
|
40
|
-
const root = makeMdastRoot([makeMdastParagraph([makeMdastText("text")])])
|
|
41
|
-
expect(root.type).toBe("root")
|
|
42
|
-
expect(root.children).toHaveLength(1)
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
describe("type guards", () => {
|
|
47
|
-
it("isMdastText returns true for text node", () => {
|
|
48
|
-
expect(isMdastText(makeMdastText("hello"))).toBe(true)
|
|
49
|
-
expect(isMdastText(makeMdastHeading(1, []))).toBe(false)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it("isMdastHeading returns true for heading node", () => {
|
|
53
|
-
expect(isMdastHeading(makeMdastHeading(1, []))).toBe(true)
|
|
54
|
-
expect(isMdastHeading(makeMdastText("hello"))).toBe(false)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it("isMdastParagraph returns true for paragraph node", () => {
|
|
58
|
-
expect(isMdastParagraph(makeMdastParagraph([]))).toBe(true)
|
|
59
|
-
expect(isMdastParagraph(makeMdastText("hello"))).toBe(false)
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
describe("MdastTextSchema", () => {
|
|
64
|
-
it("validates text node", () => {
|
|
65
|
-
const result = Schema.decodeUnknownEither(MdastTextSchema)(makeMdastText("test"))
|
|
66
|
-
expect(Either.isRight(result)).toBe(true)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it("rejects invalid type", () => {
|
|
70
|
-
const result = Schema.decodeUnknownEither(MdastTextSchema)({ type: "other", value: "x" })
|
|
71
|
-
expect(Either.isLeft(result)).toBe(true)
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
describe("MdastRootSchema", () => {
|
|
76
|
-
it("validates root node", () => {
|
|
77
|
-
const root = makeMdastRoot([makeMdastParagraph([makeMdastText("text")])])
|
|
78
|
-
const result = Schema.decodeUnknownEither(MdastRootSchema)(root)
|
|
79
|
-
expect(Either.isRight(result)).toBe(true)
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
describe("MdastFromMarkdown", () => {
|
|
85
|
-
describe("decode (Markdown -> MDAST)", () => {
|
|
86
|
-
it.effect("parses heading", () =>
|
|
87
|
-
Effect.gen(function*() {
|
|
88
|
-
const mdast = yield* Schema.decode(MdastFromMarkdown)("# Hello")
|
|
89
|
-
expect(mdast.type).toBe("root")
|
|
90
|
-
expect(mdast.children).toHaveLength(1)
|
|
91
|
-
const heading = mdast.children[0]
|
|
92
|
-
expect(heading.type).toBe("heading")
|
|
93
|
-
}))
|
|
94
|
-
|
|
95
|
-
it.effect("parses paragraph", () =>
|
|
96
|
-
Effect.gen(function*() {
|
|
97
|
-
const mdast = yield* Schema.decode(MdastFromMarkdown)("Hello world")
|
|
98
|
-
expect(mdast.children).toHaveLength(1)
|
|
99
|
-
expect(mdast.children[0].type).toBe("paragraph")
|
|
100
|
-
}))
|
|
101
|
-
|
|
102
|
-
it.effect("parses code block", () =>
|
|
103
|
-
Effect.gen(function*() {
|
|
104
|
-
const mdast = yield* Schema.decode(MdastFromMarkdown)("```ts\nconst x = 1\n```")
|
|
105
|
-
expect(mdast.children).toHaveLength(1)
|
|
106
|
-
const code = mdast.children[0]
|
|
107
|
-
expect(code.type).toBe("code")
|
|
108
|
-
}))
|
|
109
|
-
|
|
110
|
-
it.effect("parses list", () =>
|
|
111
|
-
Effect.gen(function*() {
|
|
112
|
-
const mdast = yield* Schema.decode(MdastFromMarkdown)("- item 1\n- item 2")
|
|
113
|
-
expect(mdast.children).toHaveLength(1)
|
|
114
|
-
expect(mdast.children[0].type).toBe("list")
|
|
115
|
-
}))
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
describe("encode (MDAST -> Markdown)", () => {
|
|
119
|
-
it.effect("stringifies heading", () =>
|
|
120
|
-
Effect.gen(function*() {
|
|
121
|
-
const mdast = makeMdastRoot([
|
|
122
|
-
makeMdastHeading(1, [makeMdastText("Title")])
|
|
123
|
-
])
|
|
124
|
-
const md = yield* Schema.encode(MdastFromMarkdown)(mdast)
|
|
125
|
-
expect(md.trim()).toBe("# Title")
|
|
126
|
-
}))
|
|
127
|
-
|
|
128
|
-
it.effect("stringifies paragraph", () =>
|
|
129
|
-
Effect.gen(function*() {
|
|
130
|
-
const mdast = makeMdastRoot([
|
|
131
|
-
makeMdastParagraph([makeMdastText("Hello world")])
|
|
132
|
-
])
|
|
133
|
-
const md = yield* Schema.encode(MdastFromMarkdown)(mdast)
|
|
134
|
-
expect(md.trim()).toBe("Hello world")
|
|
135
|
-
}))
|
|
136
|
-
|
|
137
|
-
it.effect("roundtrips markdown", () =>
|
|
138
|
-
Effect.gen(function*() {
|
|
139
|
-
const original = "# Title\n\nParagraph text."
|
|
140
|
-
const mdast = yield* Schema.decode(MdastFromMarkdown)(original)
|
|
141
|
-
const md = yield* Schema.encode(MdastFromMarkdown)(mdast)
|
|
142
|
-
expect(md.trim()).toBe(original)
|
|
143
|
-
}))
|
|
144
|
-
})
|
|
145
|
-
})
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
-
import type { UnsupportedBlock } from "../../../../src/ast/BlockNode.js"
|
|
3
|
-
import {
|
|
4
|
-
CodeBlock,
|
|
5
|
-
Heading,
|
|
6
|
-
Paragraph,
|
|
7
|
-
Table,
|
|
8
|
-
TableCell,
|
|
9
|
-
TableRow,
|
|
10
|
-
ThematicBreak
|
|
11
|
-
} from "../../../../src/ast/BlockNode.js"
|
|
12
|
-
import { Text } from "../../../../src/ast/InlineNode.js"
|
|
13
|
-
import { makeMdastHeading, makeMdastParagraph, makeMdastText } from "../../../../src/schemas/mdast/index.js"
|
|
14
|
-
import { blockNodeFromMdast, blockNodeToHast, blockNodeToMdast } from "../../../../src/schemas/nodes/block/index.js"
|
|
15
|
-
|
|
16
|
-
describe("BlockSchema", () => {
|
|
17
|
-
describe("blockNodeToHast", () => {
|
|
18
|
-
it("converts Heading to hast h element", () => {
|
|
19
|
-
const heading = new Heading({ level: 2, children: [new Text({ value: "Title" })] })
|
|
20
|
-
const result = blockNodeToHast(heading)
|
|
21
|
-
expect(result._tag).toBe("element")
|
|
22
|
-
expect(result.tagName).toBe("h2")
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it("converts Paragraph to hast p element", () => {
|
|
26
|
-
const para = new Paragraph({ children: [new Text({ value: "Hello" })] })
|
|
27
|
-
const result = blockNodeToHast(para)
|
|
28
|
-
expect(result._tag).toBe("element")
|
|
29
|
-
expect(result.tagName).toBe("p")
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it("converts CodeBlock to hast pre/code elements", () => {
|
|
33
|
-
const code = new CodeBlock({ code: "const x = 1", language: "ts" })
|
|
34
|
-
const result = blockNodeToHast(code)
|
|
35
|
-
expect(result._tag).toBe("element")
|
|
36
|
-
expect(result.tagName).toBe("pre")
|
|
37
|
-
expect(result.properties?.dataLanguage).toBe("ts")
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it("converts ThematicBreak to hast hr element", () => {
|
|
41
|
-
const hr = new ThematicBreak({})
|
|
42
|
-
const result = blockNodeToHast(hr)
|
|
43
|
-
expect(result._tag).toBe("element")
|
|
44
|
-
expect(result.tagName).toBe("hr")
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it("converts Table to hast table element", () => {
|
|
48
|
-
const table = new Table({
|
|
49
|
-
header: new TableRow({
|
|
50
|
-
cells: [new TableCell({ isHeader: true, children: [new Text({ value: "Col" })] })]
|
|
51
|
-
}),
|
|
52
|
-
rows: [
|
|
53
|
-
new TableRow({
|
|
54
|
-
cells: [new TableCell({ children: [new Text({ value: "Val" })] })]
|
|
55
|
-
})
|
|
56
|
-
]
|
|
57
|
-
})
|
|
58
|
-
const result = blockNodeToHast(table)
|
|
59
|
-
expect(result._tag).toBe("element")
|
|
60
|
-
expect(result.tagName).toBe("table")
|
|
61
|
-
})
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
describe("blockNodeToMdast", () => {
|
|
65
|
-
it("converts Heading to mdast heading", () => {
|
|
66
|
-
const heading = new Heading({ level: 1, children: [new Text({ value: "Title" })] })
|
|
67
|
-
const result = blockNodeToMdast(heading)
|
|
68
|
-
expect(result.type).toBe("heading")
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it("converts Paragraph to mdast paragraph", () => {
|
|
72
|
-
const para = new Paragraph({ children: [new Text({ value: "Hello" })] })
|
|
73
|
-
const result = blockNodeToMdast(para)
|
|
74
|
-
expect(result.type).toBe("paragraph")
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it("converts CodeBlock to mdast code", () => {
|
|
78
|
-
const code = new CodeBlock({ code: "const x = 1", language: "ts" })
|
|
79
|
-
const result = blockNodeToMdast(code)
|
|
80
|
-
expect(result.type).toBe("code")
|
|
81
|
-
expect((result as { value: string }).value).toBe("const x = 1")
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it("converts ThematicBreak to mdast thematicBreak", () => {
|
|
85
|
-
const hr = new ThematicBreak({})
|
|
86
|
-
const result = blockNodeToMdast(hr)
|
|
87
|
-
expect(result.type).toBe("thematicBreak")
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it("converts Table to mdast table", () => {
|
|
91
|
-
const table = new Table({ rows: [] })
|
|
92
|
-
const result = blockNodeToMdast(table)
|
|
93
|
-
expect(result.type).toBe("table")
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
describe("blockNodeFromMdast", () => {
|
|
98
|
-
it("converts mdast heading to Heading", () => {
|
|
99
|
-
const mdast = makeMdastHeading(2, [makeMdastText("Title")])
|
|
100
|
-
const result = blockNodeFromMdast(mdast)
|
|
101
|
-
expect(result._tag).toBe("Heading")
|
|
102
|
-
expect((result as Heading).level).toBe(2)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it("converts mdast paragraph to Paragraph", () => {
|
|
106
|
-
const mdast = makeMdastParagraph([makeMdastText("Hello")])
|
|
107
|
-
const result = blockNodeFromMdast(mdast)
|
|
108
|
-
expect(result._tag).toBe("Paragraph")
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it("converts mdast code to CodeBlock", () => {
|
|
112
|
-
const mdast = { type: "code" as const, value: "const x = 1", lang: "ts" }
|
|
113
|
-
const result = blockNodeFromMdast(mdast)
|
|
114
|
-
expect(result._tag).toBe("CodeBlock")
|
|
115
|
-
expect((result as CodeBlock).code).toBe("const x = 1")
|
|
116
|
-
expect((result as CodeBlock).language).toBe("ts")
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
it("converts mdast thematicBreak to ThematicBreak", () => {
|
|
120
|
-
const mdast = { type: "thematicBreak" as const }
|
|
121
|
-
const result = blockNodeFromMdast(mdast)
|
|
122
|
-
expect(result._tag).toBe("ThematicBreak")
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
it("converts mdast blockquote to BlockQuote", () => {
|
|
126
|
-
const mdast = {
|
|
127
|
-
type: "blockquote" as const,
|
|
128
|
-
children: [makeMdastParagraph([makeMdastText("Quote")])]
|
|
129
|
-
}
|
|
130
|
-
const result = blockNodeFromMdast(mdast)
|
|
131
|
-
expect(result._tag).toBe("BlockQuote")
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it("converts mdast list to List", () => {
|
|
135
|
-
const mdast = {
|
|
136
|
-
type: "list" as const,
|
|
137
|
-
ordered: true,
|
|
138
|
-
children: [{
|
|
139
|
-
type: "listItem" as const,
|
|
140
|
-
children: [makeMdastParagraph([makeMdastText("Item")])]
|
|
141
|
-
}]
|
|
142
|
-
}
|
|
143
|
-
const result = blockNodeFromMdast(mdast)
|
|
144
|
-
expect(result._tag).toBe("List")
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
it("converts mdast html to UnsupportedBlock", () => {
|
|
148
|
-
const mdast = { type: "html" as const, value: "<custom>x</custom>" }
|
|
149
|
-
const result = blockNodeFromMdast(mdast)
|
|
150
|
-
expect(result._tag).toBe("UnsupportedBlock")
|
|
151
|
-
expect((result as UnsupportedBlock).rawMarkdown).toBe("<custom>x</custom>")
|
|
152
|
-
})
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
describe("roundtrip", () => {
|
|
156
|
-
it("Heading roundtrips through MDAST", () => {
|
|
157
|
-
const original = new Heading({ level: 3, children: [new Text({ value: "Title" })] })
|
|
158
|
-
const mdast = blockNodeToMdast(original)
|
|
159
|
-
const result = blockNodeFromMdast(mdast)
|
|
160
|
-
expect(result._tag).toBe("Heading")
|
|
161
|
-
expect((result as Heading).level).toBe(3)
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it("CodeBlock roundtrips through MDAST", () => {
|
|
165
|
-
const original = new CodeBlock({ code: "x = 1", language: "py" })
|
|
166
|
-
const mdast = blockNodeToMdast(original)
|
|
167
|
-
const result = blockNodeFromMdast(mdast)
|
|
168
|
-
expect(result._tag).toBe("CodeBlock")
|
|
169
|
-
expect((result as CodeBlock).code).toBe("x = 1")
|
|
170
|
-
expect((result as CodeBlock).language).toBe("py")
|
|
171
|
-
})
|
|
172
|
-
})
|
|
173
|
-
})
|