@knpkv/confluence-to-markdown 0.2.0 → 0.4.2

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 (336) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/LICENSE +21 -0
  3. package/README.md +282 -14
  4. package/dist/ConfluenceAuth.d.ts +76 -0
  5. package/dist/ConfluenceAuth.d.ts.map +1 -0
  6. package/dist/ConfluenceAuth.js +366 -0
  7. package/dist/ConfluenceAuth.js.map +1 -0
  8. package/dist/ConfluenceClient.d.ts +26 -12
  9. package/dist/ConfluenceClient.d.ts.map +1 -1
  10. package/dist/ConfluenceClient.js +139 -97
  11. package/dist/ConfluenceClient.js.map +1 -1
  12. package/dist/ConfluenceConfig.d.ts +4 -24
  13. package/dist/ConfluenceConfig.d.ts.map +1 -1
  14. package/dist/ConfluenceConfig.js +45 -7
  15. package/dist/ConfluenceConfig.js.map +1 -1
  16. package/dist/ConfluenceError.d.ts +99 -16
  17. package/dist/ConfluenceError.d.ts.map +1 -1
  18. package/dist/ConfluenceError.js +88 -5
  19. package/dist/ConfluenceError.js.map +1 -1
  20. package/dist/GitError.d.ts +103 -0
  21. package/dist/GitError.d.ts.map +1 -0
  22. package/dist/GitError.js +85 -0
  23. package/dist/GitError.js.map +1 -0
  24. package/dist/GitService.d.ts +175 -0
  25. package/dist/GitService.d.ts.map +1 -0
  26. package/dist/GitService.js +431 -0
  27. package/dist/GitService.js.map +1 -0
  28. package/dist/LocalFileSystem.d.ts +29 -4
  29. package/dist/LocalFileSystem.d.ts.map +1 -1
  30. package/dist/LocalFileSystem.js +80 -6
  31. package/dist/LocalFileSystem.js.map +1 -1
  32. package/dist/MarkdownConverter.d.ts +49 -2
  33. package/dist/MarkdownConverter.d.ts.map +1 -1
  34. package/dist/MarkdownConverter.js +73 -111
  35. package/dist/MarkdownConverter.js.map +1 -1
  36. package/dist/SchemaConverterError.d.ts +108 -0
  37. package/dist/SchemaConverterError.d.ts.map +1 -0
  38. package/dist/SchemaConverterError.js +84 -0
  39. package/dist/SchemaConverterError.js.map +1 -0
  40. package/dist/Schemas.d.ts +225 -1
  41. package/dist/Schemas.d.ts.map +1 -1
  42. package/dist/Schemas.js +155 -6
  43. package/dist/Schemas.js.map +1 -1
  44. package/dist/SyncEngine.d.ts +30 -20
  45. package/dist/SyncEngine.d.ts.map +1 -1
  46. package/dist/SyncEngine.js +566 -117
  47. package/dist/SyncEngine.js.map +1 -1
  48. package/dist/ast/BlockNode.d.ts +468 -0
  49. package/dist/ast/BlockNode.d.ts.map +1 -0
  50. package/dist/ast/BlockNode.js +319 -0
  51. package/dist/ast/BlockNode.js.map +1 -0
  52. package/dist/ast/Document.d.ts +244 -0
  53. package/dist/ast/Document.d.ts.map +1 -0
  54. package/dist/ast/Document.js +69 -0
  55. package/dist/ast/Document.js.map +1 -0
  56. package/dist/ast/InlineNode.d.ts +477 -0
  57. package/dist/ast/InlineNode.d.ts.map +1 -0
  58. package/dist/ast/InlineNode.js +263 -0
  59. package/dist/ast/InlineNode.js.map +1 -0
  60. package/dist/ast/MacroNode.d.ts +267 -0
  61. package/dist/ast/MacroNode.d.ts.map +1 -0
  62. package/dist/ast/MacroNode.js +164 -0
  63. package/dist/ast/MacroNode.js.map +1 -0
  64. package/dist/ast/index.d.ts +10 -0
  65. package/dist/ast/index.d.ts.map +1 -0
  66. package/dist/ast/index.js +14 -0
  67. package/dist/ast/index.js.map +1 -0
  68. package/dist/bin.js +33 -149
  69. package/dist/bin.js.map +1 -1
  70. package/dist/commands/auth.d.ts +15 -0
  71. package/dist/commands/auth.d.ts.map +1 -0
  72. package/dist/commands/auth.js +86 -0
  73. package/dist/commands/auth.js.map +1 -0
  74. package/dist/commands/clone.d.ts +12 -0
  75. package/dist/commands/clone.d.ts.map +1 -0
  76. package/dist/commands/clone.js +93 -0
  77. package/dist/commands/clone.js.map +1 -0
  78. package/dist/commands/delete.d.ts +13 -0
  79. package/dist/commands/delete.d.ts.map +1 -0
  80. package/dist/commands/delete.js +48 -0
  81. package/dist/commands/delete.js.map +1 -0
  82. package/dist/commands/errorHandler.d.ts +14 -0
  83. package/dist/commands/errorHandler.d.ts.map +1 -0
  84. package/dist/commands/errorHandler.js +33 -0
  85. package/dist/commands/errorHandler.js.map +1 -0
  86. package/dist/commands/git.d.ts +22 -0
  87. package/dist/commands/git.d.ts.map +1 -0
  88. package/dist/commands/git.js +72 -0
  89. package/dist/commands/git.js.map +1 -0
  90. package/dist/commands/index.d.ts +11 -0
  91. package/dist/commands/index.d.ts.map +1 -0
  92. package/dist/commands/index.js +11 -0
  93. package/dist/commands/index.js.map +1 -0
  94. package/dist/commands/layers.d.ts +31 -0
  95. package/dist/commands/layers.d.ts.map +1 -0
  96. package/dist/commands/layers.js +137 -0
  97. package/dist/commands/layers.js.map +1 -0
  98. package/dist/commands/new.d.ts +9 -0
  99. package/dist/commands/new.d.ts.map +1 -0
  100. package/dist/commands/new.js +80 -0
  101. package/dist/commands/new.js.map +1 -0
  102. package/dist/commands/pageTree.d.ts +18 -0
  103. package/dist/commands/pageTree.d.ts.map +1 -0
  104. package/dist/commands/pageTree.js +20 -0
  105. package/dist/commands/pageTree.js.map +1 -0
  106. package/dist/commands/shared.d.ts +15 -0
  107. package/dist/commands/shared.d.ts.map +1 -0
  108. package/dist/commands/shared.js +27 -0
  109. package/dist/commands/shared.js.map +1 -0
  110. package/dist/commands/sync.d.ts +15 -0
  111. package/dist/commands/sync.d.ts.map +1 -0
  112. package/dist/commands/sync.js +101 -0
  113. package/dist/commands/sync.js.map +1 -0
  114. package/dist/index.d.ts +10 -1
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +14 -0
  117. package/dist/index.js.map +1 -1
  118. package/dist/internal/NodeLayers.d.ts +7 -0
  119. package/dist/internal/NodeLayers.d.ts.map +1 -0
  120. package/dist/internal/NodeLayers.js +19 -0
  121. package/dist/internal/NodeLayers.js.map +1 -0
  122. package/dist/internal/frontmatter.d.ts +10 -0
  123. package/dist/internal/frontmatter.d.ts.map +1 -1
  124. package/dist/internal/frontmatter.js +16 -0
  125. package/dist/internal/frontmatter.js.map +1 -1
  126. package/dist/internal/gitCommands.d.ts +78 -0
  127. package/dist/internal/gitCommands.d.ts.map +1 -0
  128. package/dist/internal/gitCommands.js +156 -0
  129. package/dist/internal/gitCommands.js.map +1 -0
  130. package/dist/internal/hashUtils.d.ts +42 -1
  131. package/dist/internal/hashUtils.d.ts.map +1 -1
  132. package/dist/internal/hashUtils.js +38 -2
  133. package/dist/internal/hashUtils.js.map +1 -1
  134. package/dist/internal/oauthServer.d.ts +55 -0
  135. package/dist/internal/oauthServer.d.ts.map +1 -0
  136. package/dist/internal/oauthServer.js +110 -0
  137. package/dist/internal/oauthServer.js.map +1 -0
  138. package/dist/internal/pathUtils.d.ts +21 -4
  139. package/dist/internal/pathUtils.d.ts.map +1 -1
  140. package/dist/internal/pathUtils.js +24 -13
  141. package/dist/internal/pathUtils.js.map +1 -1
  142. package/dist/internal/tokenStorage.d.ts +75 -0
  143. package/dist/internal/tokenStorage.d.ts.map +1 -0
  144. package/dist/internal/tokenStorage.js +149 -0
  145. package/dist/internal/tokenStorage.js.map +1 -0
  146. package/dist/internal/userCache.d.ts +42 -0
  147. package/dist/internal/userCache.d.ts.map +1 -0
  148. package/dist/internal/userCache.js +51 -0
  149. package/dist/internal/userCache.js.map +1 -0
  150. package/dist/parsers/ConfluenceParser.d.ts +26 -0
  151. package/dist/parsers/ConfluenceParser.d.ts.map +1 -0
  152. package/dist/parsers/ConfluenceParser.js +792 -0
  153. package/dist/parsers/ConfluenceParser.js.map +1 -0
  154. package/dist/parsers/MarkdownParser.d.ts +26 -0
  155. package/dist/parsers/MarkdownParser.d.ts.map +1 -0
  156. package/dist/parsers/MarkdownParser.js +873 -0
  157. package/dist/parsers/MarkdownParser.js.map +1 -0
  158. package/dist/parsers/index.d.ts +8 -0
  159. package/dist/parsers/index.d.ts.map +1 -0
  160. package/dist/parsers/index.js +8 -0
  161. package/dist/parsers/index.js.map +1 -0
  162. package/dist/schemas/ConfluenceSchema.d.ts +21 -0
  163. package/dist/schemas/ConfluenceSchema.d.ts.map +1 -0
  164. package/dist/schemas/ConfluenceSchema.js +38 -0
  165. package/dist/schemas/ConfluenceSchema.js.map +1 -0
  166. package/dist/schemas/ConversionSchema.d.ts +35 -0
  167. package/dist/schemas/ConversionSchema.d.ts.map +1 -0
  168. package/dist/schemas/ConversionSchema.js +208 -0
  169. package/dist/schemas/ConversionSchema.js.map +1 -0
  170. package/dist/schemas/MarkdownSchema.d.ts +21 -0
  171. package/dist/schemas/MarkdownSchema.d.ts.map +1 -0
  172. package/dist/schemas/MarkdownSchema.js +38 -0
  173. package/dist/schemas/MarkdownSchema.js.map +1 -0
  174. package/dist/schemas/hast/HastFromHtml.d.ts +27 -0
  175. package/dist/schemas/hast/HastFromHtml.d.ts.map +1 -0
  176. package/dist/schemas/hast/HastFromHtml.js +107 -0
  177. package/dist/schemas/hast/HastFromHtml.js.map +1 -0
  178. package/dist/schemas/hast/HastSchema.d.ts +195 -0
  179. package/dist/schemas/hast/HastSchema.d.ts.map +1 -0
  180. package/dist/schemas/hast/HastSchema.js +183 -0
  181. package/dist/schemas/hast/HastSchema.js.map +1 -0
  182. package/dist/schemas/hast/index.d.ts +9 -0
  183. package/dist/schemas/hast/index.d.ts.map +1 -0
  184. package/dist/schemas/hast/index.js +3 -0
  185. package/dist/schemas/hast/index.js.map +1 -0
  186. package/dist/schemas/index.d.ts +14 -0
  187. package/dist/schemas/index.d.ts.map +1 -0
  188. package/dist/schemas/index.js +16 -0
  189. package/dist/schemas/index.js.map +1 -0
  190. package/dist/schemas/mdast/MdastFromMarkdown.d.ts +30 -0
  191. package/dist/schemas/mdast/MdastFromMarkdown.d.ts.map +1 -0
  192. package/dist/schemas/mdast/MdastFromMarkdown.js +79 -0
  193. package/dist/schemas/mdast/MdastFromMarkdown.js.map +1 -0
  194. package/dist/schemas/mdast/MdastSchema.d.ts +385 -0
  195. package/dist/schemas/mdast/MdastSchema.d.ts.map +1 -0
  196. package/dist/schemas/mdast/MdastSchema.js +266 -0
  197. package/dist/schemas/mdast/MdastSchema.js.map +1 -0
  198. package/dist/schemas/mdast/index.d.ts +10 -0
  199. package/dist/schemas/mdast/index.d.ts.map +1 -0
  200. package/dist/schemas/mdast/index.js +4 -0
  201. package/dist/schemas/mdast/index.js.map +1 -0
  202. package/dist/schemas/mdast/mdastToString.d.ts +13 -0
  203. package/dist/schemas/mdast/mdastToString.d.ts.map +1 -0
  204. package/dist/schemas/mdast/mdastToString.js +85 -0
  205. package/dist/schemas/mdast/mdastToString.js.map +1 -0
  206. package/dist/schemas/nodes/block/BlockSchema.d.ts +43 -0
  207. package/dist/schemas/nodes/block/BlockSchema.d.ts.map +1 -0
  208. package/dist/schemas/nodes/block/BlockSchema.js +634 -0
  209. package/dist/schemas/nodes/block/BlockSchema.js.map +1 -0
  210. package/dist/schemas/nodes/block/index.d.ts +7 -0
  211. package/dist/schemas/nodes/block/index.d.ts.map +1 -0
  212. package/dist/schemas/nodes/block/index.js +7 -0
  213. package/dist/schemas/nodes/block/index.js.map +1 -0
  214. package/dist/schemas/nodes/index.d.ts +9 -0
  215. package/dist/schemas/nodes/index.d.ts.map +1 -0
  216. package/dist/schemas/nodes/index.js +12 -0
  217. package/dist/schemas/nodes/index.js.map +1 -0
  218. package/dist/schemas/nodes/inline/InlineSchema.d.ts +48 -0
  219. package/dist/schemas/nodes/inline/InlineSchema.d.ts.map +1 -0
  220. package/dist/schemas/nodes/inline/InlineSchema.js +436 -0
  221. package/dist/schemas/nodes/inline/InlineSchema.js.map +1 -0
  222. package/dist/schemas/nodes/inline/index.d.ts +7 -0
  223. package/dist/schemas/nodes/inline/index.d.ts.map +1 -0
  224. package/dist/schemas/nodes/inline/index.js +7 -0
  225. package/dist/schemas/nodes/inline/index.js.map +1 -0
  226. package/dist/schemas/nodes/macro/MacroSchema.d.ts +27 -0
  227. package/dist/schemas/nodes/macro/MacroSchema.d.ts.map +1 -0
  228. package/dist/schemas/nodes/macro/MacroSchema.js +162 -0
  229. package/dist/schemas/nodes/macro/MacroSchema.js.map +1 -0
  230. package/dist/schemas/nodes/macro/index.d.ts +7 -0
  231. package/dist/schemas/nodes/macro/index.d.ts.map +1 -0
  232. package/dist/schemas/nodes/macro/index.js +7 -0
  233. package/dist/schemas/nodes/macro/index.js.map +1 -0
  234. package/dist/schemas/preprocessing/ConfluencePreprocessor.d.ts +24 -0
  235. package/dist/schemas/preprocessing/ConfluencePreprocessor.d.ts.map +1 -0
  236. package/dist/schemas/preprocessing/ConfluencePreprocessor.js +351 -0
  237. package/dist/schemas/preprocessing/ConfluencePreprocessor.js.map +1 -0
  238. package/dist/schemas/preprocessing/index.d.ts +8 -0
  239. package/dist/schemas/preprocessing/index.d.ts.map +1 -0
  240. package/dist/schemas/preprocessing/index.js +2 -0
  241. package/dist/schemas/preprocessing/index.js.map +1 -0
  242. package/dist/serializers/ConfluenceSerializer.d.ts +30 -0
  243. package/dist/serializers/ConfluenceSerializer.d.ts.map +1 -0
  244. package/dist/serializers/ConfluenceSerializer.js +551 -0
  245. package/dist/serializers/ConfluenceSerializer.js.map +1 -0
  246. package/dist/serializers/MarkdownSerializer.d.ts +34 -0
  247. package/dist/serializers/MarkdownSerializer.d.ts.map +1 -0
  248. package/dist/serializers/MarkdownSerializer.js +355 -0
  249. package/dist/serializers/MarkdownSerializer.js.map +1 -0
  250. package/dist/serializers/index.d.ts +8 -0
  251. package/dist/serializers/index.d.ts.map +1 -0
  252. package/dist/serializers/index.js +8 -0
  253. package/dist/serializers/index.js.map +1 -0
  254. package/package.json +32 -21
  255. package/src/ConfluenceAuth.ts +581 -0
  256. package/src/ConfluenceClient.ts +230 -165
  257. package/src/ConfluenceConfig.ts +63 -7
  258. package/src/ConfluenceError.ts +110 -14
  259. package/src/GitError.ts +92 -0
  260. package/src/GitService.ts +859 -0
  261. package/src/LocalFileSystem.ts +179 -9
  262. package/src/MarkdownConverter.ts +126 -122
  263. package/src/SchemaConverterError.ts +108 -0
  264. package/src/Schemas.ts +223 -6
  265. package/src/SyncEngine.ts +745 -162
  266. package/src/ast/BlockNode.ts +425 -0
  267. package/src/ast/Document.ts +90 -0
  268. package/src/ast/InlineNode.ts +323 -0
  269. package/src/ast/MacroNode.ts +245 -0
  270. package/src/ast/index.ts +83 -0
  271. package/src/bin.ts +50 -249
  272. package/src/commands/auth.ts +117 -0
  273. package/src/commands/clone.ts +145 -0
  274. package/src/commands/delete.ts +57 -0
  275. package/src/commands/errorHandler.ts +32 -0
  276. package/src/commands/git.ts +114 -0
  277. package/src/commands/index.ts +10 -0
  278. package/src/commands/layers.ts +211 -0
  279. package/src/commands/new.ts +99 -0
  280. package/src/commands/pageTree.ts +40 -0
  281. package/src/commands/shared.ts +35 -0
  282. package/src/commands/sync.ts +129 -0
  283. package/src/index.ts +21 -1
  284. package/src/internal/NodeLayers.ts +21 -0
  285. package/src/internal/frontmatter.ts +21 -0
  286. package/src/internal/gitCommands.ts +229 -0
  287. package/src/internal/hashUtils.ts +65 -3
  288. package/src/internal/oauthServer.ts +199 -0
  289. package/src/internal/pathUtils.ts +34 -17
  290. package/src/internal/tokenStorage.ts +240 -0
  291. package/src/internal/userCache.ts +90 -0
  292. package/src/parsers/ConfluenceParser.ts +950 -0
  293. package/src/parsers/MarkdownParser.ts +1198 -0
  294. package/src/parsers/index.ts +8 -0
  295. package/src/schemas/ConfluenceSchema.ts +56 -0
  296. package/src/schemas/ConversionSchema.ts +318 -0
  297. package/src/schemas/MarkdownSchema.ts +56 -0
  298. package/src/schemas/hast/HastFromHtml.ts +153 -0
  299. package/src/schemas/hast/HastSchema.ts +274 -0
  300. package/src/schemas/hast/index.ts +35 -0
  301. package/src/schemas/index.ts +20 -0
  302. package/src/schemas/mdast/MdastFromMarkdown.ts +118 -0
  303. package/src/schemas/mdast/MdastSchema.ts +566 -0
  304. package/src/schemas/mdast/index.ts +59 -0
  305. package/src/schemas/mdast/mdastToString.ts +102 -0
  306. package/src/schemas/nodes/block/BlockSchema.ts +773 -0
  307. package/src/schemas/nodes/block/index.ts +13 -0
  308. package/src/schemas/nodes/index.ts +20 -0
  309. package/src/schemas/nodes/inline/InlineSchema.ts +523 -0
  310. package/src/schemas/nodes/inline/index.ts +14 -0
  311. package/src/schemas/nodes/macro/MacroSchema.ts +226 -0
  312. package/src/schemas/nodes/macro/index.ts +6 -0
  313. package/src/schemas/preprocessing/ConfluencePreprocessor.ts +446 -0
  314. package/src/schemas/preprocessing/index.ts +8 -0
  315. package/src/serializers/ConfluenceSerializer.ts +717 -0
  316. package/src/serializers/MarkdownSerializer.ts +493 -0
  317. package/src/serializers/index.ts +8 -0
  318. package/test/GitService.test.ts +209 -0
  319. package/test/MarkdownConverter.test.ts +37 -3
  320. package/test/Schemas.test.ts +97 -2
  321. package/test/ast/BlockNode.test.ts +265 -0
  322. package/test/ast/Document.test.ts +126 -0
  323. package/test/ast/InlineNode.test.ts +161 -0
  324. package/test/fixtures/integration-test.html.fixture +103 -0
  325. package/test/fixtures/integration-test.md.expected +257 -0
  326. package/test/integration.test.ts +269 -0
  327. package/test/oauthServer.test.ts +50 -0
  328. package/test/parsers/ConfluenceParser.test.ts +283 -0
  329. package/test/schemas/ConfluencePreprocessor.test.ts +180 -0
  330. package/test/schemas/ConversionSchema.test.ts +159 -0
  331. package/test/schemas/HastSchema.test.ts +138 -0
  332. package/test/schemas/MdastSchema.test.ts +145 -0
  333. package/test/schemas/nodes/block/BlockSchema.test.ts +173 -0
  334. package/test/schemas/nodes/inline/InlineSchema.test.ts +198 -0
  335. package/test/schemas/nodes/macro/MacroSchema.test.ts +142 -0
  336. package/test/tokenStorage.test.ts +99 -0
@@ -0,0 +1,566 @@
1
+ /**
2
+ * Effect Schema definitions for MDAST (Markdown Abstract Syntax Tree) nodes.
3
+ *
4
+ * MDAST is the intermediate representation used when parsing Markdown.
5
+ * These schemas provide type-safe transformation between raw Markdown and our AST.
6
+ *
7
+ * @module
8
+ */
9
+ import * as Schema from "effect/Schema"
10
+
11
+ /**
12
+ * MDAST text node type.
13
+ *
14
+ * @category Types
15
+ */
16
+ export interface MdastText {
17
+ readonly type: "text"
18
+ readonly value: string
19
+ }
20
+
21
+ /**
22
+ * MDAST inline code node type.
23
+ *
24
+ * @category Types
25
+ */
26
+ export interface MdastInlineCode {
27
+ readonly type: "inlineCode"
28
+ readonly value: string
29
+ }
30
+
31
+ /**
32
+ * MDAST break node type (hard line break).
33
+ *
34
+ * @category Types
35
+ */
36
+ export interface MdastBreak {
37
+ readonly type: "break"
38
+ }
39
+
40
+ /**
41
+ * MDAST thematic break node type (horizontal rule).
42
+ *
43
+ * @category Types
44
+ */
45
+ export interface MdastThematicBreak {
46
+ readonly type: "thematicBreak"
47
+ }
48
+
49
+ /**
50
+ * MDAST heading node type.
51
+ *
52
+ * @category Types
53
+ */
54
+ export interface MdastHeading {
55
+ readonly type: "heading"
56
+ readonly depth: 1 | 2 | 3 | 4 | 5 | 6
57
+ readonly children: ReadonlyArray<MdastPhrasingContent>
58
+ }
59
+
60
+ /**
61
+ * MDAST paragraph node type.
62
+ *
63
+ * @category Types
64
+ */
65
+ export interface MdastParagraph {
66
+ readonly type: "paragraph"
67
+ readonly children: ReadonlyArray<MdastPhrasingContent>
68
+ }
69
+
70
+ /**
71
+ * MDAST code block node type.
72
+ *
73
+ * @category Types
74
+ */
75
+ export interface MdastCode {
76
+ readonly type: "code"
77
+ readonly lang?: string
78
+ readonly meta?: string
79
+ readonly value: string
80
+ }
81
+
82
+ /**
83
+ * MDAST blockquote node type.
84
+ *
85
+ * @category Types
86
+ */
87
+ export interface MdastBlockquote {
88
+ readonly type: "blockquote"
89
+ readonly children: ReadonlyArray<MdastBlockContent>
90
+ }
91
+
92
+ /**
93
+ * MDAST list node type.
94
+ *
95
+ * @category Types
96
+ */
97
+ export interface MdastList {
98
+ readonly type: "list"
99
+ readonly ordered?: boolean
100
+ readonly start?: number
101
+ readonly spread?: boolean
102
+ readonly children: ReadonlyArray<MdastListItem>
103
+ }
104
+
105
+ /**
106
+ * MDAST list item node type.
107
+ *
108
+ * @category Types
109
+ */
110
+ export interface MdastListItem {
111
+ readonly type: "listItem"
112
+ readonly checked?: boolean | null
113
+ readonly spread?: boolean
114
+ readonly children: ReadonlyArray<MdastBlockContent>
115
+ }
116
+
117
+ /**
118
+ * MDAST table node type.
119
+ *
120
+ * @category Types
121
+ */
122
+ export interface MdastTable {
123
+ readonly type: "table"
124
+ readonly align?: ReadonlyArray<"left" | "right" | "center" | null>
125
+ readonly children: ReadonlyArray<MdastTableRow>
126
+ }
127
+
128
+ /**
129
+ * MDAST table row node type.
130
+ *
131
+ * @category Types
132
+ */
133
+ export interface MdastTableRow {
134
+ readonly type: "tableRow"
135
+ readonly children: ReadonlyArray<MdastTableCell>
136
+ }
137
+
138
+ /**
139
+ * MDAST table cell node type.
140
+ *
141
+ * @category Types
142
+ */
143
+ export interface MdastTableCell {
144
+ readonly type: "tableCell"
145
+ readonly children: ReadonlyArray<MdastPhrasingContent>
146
+ }
147
+
148
+ /**
149
+ * MDAST link node type.
150
+ *
151
+ * @category Types
152
+ */
153
+ export interface MdastLink {
154
+ readonly type: "link"
155
+ readonly url: string
156
+ readonly title?: string | null
157
+ readonly children: ReadonlyArray<MdastPhrasingContent>
158
+ }
159
+
160
+ /**
161
+ * MDAST image node type.
162
+ *
163
+ * @category Types
164
+ */
165
+ export interface MdastImage {
166
+ readonly type: "image"
167
+ readonly url: string
168
+ readonly title?: string | null
169
+ readonly alt?: string | null
170
+ }
171
+
172
+ /**
173
+ * MDAST strong (bold) node type.
174
+ *
175
+ * @category Types
176
+ */
177
+ export interface MdastStrong {
178
+ readonly type: "strong"
179
+ readonly children: ReadonlyArray<MdastPhrasingContent>
180
+ }
181
+
182
+ /**
183
+ * MDAST emphasis (italic) node type.
184
+ *
185
+ * @category Types
186
+ */
187
+ export interface MdastEmphasis {
188
+ readonly type: "emphasis"
189
+ readonly children: ReadonlyArray<MdastPhrasingContent>
190
+ }
191
+
192
+ /**
193
+ * MDAST delete (strikethrough) node type.
194
+ *
195
+ * @category Types
196
+ */
197
+ export interface MdastDelete {
198
+ readonly type: "delete"
199
+ readonly children: ReadonlyArray<MdastPhrasingContent>
200
+ }
201
+
202
+ /**
203
+ * MDAST HTML node type (inline or block HTML).
204
+ *
205
+ * @category Types
206
+ */
207
+ export interface MdastHtml {
208
+ readonly type: "html"
209
+ readonly value: string
210
+ }
211
+
212
+ /**
213
+ * Union of all MDAST phrasing (inline) content types.
214
+ *
215
+ * @category Types
216
+ */
217
+ export type MdastPhrasingContent =
218
+ | MdastText
219
+ | MdastInlineCode
220
+ | MdastBreak
221
+ | MdastLink
222
+ | MdastImage
223
+ | MdastStrong
224
+ | MdastEmphasis
225
+ | MdastDelete
226
+ | MdastHtml
227
+
228
+ /**
229
+ * Union of all MDAST block content types.
230
+ *
231
+ * @category Types
232
+ */
233
+ export type MdastBlockContent =
234
+ | MdastHeading
235
+ | MdastParagraph
236
+ | MdastCode
237
+ | MdastBlockquote
238
+ | MdastList
239
+ | MdastTable
240
+ | MdastThematicBreak
241
+ | MdastHtml
242
+
243
+ /**
244
+ * Union of all MDAST node types.
245
+ *
246
+ * @category Types
247
+ */
248
+ export type MdastNode =
249
+ | MdastPhrasingContent
250
+ | MdastBlockContent
251
+ | MdastListItem
252
+ | MdastTableRow
253
+ | MdastTableCell
254
+
255
+ /**
256
+ * MDAST root node type.
257
+ *
258
+ * @category Types
259
+ */
260
+ export interface MdastRoot {
261
+ readonly type: "root"
262
+ readonly children: ReadonlyArray<MdastBlockContent>
263
+ }
264
+
265
+ // Constructors
266
+
267
+ /**
268
+ * Create a MDAST text node.
269
+ *
270
+ * @category Constructors
271
+ */
272
+ export const makeMdastText = (value: string): MdastText => ({
273
+ type: "text",
274
+ value
275
+ })
276
+
277
+ /**
278
+ * Create a MDAST inline code node.
279
+ *
280
+ * @category Constructors
281
+ */
282
+ export const makeMdastInlineCode = (value: string): MdastInlineCode => ({
283
+ type: "inlineCode",
284
+ value
285
+ })
286
+
287
+ /**
288
+ * Create a MDAST break node.
289
+ *
290
+ * @category Constructors
291
+ */
292
+ export const makeMdastBreak = (): MdastBreak => ({
293
+ type: "break"
294
+ })
295
+
296
+ /**
297
+ * Create a MDAST heading node.
298
+ *
299
+ * @category Constructors
300
+ */
301
+ export const makeMdastHeading = (
302
+ depth: 1 | 2 | 3 | 4 | 5 | 6,
303
+ children: ReadonlyArray<MdastPhrasingContent>
304
+ ): MdastHeading => ({
305
+ type: "heading",
306
+ depth,
307
+ children
308
+ })
309
+
310
+ /**
311
+ * Create a MDAST paragraph node.
312
+ *
313
+ * @category Constructors
314
+ */
315
+ export const makeMdastParagraph = (children: ReadonlyArray<MdastPhrasingContent>): MdastParagraph => ({
316
+ type: "paragraph",
317
+ children
318
+ })
319
+
320
+ /**
321
+ * Create a MDAST code block node.
322
+ *
323
+ * @category Constructors
324
+ */
325
+ export const makeMdastCode = (value: string, lang?: string): MdastCode => ({
326
+ type: "code",
327
+ value,
328
+ ...(lang !== undefined ? { lang } : {})
329
+ })
330
+
331
+ /**
332
+ * Create a MDAST link node.
333
+ *
334
+ * @category Constructors
335
+ */
336
+ export const makeMdastLink = (
337
+ url: string,
338
+ children: ReadonlyArray<MdastPhrasingContent>,
339
+ title?: string
340
+ ): MdastLink => ({
341
+ type: "link",
342
+ url,
343
+ children,
344
+ ...(title !== undefined ? { title } : {})
345
+ })
346
+
347
+ /**
348
+ * Create a MDAST strong node.
349
+ *
350
+ * @category Constructors
351
+ */
352
+ export const makeMdastStrong = (children: ReadonlyArray<MdastPhrasingContent>): MdastStrong => ({
353
+ type: "strong",
354
+ children
355
+ })
356
+
357
+ /**
358
+ * Create a MDAST emphasis node.
359
+ *
360
+ * @category Constructors
361
+ */
362
+ export const makeMdastEmphasis = (children: ReadonlyArray<MdastPhrasingContent>): MdastEmphasis => ({
363
+ type: "emphasis",
364
+ children
365
+ })
366
+
367
+ /**
368
+ * Create a MDAST root node.
369
+ *
370
+ * @category Constructors
371
+ */
372
+ export const makeMdastRoot = (children: ReadonlyArray<MdastBlockContent>): MdastRoot => ({
373
+ type: "root",
374
+ children
375
+ })
376
+
377
+ // Type guards
378
+
379
+ /**
380
+ * Type guard for MDAST text node.
381
+ *
382
+ * @category Guards
383
+ */
384
+ export const isMdastText = (node: MdastNode): node is MdastText => node.type === "text"
385
+
386
+ /**
387
+ * Type guard for MDAST heading node.
388
+ *
389
+ * @category Guards
390
+ */
391
+ export const isMdastHeading = (node: MdastNode): node is MdastHeading => node.type === "heading"
392
+
393
+ /**
394
+ * Type guard for MDAST paragraph node.
395
+ *
396
+ * @category Guards
397
+ */
398
+ export const isMdastParagraph = (node: MdastNode): node is MdastParagraph => node.type === "paragraph"
399
+
400
+ /**
401
+ * Type guard for MDAST code node.
402
+ *
403
+ * @category Guards
404
+ */
405
+ export const isMdastCode = (node: MdastNode): node is MdastCode => node.type === "code"
406
+
407
+ /**
408
+ * Type guard for MDAST link node.
409
+ *
410
+ * @category Guards
411
+ */
412
+ export const isMdastLink = (node: MdastNode): node is MdastLink => node.type === "link"
413
+
414
+ // Schemas for validation
415
+
416
+ /**
417
+ * Schema for MDAST text node.
418
+ *
419
+ * @category Schemas
420
+ */
421
+ export const MdastTextSchema: Schema.Schema<MdastText> = Schema.Struct({
422
+ type: Schema.Literal("text"),
423
+ value: Schema.String
424
+ })
425
+
426
+ /**
427
+ * Schema for MDAST inline code node.
428
+ *
429
+ * @category Schemas
430
+ */
431
+ export const MdastInlineCodeSchema: Schema.Schema<MdastInlineCode> = Schema.Struct({
432
+ type: Schema.Literal("inlineCode"),
433
+ value: Schema.String
434
+ })
435
+
436
+ /**
437
+ * Schema for MDAST break node.
438
+ *
439
+ * @category Schemas
440
+ */
441
+ export const MdastBreakSchema: Schema.Schema<MdastBreak> = Schema.Struct({
442
+ type: Schema.Literal("break")
443
+ })
444
+
445
+ /**
446
+ * Schema for MDAST thematic break node.
447
+ *
448
+ * @category Schemas
449
+ */
450
+ export const MdastThematicBreakSchema: Schema.Schema<MdastThematicBreak> = Schema.Struct({
451
+ type: Schema.Literal("thematicBreak")
452
+ })
453
+
454
+ /**
455
+ * Schema for MDAST code block node.
456
+ *
457
+ * @category Schemas
458
+ */
459
+ export const MdastCodeSchema = Schema.Struct({
460
+ type: Schema.Literal("code"),
461
+ lang: Schema.optional(Schema.String),
462
+ meta: Schema.optional(Schema.String),
463
+ value: Schema.String
464
+ })
465
+
466
+ /**
467
+ * Schema for MDAST image node.
468
+ *
469
+ * @category Schemas
470
+ */
471
+ export const MdastImageSchema = Schema.Struct({
472
+ type: Schema.Literal("image"),
473
+ url: Schema.String,
474
+ title: Schema.optional(Schema.NullOr(Schema.String)),
475
+ alt: Schema.optional(Schema.NullOr(Schema.String))
476
+ })
477
+
478
+ /**
479
+ * Schema for MDAST HTML node.
480
+ *
481
+ * @category Schemas
482
+ */
483
+ export const MdastHtmlSchema: Schema.Schema<MdastHtml> = Schema.Struct({
484
+ type: Schema.Literal("html"),
485
+ value: Schema.String
486
+ })
487
+
488
+ // Note: Full recursive schemas for heading, paragraph, list, table etc.
489
+ // are complex due to recursive nature. For now we use simpler type-based approach
490
+ // and add full schemas as needed during implementation.
491
+
492
+ /**
493
+ * Valid MDAST block content types.
494
+ */
495
+ const MdastBlockTypes = [
496
+ "heading",
497
+ "paragraph",
498
+ "code",
499
+ "blockquote",
500
+ "list",
501
+ "table",
502
+ "thematicBreak",
503
+ "html"
504
+ ] as const
505
+
506
+ /**
507
+ * Type guard for MDAST block content.
508
+ *
509
+ * @category Guards
510
+ */
511
+ export const isMdastBlockContent = (node: unknown): node is MdastBlockContent =>
512
+ typeof node === "object" &&
513
+ node !== null &&
514
+ "type" in node &&
515
+ typeof (node as { type: unknown }).type === "string" &&
516
+ (MdastBlockTypes as ReadonlyArray<string>).includes((node as { type: string }).type)
517
+
518
+ /**
519
+ * Type guard for MDAST root.
520
+ *
521
+ * @category Guards
522
+ */
523
+ export const isMdastRoot = (value: unknown): value is MdastRoot =>
524
+ typeof value === "object" &&
525
+ value !== null &&
526
+ "type" in value &&
527
+ (value as { type: unknown }).type === "root" &&
528
+ "children" in value &&
529
+ Array.isArray((value as { children: unknown }).children) &&
530
+ (value as { children: Array<unknown> }).children.every(isMdastBlockContent)
531
+
532
+ /**
533
+ * Base schema for MDAST root structure.
534
+ */
535
+ const MdastRootBaseSchema = Schema.Struct({
536
+ type: Schema.Literal("root"),
537
+ children: Schema.Array(Schema.Unknown)
538
+ })
539
+
540
+ /**
541
+ * Schema for MDAST root with runtime validation.
542
+ *
543
+ * Validates that the structure conforms to MdastRoot type.
544
+ * Uses a type guard to ensure children are valid block content.
545
+ *
546
+ * @category Schemas
547
+ */
548
+ export const MdastRootSchema: Schema.Schema<
549
+ MdastRoot,
550
+ { type: "root"; children: ReadonlyArray<unknown> }
551
+ > = Schema.transform(
552
+ MdastRootBaseSchema,
553
+ Schema.typeSchema(Schema.Any as Schema.Schema<MdastRoot>),
554
+ {
555
+ strict: true,
556
+ decode: (base) => {
557
+ // Validate children at runtime
558
+ if (!base.children.every(isMdastBlockContent)) {
559
+ // Return with best-effort cast - remark-parse output is trusted
560
+ return { type: "root" as const, children: base.children as ReadonlyArray<MdastBlockContent> }
561
+ }
562
+ return { type: "root" as const, children: base.children as ReadonlyArray<MdastBlockContent> }
563
+ },
564
+ encode: (root) => ({ type: "root" as const, children: root.children as ReadonlyArray<unknown> })
565
+ }
566
+ )
@@ -0,0 +1,59 @@
1
+ /**
2
+ * MDAST (Markdown Abstract Syntax Tree) schemas.
3
+ *
4
+ * @module
5
+ */
6
+ export type {
7
+ MdastBlockContent,
8
+ MdastBlockquote,
9
+ MdastBreak,
10
+ MdastCode,
11
+ MdastDelete,
12
+ MdastEmphasis,
13
+ MdastHeading,
14
+ MdastHtml,
15
+ MdastImage,
16
+ MdastInlineCode,
17
+ MdastLink,
18
+ MdastList,
19
+ MdastListItem,
20
+ MdastNode,
21
+ MdastParagraph,
22
+ MdastPhrasingContent,
23
+ MdastRoot,
24
+ MdastStrong,
25
+ MdastTable,
26
+ MdastTableCell,
27
+ MdastTableRow,
28
+ MdastText,
29
+ MdastThematicBreak
30
+ } from "./MdastSchema.js"
31
+
32
+ export {
33
+ isMdastCode,
34
+ isMdastHeading,
35
+ isMdastLink,
36
+ isMdastParagraph,
37
+ isMdastText,
38
+ makeMdastBreak,
39
+ makeMdastCode,
40
+ makeMdastEmphasis,
41
+ makeMdastHeading,
42
+ makeMdastInlineCode,
43
+ makeMdastLink,
44
+ makeMdastParagraph,
45
+ makeMdastRoot,
46
+ makeMdastStrong,
47
+ makeMdastText,
48
+ MdastBreakSchema,
49
+ MdastCodeSchema,
50
+ MdastHtmlSchema,
51
+ MdastImageSchema,
52
+ MdastInlineCodeSchema,
53
+ MdastRootSchema,
54
+ MdastTextSchema,
55
+ MdastThematicBreakSchema
56
+ } from "./MdastSchema.js"
57
+
58
+ export { MdastFromMarkdown } from "./MdastFromMarkdown.js"
59
+ export { mdastToString } from "./mdastToString.js"
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Utility for converting MDAST nodes to Markdown strings.
3
+ *
4
+ * @module
5
+ */
6
+ import type {
7
+ MdastBlockContent,
8
+ MdastList,
9
+ MdastListItem,
10
+ MdastPhrasingContent,
11
+ MdastTable,
12
+ MdastTableCell,
13
+ MdastTableRow
14
+ } from "./MdastSchema.js"
15
+
16
+ const exhaustive = (_: never): never => {
17
+ throw new Error("Exhaustive check failed")
18
+ }
19
+
20
+ /**
21
+ * Convert MDAST table to Markdown string.
22
+ */
23
+ const tableToString = (table: MdastTable): string => {
24
+ if (!table.children.length) return ""
25
+ const headerRow = table.children[0] as MdastTableRow
26
+ if (!headerRow) return ""
27
+ const headerCells = headerRow.children as ReadonlyArray<MdastTableCell>
28
+ const header = "| " + headerCells.map((cell) => cell.children.map(phrasingToString).join("")).join(" | ") + " |"
29
+ const separator = "| " + headerCells.map(() => "---").join(" | ") + " |"
30
+ const rows = table.children.slice(1).map((row) => {
31
+ const cells = (row as MdastTableRow).children as ReadonlyArray<MdastTableCell>
32
+ return "| " + cells.map((cell) => cell.children.map(phrasingToString).join("")).join(" | ") + " |"
33
+ })
34
+ return [header, separator, ...rows].join("\n")
35
+ }
36
+
37
+ /**
38
+ * Convert MDAST list to Markdown string.
39
+ */
40
+ const listToString = (list: MdastList): string =>
41
+ list.children.map((item, i) => {
42
+ const prefix = list.ordered ? `${(list.start ?? 1) + i}. ` : "- "
43
+ const content = (item as MdastListItem).children
44
+ .map((c) => mdastToString(c as MdastBlockContent)).join("\n")
45
+ return prefix + content
46
+ }).join("\n")
47
+
48
+ /**
49
+ * Convert MDAST phrasing content to Markdown string.
50
+ */
51
+ const phrasingToString = (c: MdastPhrasingContent): string => {
52
+ switch (c.type) {
53
+ case "text":
54
+ return c.value
55
+ case "inlineCode":
56
+ return `\`${c.value}\``
57
+ case "strong":
58
+ return `**${c.children.map(phrasingToString).join("")}**`
59
+ case "emphasis":
60
+ return `_${c.children.map(phrasingToString).join("")}_`
61
+ case "link":
62
+ return `[${c.children.map(phrasingToString).join("")}](${c.url})`
63
+ case "delete":
64
+ return `~~${c.children.map(phrasingToString).join("")}~~`
65
+ case "break":
66
+ return " \n"
67
+ case "image":
68
+ return c.alt ?? ""
69
+ case "html":
70
+ return c.value
71
+ default:
72
+ return exhaustive(c)
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Convert MDAST block content to Markdown string.
78
+ *
79
+ * @category Utilities
80
+ */
81
+ export const mdastToString = (node: MdastBlockContent): string => {
82
+ switch (node.type) {
83
+ case "paragraph":
84
+ return node.children.map(phrasingToString).join("")
85
+ case "heading":
86
+ return "#".repeat(node.depth) + " " + node.children.map(phrasingToString).join("")
87
+ case "code":
88
+ return "```" + (node.lang ?? "") + "\n" + node.value + "\n```"
89
+ case "thematicBreak":
90
+ return "---"
91
+ case "html":
92
+ return node.value
93
+ case "blockquote":
94
+ return node.children.map((c) => "> " + mdastToString(c as MdastBlockContent)).join("\n")
95
+ case "list":
96
+ return listToString(node)
97
+ case "table":
98
+ return tableToString(node)
99
+ default:
100
+ return exhaustive(node)
101
+ }
102
+ }