@driftsys/markspec 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (331) hide show
  1. package/esm/ast/build.d.ts +70 -0
  2. package/esm/ast/build.d.ts.map +1 -0
  3. package/esm/ast/build.js +605 -0
  4. package/esm/ast/equivalence.d.ts +18 -0
  5. package/esm/ast/equivalence.d.ts.map +1 -0
  6. package/esm/ast/equivalence.js +56 -0
  7. package/esm/ast/nodes.d.ts +221 -0
  8. package/esm/ast/nodes.d.ts.map +1 -0
  9. package/esm/ast/nodes.js +12 -0
  10. package/esm/ast/normalize.d.ts +67 -0
  11. package/esm/ast/normalize.d.ts.map +1 -0
  12. package/esm/ast/normalize.js +255 -0
  13. package/esm/ast/render.d.ts +34 -0
  14. package/esm/ast/render.d.ts.map +1 -0
  15. package/esm/ast/render.js +215 -0
  16. package/esm/compiler/inverses.d.ts +2 -8
  17. package/esm/compiler/inverses.d.ts.map +1 -1
  18. package/esm/compiler/inverses.js +50 -14
  19. package/esm/compiler/manifest.d.ts +59 -0
  20. package/esm/compiler/manifest.d.ts.map +1 -0
  21. package/esm/compiler/manifest.js +48 -0
  22. package/esm/compiler/mod.d.ts +9 -1
  23. package/esm/compiler/mod.d.ts.map +1 -1
  24. package/esm/compiler/mod.js +21 -2
  25. package/esm/compiler/ndjson_writer.d.ts +50 -0
  26. package/esm/compiler/ndjson_writer.d.ts.map +1 -0
  27. package/esm/compiler/ndjson_writer.js +73 -0
  28. package/esm/compiler/schema.d.ts +18 -1
  29. package/esm/compiler/schema.d.ts.map +1 -1
  30. package/esm/compiler/schema.js +18 -9
  31. package/esm/config/mod.d.ts.map +1 -1
  32. package/esm/config/mod.js +54 -0
  33. package/esm/formatter/mod.d.ts +56 -6
  34. package/esm/formatter/mod.d.ts.map +1 -1
  35. package/esm/formatter/mod.js +372 -41
  36. package/esm/formatter/synth_ulid.d.ts +21 -0
  37. package/esm/formatter/synth_ulid.d.ts.map +1 -0
  38. package/esm/formatter/synth_ulid.js +64 -0
  39. package/esm/lint/mod.d.ts +10 -0
  40. package/esm/lint/mod.d.ts.map +1 -0
  41. package/esm/lint/mod.js +7 -0
  42. package/esm/lint/rules/lexicon.d.ts +24 -0
  43. package/esm/lint/rules/lexicon.d.ts.map +1 -0
  44. package/esm/lint/rules/lexicon.js +236 -0
  45. package/esm/lint/rules/struct.d.ts +17 -0
  46. package/esm/lint/rules/struct.d.ts.map +1 -0
  47. package/esm/lint/rules/struct.js +55 -0
  48. package/esm/lint/rules/suppression.d.ts +19 -0
  49. package/esm/lint/rules/suppression.d.ts.map +1 -0
  50. package/esm/lint/rules/suppression.js +75 -0
  51. package/esm/lint/runner.d.ts +39 -0
  52. package/esm/lint/runner.d.ts.map +1 -0
  53. package/esm/lint/runner.js +112 -0
  54. package/esm/lint/types.d.ts +19 -0
  55. package/esm/lint/types.d.ts.map +1 -0
  56. package/esm/lint/types.js +9 -0
  57. package/esm/mod.d.ts +21 -8
  58. package/esm/mod.d.ts.map +1 -1
  59. package/esm/mod.js +16 -5
  60. package/esm/model/attributes.d.ts.map +1 -1
  61. package/esm/model/attributes.js +163 -2
  62. package/esm/model/discriminating_attr.d.ts +33 -0
  63. package/esm/model/discriminating_attr.d.ts.map +1 -0
  64. package/esm/model/discriminating_attr.js +74 -0
  65. package/esm/model/mod.d.ts +100 -3
  66. package/esm/model/mod.d.ts.map +1 -1
  67. package/esm/model/mod.js +58 -2
  68. package/esm/model/palette.d.ts +18 -0
  69. package/esm/model/palette.d.ts.map +1 -0
  70. package/esm/model/palette.js +23 -0
  71. package/esm/model/profile.d.ts +33 -27
  72. package/esm/model/profile.d.ts.map +1 -1
  73. package/esm/model/source_introspection.d.ts +26 -0
  74. package/esm/model/source_introspection.d.ts.map +1 -0
  75. package/esm/model/source_introspection.js +77 -0
  76. package/esm/model/type_hierarchy.d.ts +51 -0
  77. package/esm/model/type_hierarchy.d.ts.map +1 -0
  78. package/esm/model/type_hierarchy.js +126 -0
  79. package/esm/model/uri_scheme_map.d.ts +21 -0
  80. package/esm/model/uri_scheme_map.d.ts.map +1 -0
  81. package/esm/model/uri_scheme_map.js +66 -0
  82. package/esm/parser/attributes.d.ts.map +1 -1
  83. package/esm/parser/attributes.js +9 -6
  84. package/esm/parser/entity_refs.d.ts +53 -0
  85. package/esm/parser/entity_refs.d.ts.map +1 -0
  86. package/esm/parser/entity_refs.js +151 -0
  87. package/esm/parser/glossary.d.ts +43 -0
  88. package/esm/parser/glossary.d.ts.map +1 -0
  89. package/esm/parser/glossary.js +217 -0
  90. package/esm/parser/markdown.d.ts +10 -3
  91. package/esm/parser/markdown.d.ts.map +1 -1
  92. package/esm/parser/markdown.js +241 -11
  93. package/esm/parser/mod.d.ts +1 -0
  94. package/esm/parser/mod.d.ts.map +1 -1
  95. package/esm/parser/mod.js +4 -3
  96. package/esm/parser/source.d.ts +20 -0
  97. package/esm/parser/source.d.ts.map +1 -1
  98. package/esm/parser/source.js +4 -4
  99. package/esm/profile/chain.js +3 -13
  100. package/esm/profile/colors.d.ts +26 -0
  101. package/esm/profile/colors.d.ts.map +1 -0
  102. package/esm/profile/colors.js +46 -0
  103. package/esm/profile/introspect.d.ts +135 -0
  104. package/esm/profile/introspect.d.ts.map +1 -0
  105. package/esm/profile/introspect.js +378 -0
  106. package/esm/profile/load.d.ts.map +1 -1
  107. package/esm/profile/load.js +67 -0
  108. package/esm/profile/manifest.d.ts.map +1 -1
  109. package/esm/profile/manifest.js +278 -104
  110. package/esm/profile/merge.js +139 -39
  111. package/esm/profile/mod.d.ts +3 -4
  112. package/esm/profile/mod.d.ts.map +1 -1
  113. package/esm/profile/mod.js +6 -2
  114. package/esm/reporter/mod.js +4 -4
  115. package/esm/util/fence.d.ts +30 -0
  116. package/esm/util/fence.d.ts.map +1 -0
  117. package/esm/util/fence.js +40 -0
  118. package/esm/validator/attributes.d.ts +3 -3
  119. package/esm/validator/attributes.d.ts.map +1 -1
  120. package/esm/validator/attributes.js +1 -18
  121. package/esm/validator/body_blocks.d.ts +38 -0
  122. package/esm/validator/body_blocks.d.ts.map +1 -0
  123. package/esm/validator/body_blocks.js +218 -0
  124. package/esm/validator/caption_convention.d.ts +29 -0
  125. package/esm/validator/caption_convention.d.ts.map +1 -0
  126. package/esm/validator/caption_convention.js +58 -0
  127. package/esm/validator/captions.d.ts +22 -0
  128. package/esm/validator/captions.d.ts.map +1 -0
  129. package/esm/validator/captions.js +137 -0
  130. package/esm/validator/component_schemes.d.ts +73 -0
  131. package/esm/validator/component_schemes.d.ts.map +1 -0
  132. package/esm/validator/component_schemes.js +375 -0
  133. package/esm/validator/feature_ac.d.ts +28 -0
  134. package/esm/validator/feature_ac.d.ts.map +1 -0
  135. package/esm/validator/feature_ac.js +102 -0
  136. package/esm/validator/listing.d.ts +42 -0
  137. package/esm/validator/listing.d.ts.map +1 -0
  138. package/esm/validator/listing.js +295 -0
  139. package/esm/validator/mod.d.ts +2 -0
  140. package/esm/validator/mod.d.ts.map +1 -1
  141. package/esm/validator/mod.js +253 -12
  142. package/esm/validator/modal_keywords.d.ts +23 -0
  143. package/esm/validator/modal_keywords.d.ts.map +1 -0
  144. package/esm/validator/modal_keywords.js +137 -0
  145. package/esm/validator/per_type_attrs.d.ts +29 -0
  146. package/esm/validator/per_type_attrs.d.ts.map +1 -0
  147. package/esm/validator/per_type_attrs.js +75 -0
  148. package/esm/validator/pipeline.d.ts +7 -2
  149. package/esm/validator/pipeline.d.ts.map +1 -1
  150. package/esm/validator/pipeline.js +40 -7
  151. package/esm/validator/trace_types.d.ts +26 -0
  152. package/esm/validator/trace_types.d.ts.map +1 -0
  153. package/esm/validator/trace_types.js +232 -0
  154. package/esm/validator/traceability.d.ts +3 -4
  155. package/esm/validator/traceability.d.ts.map +1 -1
  156. package/esm/validator/traceability.js +5 -10
  157. package/esm/validator/type_resolution.d.ts +67 -0
  158. package/esm/validator/type_resolution.d.ts.map +1 -0
  159. package/esm/validator/type_resolution.js +140 -0
  160. package/esm/validator/types.d.ts +45 -0
  161. package/esm/validator/types.d.ts.map +1 -1
  162. package/esm/validator/types.js +128 -16
  163. package/esm/validator/value_types.d.ts +8 -0
  164. package/esm/validator/value_types.d.ts.map +1 -1
  165. package/esm/validator/value_types.js +8 -1
  166. package/package.json +1 -1
  167. package/script/ast/build.d.ts +70 -0
  168. package/script/ast/build.d.ts.map +1 -0
  169. package/script/ast/build.js +610 -0
  170. package/script/ast/equivalence.d.ts +18 -0
  171. package/script/ast/equivalence.d.ts.map +1 -0
  172. package/script/ast/equivalence.js +59 -0
  173. package/script/ast/nodes.d.ts +221 -0
  174. package/script/ast/nodes.d.ts.map +1 -0
  175. package/script/ast/nodes.js +13 -0
  176. package/script/ast/normalize.d.ts +67 -0
  177. package/script/ast/normalize.d.ts.map +1 -0
  178. package/script/ast/normalize.js +258 -0
  179. package/script/ast/render.d.ts +34 -0
  180. package/script/ast/render.d.ts.map +1 -0
  181. package/script/ast/render.js +218 -0
  182. package/script/compiler/inverses.d.ts +2 -8
  183. package/script/compiler/inverses.d.ts.map +1 -1
  184. package/script/compiler/inverses.js +50 -14
  185. package/script/compiler/manifest.d.ts +59 -0
  186. package/script/compiler/manifest.d.ts.map +1 -0
  187. package/script/compiler/manifest.js +51 -0
  188. package/script/compiler/mod.d.ts +9 -1
  189. package/script/compiler/mod.d.ts.map +1 -1
  190. package/script/compiler/mod.js +21 -2
  191. package/script/compiler/ndjson_writer.d.ts +50 -0
  192. package/script/compiler/ndjson_writer.d.ts.map +1 -0
  193. package/script/compiler/ndjson_writer.js +78 -0
  194. package/script/compiler/schema.d.ts +18 -1
  195. package/script/compiler/schema.d.ts.map +1 -1
  196. package/script/compiler/schema.js +18 -8
  197. package/script/config/mod.d.ts.map +1 -1
  198. package/script/config/mod.js +54 -0
  199. package/script/formatter/mod.d.ts +56 -6
  200. package/script/formatter/mod.d.ts.map +1 -1
  201. package/script/formatter/mod.js +375 -41
  202. package/script/formatter/synth_ulid.d.ts +21 -0
  203. package/script/formatter/synth_ulid.d.ts.map +1 -0
  204. package/script/formatter/synth_ulid.js +67 -0
  205. package/script/lint/mod.d.ts +10 -0
  206. package/script/lint/mod.d.ts.map +1 -0
  207. package/script/lint/mod.js +12 -0
  208. package/script/lint/rules/lexicon.d.ts +24 -0
  209. package/script/lint/rules/lexicon.d.ts.map +1 -0
  210. package/script/lint/rules/lexicon.js +240 -0
  211. package/script/lint/rules/struct.d.ts +17 -0
  212. package/script/lint/rules/struct.d.ts.map +1 -0
  213. package/script/lint/rules/struct.js +59 -0
  214. package/script/lint/rules/suppression.d.ts +19 -0
  215. package/script/lint/rules/suppression.d.ts.map +1 -0
  216. package/script/lint/rules/suppression.js +80 -0
  217. package/script/lint/runner.d.ts +39 -0
  218. package/script/lint/runner.d.ts.map +1 -0
  219. package/script/lint/runner.js +116 -0
  220. package/script/lint/types.d.ts +19 -0
  221. package/script/lint/types.d.ts.map +1 -0
  222. package/script/lint/types.js +10 -0
  223. package/script/mod.d.ts +21 -8
  224. package/script/mod.d.ts.map +1 -1
  225. package/script/mod.js +58 -32
  226. package/script/model/attributes.d.ts.map +1 -1
  227. package/script/model/attributes.js +163 -2
  228. package/script/model/discriminating_attr.d.ts +33 -0
  229. package/script/model/discriminating_attr.d.ts.map +1 -0
  230. package/script/model/discriminating_attr.js +77 -0
  231. package/script/model/mod.d.ts +100 -3
  232. package/script/model/mod.d.ts.map +1 -1
  233. package/script/model/mod.js +67 -3
  234. package/script/model/palette.d.ts +18 -0
  235. package/script/model/palette.d.ts.map +1 -0
  236. package/script/model/palette.js +26 -0
  237. package/script/model/profile.d.ts +33 -27
  238. package/script/model/profile.d.ts.map +1 -1
  239. package/script/model/source_introspection.d.ts +26 -0
  240. package/script/model/source_introspection.d.ts.map +1 -0
  241. package/script/model/source_introspection.js +80 -0
  242. package/script/model/type_hierarchy.d.ts +51 -0
  243. package/script/model/type_hierarchy.d.ts.map +1 -0
  244. package/script/model/type_hierarchy.js +130 -0
  245. package/script/model/uri_scheme_map.d.ts +21 -0
  246. package/script/model/uri_scheme_map.d.ts.map +1 -0
  247. package/script/model/uri_scheme_map.js +69 -0
  248. package/script/parser/attributes.d.ts.map +1 -1
  249. package/script/parser/attributes.js +9 -6
  250. package/script/parser/entity_refs.d.ts +53 -0
  251. package/script/parser/entity_refs.d.ts.map +1 -0
  252. package/script/parser/entity_refs.js +155 -0
  253. package/script/parser/glossary.d.ts +43 -0
  254. package/script/parser/glossary.d.ts.map +1 -0
  255. package/script/parser/glossary.js +221 -0
  256. package/script/parser/markdown.d.ts +10 -3
  257. package/script/parser/markdown.d.ts.map +1 -1
  258. package/script/parser/markdown.js +240 -10
  259. package/script/parser/mod.d.ts +1 -0
  260. package/script/parser/mod.d.ts.map +1 -1
  261. package/script/parser/mod.js +8 -4
  262. package/script/parser/source.d.ts +20 -0
  263. package/script/parser/source.d.ts.map +1 -1
  264. package/script/parser/source.js +4 -1
  265. package/script/profile/chain.js +3 -13
  266. package/script/profile/colors.d.ts +26 -0
  267. package/script/profile/colors.d.ts.map +1 -0
  268. package/script/profile/colors.js +49 -0
  269. package/script/profile/introspect.d.ts +135 -0
  270. package/script/profile/introspect.d.ts.map +1 -0
  271. package/script/profile/introspect.js +381 -0
  272. package/script/profile/load.d.ts.map +1 -1
  273. package/script/profile/load.js +67 -0
  274. package/script/profile/manifest.d.ts.map +1 -1
  275. package/script/profile/manifest.js +280 -106
  276. package/script/profile/merge.js +139 -39
  277. package/script/profile/mod.d.ts +3 -4
  278. package/script/profile/mod.d.ts.map +1 -1
  279. package/script/profile/mod.js +9 -6
  280. package/script/reporter/mod.js +4 -4
  281. package/script/util/fence.d.ts +30 -0
  282. package/script/util/fence.d.ts.map +1 -0
  283. package/script/util/fence.js +44 -0
  284. package/script/validator/attributes.d.ts +3 -3
  285. package/script/validator/attributes.d.ts.map +1 -1
  286. package/script/validator/attributes.js +1 -18
  287. package/script/validator/body_blocks.d.ts +38 -0
  288. package/script/validator/body_blocks.d.ts.map +1 -0
  289. package/script/validator/body_blocks.js +221 -0
  290. package/script/validator/caption_convention.d.ts +29 -0
  291. package/script/validator/caption_convention.d.ts.map +1 -0
  292. package/script/validator/caption_convention.js +61 -0
  293. package/script/validator/captions.d.ts +22 -0
  294. package/script/validator/captions.d.ts.map +1 -0
  295. package/script/validator/captions.js +140 -0
  296. package/script/validator/component_schemes.d.ts +73 -0
  297. package/script/validator/component_schemes.d.ts.map +1 -0
  298. package/script/validator/component_schemes.js +384 -0
  299. package/script/validator/feature_ac.d.ts +28 -0
  300. package/script/validator/feature_ac.d.ts.map +1 -0
  301. package/script/validator/feature_ac.js +105 -0
  302. package/script/validator/listing.d.ts +42 -0
  303. package/script/validator/listing.d.ts.map +1 -0
  304. package/script/validator/listing.js +298 -0
  305. package/script/validator/mod.d.ts +2 -0
  306. package/script/validator/mod.d.ts.map +1 -1
  307. package/script/validator/mod.js +256 -14
  308. package/script/validator/modal_keywords.d.ts +23 -0
  309. package/script/validator/modal_keywords.d.ts.map +1 -0
  310. package/script/validator/modal_keywords.js +140 -0
  311. package/script/validator/per_type_attrs.d.ts +29 -0
  312. package/script/validator/per_type_attrs.d.ts.map +1 -0
  313. package/script/validator/per_type_attrs.js +78 -0
  314. package/script/validator/pipeline.d.ts +7 -2
  315. package/script/validator/pipeline.d.ts.map +1 -1
  316. package/script/validator/pipeline.js +39 -6
  317. package/script/validator/trace_types.d.ts +26 -0
  318. package/script/validator/trace_types.d.ts.map +1 -0
  319. package/script/validator/trace_types.js +235 -0
  320. package/script/validator/traceability.d.ts +3 -4
  321. package/script/validator/traceability.d.ts.map +1 -1
  322. package/script/validator/traceability.js +5 -10
  323. package/script/validator/type_resolution.d.ts +67 -0
  324. package/script/validator/type_resolution.d.ts.map +1 -0
  325. package/script/validator/type_resolution.js +146 -0
  326. package/script/validator/types.d.ts +45 -0
  327. package/script/validator/types.d.ts.map +1 -1
  328. package/script/validator/types.js +131 -16
  329. package/script/validator/value_types.d.ts +8 -0
  330. package/script/validator/value_types.d.ts.map +1 -1
  331. package/script/validator/value_types.js +10 -2
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @module core/ast/build
3
+ *
4
+ * Body-string → BodyBlock[] builder. Parses the entry body string
5
+ * (post-`splitBodyAndAttributes`) with the shared remark processor and
6
+ * maps each mdast block child to the §2.4-2.6 node taxonomy.
7
+ *
8
+ * Inline markers (modal + $Identifier) are extracted for prose-bearing
9
+ * nodes: Paragraph, List items, Table cells, Note bodies, Blockquotes,
10
+ * and DefinitionList term/definitions. They are NOT extracted inside
11
+ * Code, Feature, or Math blocks (spec §2.5).
12
+ *
13
+ * This module is pure library code: no `Deno.*` APIs.
14
+ */
15
+ import type { BodyBlock, InlineMarker, SourceRange } from "./nodes.js";
16
+ /**
17
+ * Extract all inline markers from a prose text string.
18
+ * `lineOffset` is the 0-based line index of the text within the body
19
+ * (used for SourceRange line numbers).
20
+ *
21
+ * For multi-line text the SourceRange carries the first line's 1-based
22
+ * column; this is best-effort for PR 2 (noted as DONE_WITH_CONCERNS:
23
+ * multi-line paragraph ranges are approximated to the starting line).
24
+ *
25
+ * Exported so the AST-native §3.4.1 normalisation pass
26
+ * (`core/ast/normalize.ts`) re-derives `InlineContent.markers` from the
27
+ * normalised text with the SAME extraction the builder uses — no regex
28
+ * duplication.
29
+ */
30
+ export declare function extractMarkersFromText(text: string, startRange: SourceRange): readonly InlineMarker[];
31
+ /**
32
+ * Return the exact source substring for an mdast node `position`, with
33
+ * list-continuation indentation normalised to column 0 so the slice is a
34
+ * self-contained, column-0-anchored string. This is the load-bearing
35
+ * mechanism for §5.1 faithful capture (ADR-014; spec §5.1): remark
36
+ * populates byte `offset` when a string is passed to `.parse()`; a
37
+ * line/column reconstruction is the defensive fallback. Extracted from
38
+ * the original inline `TableNode` logic — behaviour is identical.
39
+ */
40
+ export declare function verbatimSlice(body: string, pos: {
41
+ start: {
42
+ line: number;
43
+ column: number;
44
+ offset?: number;
45
+ };
46
+ end: {
47
+ line: number;
48
+ column: number;
49
+ offset?: number;
50
+ };
51
+ } | undefined): string;
52
+ /**
53
+ * Build the canonical body AST from an entry body string.
54
+ *
55
+ * Re-parses `body` via the shared remark processor (CommonMark+GFM) and
56
+ * maps each block-level mdast node to a `BodyBlock`. SourceRange positions
57
+ * are body-relative (1-based line/column) matching the mdast output directly.
58
+ *
59
+ * DONE_WITH_CONCERNS notes:
60
+ * - DefinitionList: single-item best-effort. `Term\n: def` patterns in
61
+ * multi-item lists are parsed as one DefinitionListNode per paragraph
62
+ * block; the validator would need to coalesce them (deferred).
63
+ * - Caption position: assigned by adjacent-block heuristic (post-pass).
64
+ * `block` (resolved owner) is `undefined` for PR 2 per spec.
65
+ * - Multi-line paragraph marker ranges: SourceRange is approximated to
66
+ * the paragraph start line; intra-paragraph column tracking is correct
67
+ * only for single-line paragraphs.
68
+ */
69
+ export declare function buildBodyAst(body: string): BodyBlock[];
70
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/ast/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,KAAK,EAGV,SAAS,EAQT,YAAY,EAQZ,WAAW,EAGZ,MAAM,YAAY,CAAC;AAmBpB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,WAAW,GACtB,SAAS,YAAY,EAAE,CAyEzB;AAyCD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE;IACH,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACxD,GAAG,SAAS,GACZ,MAAM,CAgCR;AA4cD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,CAUtD"}
@@ -0,0 +1,605 @@
1
+ /**
2
+ * @module core/ast/build
3
+ *
4
+ * Body-string → BodyBlock[] builder. Parses the entry body string
5
+ * (post-`splitBodyAndAttributes`) with the shared remark processor and
6
+ * maps each mdast block child to the §2.4-2.6 node taxonomy.
7
+ *
8
+ * Inline markers (modal + $Identifier) are extracted for prose-bearing
9
+ * nodes: Paragraph, List items, Table cells, Note bodies, Blockquotes,
10
+ * and DefinitionList term/definitions. They are NOT extracted inside
11
+ * Code, Feature, or Math blocks (spec §2.5).
12
+ *
13
+ * This module is pure library code: no `Deno.*` APIs.
14
+ */
15
+ import { processor } from "../parser/remark.js";
16
+ import { classifyConvention } from "../parser/entity_refs.js";
17
+ // ---------------------------------------------------------------------------
18
+ // Inline marker recognition — modal keywords
19
+ // ---------------------------------------------------------------------------
20
+ /**
21
+ * RFC 2119 tokens (lowercase canonical; matched case-insensitively in prose).
22
+ * Multi-word forms listed first so the alternation greedily matches them.
23
+ */
24
+ const RFC2119_RE = /\b(shall not|should not|must not|shall|should|must|may)\b/gi;
25
+ // EARS keywords recognised: When, While, Where, Unless.
26
+ const EARS_RE = /\b(When|While|Where|Unless)\b/g;
27
+ /** `$Identifier` entity reference — must not be preceded by another `$`. */
28
+ const ENTITY_REF_RE = /\$([A-Za-z][A-Za-z0-9_]*)/g;
29
+ /**
30
+ * Extract all inline markers from a prose text string.
31
+ * `lineOffset` is the 0-based line index of the text within the body
32
+ * (used for SourceRange line numbers).
33
+ *
34
+ * For multi-line text the SourceRange carries the first line's 1-based
35
+ * column; this is best-effort for PR 2 (noted as DONE_WITH_CONCERNS:
36
+ * multi-line paragraph ranges are approximated to the starting line).
37
+ *
38
+ * Exported so the AST-native §3.4.1 normalisation pass
39
+ * (`core/ast/normalize.ts`) re-derives `InlineContent.markers` from the
40
+ * normalised text with the SAME extraction the builder uses — no regex
41
+ * duplication.
42
+ */
43
+ export function extractMarkersFromText(text, startRange) {
44
+ const markers = [];
45
+ const lines = text.split("\n");
46
+ for (let li = 0; li < lines.length; li++) {
47
+ const line = lines[li];
48
+ const lineNo = startRange.start.line + li;
49
+ // ---- RFC 2119 ---------------------------------------------------
50
+ RFC2119_RE.lastIndex = 0;
51
+ let m;
52
+ while ((m = RFC2119_RE.exec(line)) !== null) {
53
+ const raw = m[1];
54
+ const canonical = raw.toLowerCase();
55
+ const col = m.index + 1;
56
+ markers.push({
57
+ kind: "modal",
58
+ cls: "rfc2119",
59
+ canonical,
60
+ raw, // preserve source form for uppercase-keyword detection (MSL-M060)
61
+ range: {
62
+ start: { line: lineNo, column: col },
63
+ end: { line: lineNo, column: col + raw.length },
64
+ },
65
+ });
66
+ }
67
+ // ---- EARS -------------------------------------------------------
68
+ EARS_RE.lastIndex = 0;
69
+ while ((m = EARS_RE.exec(line)) !== null) {
70
+ const raw = m[1];
71
+ const col = m.index + 1;
72
+ markers.push({
73
+ kind: "modal",
74
+ cls: "ears",
75
+ canonical: raw, // EARS: source form is canonical
76
+ raw, // same as canonical for EARS
77
+ range: {
78
+ start: { line: lineNo, column: col },
79
+ end: { line: lineNo, column: col + raw.length },
80
+ },
81
+ });
82
+ }
83
+ // ---- $Identifier ------------------------------------------------
84
+ ENTITY_REF_RE.lastIndex = 0;
85
+ while ((m = ENTITY_REF_RE.exec(line)) !== null) {
86
+ // Discard if preceded by another `$` (math fence `$$…$$`)
87
+ if (m.index > 0 && line[m.index - 1] === "$")
88
+ continue;
89
+ // Discard if preceded by `\` (escaped)
90
+ if (m.index > 0 && line[m.index - 1] === "\\")
91
+ continue;
92
+ const ident = m[0]; // includes leading `$`
93
+ const bare = m[1];
94
+ const col = m.index + 1;
95
+ markers.push({
96
+ kind: "entity",
97
+ ident,
98
+ convention: classifyConvention(bare),
99
+ range: {
100
+ start: { line: lineNo, column: col },
101
+ end: { line: lineNo, column: col + ident.length },
102
+ },
103
+ });
104
+ }
105
+ }
106
+ return markers;
107
+ }
108
+ /**
109
+ * Build an InlineContent. `storedText` is the verbatim source prose that
110
+ * `render` emits (§5.1 faithful); `recognitionText` is the flattened
111
+ * projection that modal / $Identifier recognition runs on (so `\bshall\b`
112
+ * still matches inside `_shall_`). For nodes whose text carries no inline
113
+ * markup the two are identical and behaviour is unchanged.
114
+ */
115
+ function inlineContent(storedText, recognitionText, range) {
116
+ const markers = extractMarkersFromText(recognitionText, range);
117
+ return { text: storedText, markers };
118
+ }
119
+ // ---------------------------------------------------------------------------
120
+ // mdast position → SourceRange
121
+ // ---------------------------------------------------------------------------
122
+ function positionToRange(pos) {
123
+ if (!pos) {
124
+ return { start: { line: 1, column: 1 }, end: { line: 1, column: 1 } };
125
+ }
126
+ return {
127
+ start: { line: pos.start.line, column: pos.start.column },
128
+ end: { line: pos.end.line, column: pos.end.column },
129
+ };
130
+ }
131
+ // ---------------------------------------------------------------------------
132
+ // verbatimSlice — faithful capture helper (§5.1)
133
+ // ---------------------------------------------------------------------------
134
+ /**
135
+ * Return the exact source substring for an mdast node `position`, with
136
+ * list-continuation indentation normalised to column 0 so the slice is a
137
+ * self-contained, column-0-anchored string. This is the load-bearing
138
+ * mechanism for §5.1 faithful capture (ADR-014; spec §5.1): remark
139
+ * populates byte `offset` when a string is passed to `.parse()`; a
140
+ * line/column reconstruction is the defensive fallback. Extracted from
141
+ * the original inline `TableNode` logic — behaviour is identical.
142
+ */
143
+ export function verbatimSlice(body, pos) {
144
+ if (!pos)
145
+ return "";
146
+ let raw;
147
+ if (pos.start.offset !== undefined && pos.end.offset !== undefined) {
148
+ raw = body.slice(pos.start.offset, pos.end.offset);
149
+ }
150
+ else {
151
+ const bodyLines = body.split("\n");
152
+ const startLine = pos.start.line - 1;
153
+ const endLine = pos.end.line - 1;
154
+ const startCol = pos.start.column - 1;
155
+ const endCol = pos.end.column - 1;
156
+ if (startLine === endLine) {
157
+ raw = bodyLines[startLine]?.slice(startCol, endCol) ?? "";
158
+ }
159
+ else {
160
+ const firstPart = bodyLines[startLine]?.slice(startCol) ?? "";
161
+ const middleParts = bodyLines.slice(startLine + 1, endLine);
162
+ const lastPart = bodyLines[endLine]?.slice(0, endCol) ?? "";
163
+ raw = [firstPart, ...middleParts, lastPart].join("\n");
164
+ }
165
+ }
166
+ const listIndent = pos.start.column - 1; // 0 for top-level nodes
167
+ if (listIndent > 0) {
168
+ const prefix = " ".repeat(listIndent);
169
+ const rawLines = raw.split("\n");
170
+ raw = [
171
+ rawLines[0],
172
+ ...rawLines.slice(1).map((line) => line.startsWith(prefix) ? line.slice(listIndent) : line),
173
+ ].join("\n");
174
+ }
175
+ return raw;
176
+ }
177
+ // ---------------------------------------------------------------------------
178
+ // Caption detection
179
+ // ---------------------------------------------------------------------------
180
+ /** Caption keywords from spec §2.6. */
181
+ const CAPTION_KEYWORDS = [
182
+ "Figure",
183
+ "Table",
184
+ "Listing",
185
+ "Feature",
186
+ "Equation",
187
+ "List",
188
+ ];
189
+ const CAPTION_RE = /^(Figure|Table|Listing|Feature|Equation|List):\s+(\S.*)/;
190
+ function tryCaptionParagraph(text) {
191
+ const m = CAPTION_RE.exec(text.trim());
192
+ if (!m)
193
+ return undefined;
194
+ return { keyword: m[1], text: m[2].trim() };
195
+ }
196
+ // ---------------------------------------------------------------------------
197
+ // Math detection — `$$` delimited paragraphs
198
+ // ---------------------------------------------------------------------------
199
+ const MATH_BLOCK_RE = /^\$\$([\s\S]*?)\$\$$/;
200
+ function tryMathParagraph(text) {
201
+ // Plain text that is exactly `$$ ... $$` → math block
202
+ const m = MATH_BLOCK_RE.exec(text.trim());
203
+ if (m)
204
+ return m[1];
205
+ return undefined;
206
+ }
207
+ // ---------------------------------------------------------------------------
208
+ // Admonition detection
209
+ // ---------------------------------------------------------------------------
210
+ const ADMONITION_FIRST_LINE_RE = /^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]/;
211
+ // ---------------------------------------------------------------------------
212
+ // Definition-list detection (GLFM `Term\n: def` pattern)
213
+ //
214
+ // remark-gfm does NOT parse GLFM definition lists; they come through as
215
+ // Paragraph nodes. We detect the pattern in the body string before parsing
216
+ // and handle them via our pre-pass.
217
+ //
218
+ // DONE_WITH_CONCERNS: single-item best-effort as documented in the PR brief.
219
+ // ---------------------------------------------------------------------------
220
+ const DEFLIST_RE = /^([^\n:][^\n]*)\n:\s+(.+)$/m;
221
+ function tryDefinitionList(text) {
222
+ const m = DEFLIST_RE.exec(text.trim());
223
+ if (!m)
224
+ return undefined;
225
+ return { term: m[1].trim(), definition: m[2].trim() };
226
+ }
227
+ /**
228
+ * Deterministically split a verbatim definition-list slice into its
229
+ * term and definition substrings.
230
+ *
231
+ * Detection still runs on the flattened text via {@linkcode
232
+ * tryDefinitionList} (markup-stripped recognition, mirroring caption /
233
+ * math detection). This function only governs what is *stored*: it
234
+ * returns the byte-exact verbatim term and definition so inline markup
235
+ * on either side survives.
236
+ *
237
+ * The split mirrors `renderDefinitionList` in `render.ts` exactly. That
238
+ * renderer emits `${term.text}\n: ${definition.text}` — one newline,
239
+ * then `: ` (colon + single space). The inverse is therefore: split on
240
+ * the first `\n:`, take everything before as the term, then consume the
241
+ * leading whitespace after the colon (the `\s+` that `DEFLIST_RE` and
242
+ * the canonical `: ` collapse). The remainder is the definition.
243
+ *
244
+ * Why this replaces `DEFLIST_RE.exec(verbatim.trim())`: that regex's
245
+ * `(.+)$` under the `/m` flag stops at the first newline, so a verbatim
246
+ * slice spanning multiple source lines silently lost everything after
247
+ * the first definition line and fell back to the flattened (markup-
248
+ * stripped) form. A deterministic first-`\n:` split never misses.
249
+ *
250
+ * Returns `undefined` only when the verbatim slice contains no `\n:`
251
+ * separator (cannot happen for a canonical single-item deflist that
252
+ * flattened-detection accepted, but kept total for safety).
253
+ */
254
+ function splitVerbatimDeflist(verbatim) {
255
+ const sepIndex = verbatim.indexOf("\n:");
256
+ if (sepIndex < 0)
257
+ return undefined;
258
+ const term = verbatim.slice(0, sepIndex);
259
+ // Skip the `\n:` then the leading whitespace the renderer re-emits
260
+ // as the single space in `: ` (same whitespace `DEFLIST_RE`'s `\s+`
261
+ // would have consumed).
262
+ let defStart = sepIndex + 2;
263
+ while (defStart < verbatim.length && /\s/.test(verbatim[defStart])) {
264
+ defStart++;
265
+ }
266
+ const definition = verbatim.slice(defStart);
267
+ return { term, definition };
268
+ }
269
+ // ---------------------------------------------------------------------------
270
+ // mdast text extraction helper
271
+ // ---------------------------------------------------------------------------
272
+ // deno-lint-ignore no-explicit-any
273
+ function extractMdastText(node) {
274
+ if (!node)
275
+ return "";
276
+ // Inline code nodes carry their value without delimiters in mdast;
277
+ // re-add the backtick delimiters so the round-trip is byte-identical.
278
+ if (node.type === "inlineCode")
279
+ return `\`${node.value}\``;
280
+ if (typeof node.value === "string")
281
+ return node.value;
282
+ if (Array.isArray(node.children)) {
283
+ return node.children.map(extractMdastText).join("");
284
+ }
285
+ return "";
286
+ }
287
+ // ---------------------------------------------------------------------------
288
+ // Caption position computation
289
+ // ---------------------------------------------------------------------------
290
+ /**
291
+ * Compute caption positions: "above" or "below" relative to adjacent blocks.
292
+ * This is a post-processing pass that examines caption nodes relative to their
293
+ * neighbours.
294
+ *
295
+ * DONE_WITH_CONCERNS: position is determined by source order heuristic —
296
+ * if the block *after* the caption is a non-caption, non-paragraph block,
297
+ * caption is "above"; if the block *before* is such a block, it's "below".
298
+ * For PR 2, defaults to "below" when adjacent block type is unclear.
299
+ */
300
+ function assignCaptionPositions(blocks) {
301
+ const result = [];
302
+ for (let i = 0; i < blocks.length; i++) {
303
+ if (blocks[i].kind !== "caption") {
304
+ result.push(blocks[i]);
305
+ continue;
306
+ }
307
+ const cap = blocks[i];
308
+ // Look ahead for a non-caption, non-paragraph block
309
+ const nextBlock = blocks[i + 1];
310
+ const prevBlock = result[result.length - 1];
311
+ const isCaptionable = (b) => {
312
+ if (!b)
313
+ return false;
314
+ return (b.kind === "figure" ||
315
+ b.kind === "table" ||
316
+ b.kind === "code" ||
317
+ b.kind === "feature" ||
318
+ b.kind === "math" ||
319
+ b.kind === "list");
320
+ };
321
+ let position;
322
+ if (isCaptionable(nextBlock)) {
323
+ position = "above";
324
+ }
325
+ else if (isCaptionable(prevBlock)) {
326
+ position = "below";
327
+ }
328
+ else {
329
+ // Default: below (conservative)
330
+ position = "below";
331
+ }
332
+ result.push({ ...cap, position });
333
+ }
334
+ return result;
335
+ }
336
+ // ---------------------------------------------------------------------------
337
+ // Blockquote de-quote (§5.1 faithful)
338
+ // ---------------------------------------------------------------------------
339
+ /**
340
+ * De-quote a verbatim blockquote slice: strip the per-line `> ` (or bare
341
+ * `>` for blank quoted lines) marker, preserving inline markup and the
342
+ * interior-blank-line convention. CommonMark canonical quoting is `> `
343
+ * on content lines and `>` alone on blank lines; a defensive `>`-without
344
+ * -space strip handles non-canonical input.
345
+ */
346
+ function deQuote(rawBlockquote) {
347
+ return rawBlockquote
348
+ .split("\n")
349
+ .map((line) => {
350
+ if (line.startsWith("> "))
351
+ return line.slice(2);
352
+ if (line === ">")
353
+ return "";
354
+ if (line.startsWith(">"))
355
+ return line.slice(1);
356
+ return line;
357
+ })
358
+ .join("\n");
359
+ }
360
+ // ---------------------------------------------------------------------------
361
+ // Main builder — mdast node → BodyBlock
362
+ // ---------------------------------------------------------------------------
363
+ // deno-lint-ignore no-explicit-any
364
+ function mapMdastNode(node, body) {
365
+ const range = positionToRange(node.position);
366
+ switch (node.type) {
367
+ case "paragraph": {
368
+ const text = extractMdastText(node); // flattened — detection + recognition
369
+ const verbatim = verbatimSlice(body, node.position);
370
+ // Check for lone image → FigureNode
371
+ if (node.children.length === 1 &&
372
+ node.children[0].type === "image") {
373
+ const img = node.children[0];
374
+ return {
375
+ kind: "figure",
376
+ alt: img.alt ?? "",
377
+ path: img.url ?? "",
378
+ range,
379
+ };
380
+ }
381
+ // Check for math `$$ ... $$` paragraph
382
+ const mathTex = tryMathParagraph(text);
383
+ if (mathTex !== undefined) {
384
+ return { kind: "math", tex: mathTex, range };
385
+ }
386
+ // Check for definition-list pattern `Term\n: def`
387
+ const defList = tryDefinitionList(text);
388
+ if (defList) {
389
+ // Detection ran on the flattened text (markup-stripped, like
390
+ // caption / math detection). The *stored* term and definition
391
+ // are the byte-exact verbatim substrings so inline markup on
392
+ // either side survives. The split is deterministic (first
393
+ // `\n:`) and mirrors `renderDefinitionList` exactly — it can
394
+ // never miss a multi-line verbatim slice the way the old
395
+ // `DEFLIST_RE.exec(verbatim.trim())` could, so there is no
396
+ // flattened fallback. `splitVerbatimDeflist` only returns
397
+ // `undefined` when there is no `\n:` at all (impossible here,
398
+ // since flattened detection already matched `\n:`); the
399
+ // `?? defList` keeps the expression total.
400
+ const split = splitVerbatimDeflist(verbatim) ?? defList;
401
+ const vTerm = split.term;
402
+ const vDef = split.definition;
403
+ const termRange = {
404
+ start: range.start,
405
+ end: range.start,
406
+ };
407
+ const defRange = {
408
+ start: range.start,
409
+ end: range.end,
410
+ };
411
+ return {
412
+ kind: "definition-list",
413
+ items: [
414
+ {
415
+ term: inlineContent(vTerm, defList.term, termRange),
416
+ definition: inlineContent(vDef, defList.definition, defRange),
417
+ },
418
+ ],
419
+ range,
420
+ };
421
+ }
422
+ // Check for caption `Figure: text` etc.
423
+ const caption = tryCaptionParagraph(text);
424
+ if (caption) {
425
+ // Position is resolved in a post-pass; default "below" for now
426
+ return {
427
+ kind: "caption",
428
+ keyword: caption.keyword,
429
+ text: caption.text,
430
+ position: "below",
431
+ range,
432
+ };
433
+ }
434
+ // Plain paragraph: store verbatim source, recognise on flattened text.
435
+ return {
436
+ kind: "paragraph",
437
+ content: inlineContent(verbatim, text, range),
438
+ range,
439
+ };
440
+ }
441
+ case "list": {
442
+ // Detect GFM task-list items (remark-gfm sets `checked` to true/false).
443
+ // deno-lint-ignore no-explicit-any
444
+ const hasTaskItems = node.children.some((item) => item.checked != null);
445
+ const items = node.children.map(
446
+ // deno-lint-ignore no-explicit-any
447
+ (item) => {
448
+ const itemRange = positionToRange(item.position);
449
+ const subBlocks = (item.children ?? []).map(
450
+ // deno-lint-ignore no-explicit-any
451
+ (child) => mapMdastNode(child, body));
452
+ return {
453
+ blocks: subBlocks,
454
+ ...(item.checked != null ? { checked: item.checked } : {}),
455
+ ...(item.spread != null ? { spread: item.spread } : {}),
456
+ range: itemRange,
457
+ };
458
+ });
459
+ return {
460
+ kind: "list",
461
+ ordered: node.ordered ?? false,
462
+ spread: node.spread ?? false,
463
+ items,
464
+ ...(hasTaskItems ? { hasTaskItems: true } : {}),
465
+ range,
466
+ };
467
+ }
468
+ case "table": {
469
+ // deno-lint-ignore no-explicit-any
470
+ const rows = node.children.map((row) =>
471
+ // deno-lint-ignore no-explicit-any
472
+ (row.children ?? []).map((cell) => {
473
+ const cellText = extractMdastText(cell);
474
+ const cellRange = positionToRange(cell.position);
475
+ // stored == recognition (table cells render via TableNode.raw; Task 5 confirms)
476
+ return inlineContent(cellText, cellText, cellRange);
477
+ }));
478
+ const [header = [], ...dataRows] = rows;
479
+ const raw = verbatimSlice(body, node.position);
480
+ return {
481
+ kind: "table",
482
+ header,
483
+ rows: dataRows,
484
+ raw,
485
+ range,
486
+ };
487
+ }
488
+ case "code": {
489
+ const lang = node.lang ?? undefined; // empty string → undefined
490
+ if (lang === "gherkin") {
491
+ return {
492
+ kind: "feature",
493
+ source: node.value ?? "",
494
+ range,
495
+ };
496
+ }
497
+ return {
498
+ kind: "code",
499
+ lang: lang || undefined,
500
+ text: node.value ?? "",
501
+ range,
502
+ };
503
+ }
504
+ case "blockquote": {
505
+ const verbatim = deQuote(verbatimSlice(body, node.position));
506
+ const firstChild = node.children?.[0];
507
+ if (firstChild?.type === "paragraph") {
508
+ const paraText = extractMdastText(firstChild);
509
+ const admonMatch = ADMONITION_FIRST_LINE_RE.exec(paraText.trim());
510
+ if (admonMatch) {
511
+ const kind = admonMatch[1];
512
+ // Flattened recognition text (unchanged from prior behaviour):
513
+ // marker-stripped first paragraph + remaining paragraphs.
514
+ const rest = paraText.replace(ADMONITION_FIRST_LINE_RE, "").trim();
515
+ const otherText = node.children
516
+ .slice(1)
517
+ // deno-lint-ignore no-explicit-any
518
+ .map((c) => extractMdastText(c))
519
+ .join("\n\n");
520
+ const flattened = [rest, otherText].filter(Boolean).join("\n\n");
521
+ // Verbatim stored text: de-quoted slice with the `[!KIND]`
522
+ // token removed from the first line. Anything the author put
523
+ // after the marker on the same line is kept verbatim.
524
+ const vLines = verbatim.split("\n");
525
+ // `kind` is enum-constrained (NOTE|TIP|IMPORTANT|WARNING|CAUTION,
526
+ // captured by ADMONITION_FIRST_LINE_RE) — no regex metacharacters,
527
+ // so this dynamic RegExp is injection-safe (no escaping needed).
528
+ const markerRe = new RegExp(`^\\[!${kind}\\]`);
529
+ const afterMarker = (vLines[0] ?? "").replace(markerRe, "");
530
+ const bodyLines = vLines.slice(1);
531
+ // A non-empty `afterMarker` means the body began on the marker
532
+ // line (`> [!KIND] text`). Record it so the renderer reproduces
533
+ // the same-line form rather than rewriting to the own-line form.
534
+ const markerInline = afterMarker.trim().length > 0;
535
+ const storedText = markerInline
536
+ ? [afterMarker.trimStart(), ...bodyLines].join("\n")
537
+ : bodyLines.join("\n");
538
+ return {
539
+ kind: "note",
540
+ admonition: kind,
541
+ content: inlineContent(storedText, flattened, range),
542
+ ...(markerInline ? { markerInline: true } : {}),
543
+ range,
544
+ };
545
+ }
546
+ }
547
+ const bqFlattened = node.children
548
+ // deno-lint-ignore no-explicit-any
549
+ .map((c) => extractMdastText(c))
550
+ .join("\n\n");
551
+ return {
552
+ kind: "blockquote",
553
+ content: inlineContent(verbatim, bqFlattened, range),
554
+ range,
555
+ };
556
+ }
557
+ default: {
558
+ let subkind;
559
+ if (node.type === "heading" ||
560
+ node.type === "setextHeading") {
561
+ subkind = "heading";
562
+ }
563
+ else if (node.type === "thematicBreak") {
564
+ subkind = "thematic-break";
565
+ }
566
+ else if (node.type === "html") {
567
+ subkind = "html";
568
+ }
569
+ return {
570
+ kind: "unknown",
571
+ raw: verbatimSlice(body, node.position),
572
+ ...(subkind !== undefined ? { subkind } : {}),
573
+ range,
574
+ };
575
+ }
576
+ }
577
+ }
578
+ // ---------------------------------------------------------------------------
579
+ // Public API
580
+ // ---------------------------------------------------------------------------
581
+ /**
582
+ * Build the canonical body AST from an entry body string.
583
+ *
584
+ * Re-parses `body` via the shared remark processor (CommonMark+GFM) and
585
+ * maps each block-level mdast node to a `BodyBlock`. SourceRange positions
586
+ * are body-relative (1-based line/column) matching the mdast output directly.
587
+ *
588
+ * DONE_WITH_CONCERNS notes:
589
+ * - DefinitionList: single-item best-effort. `Term\n: def` patterns in
590
+ * multi-item lists are parsed as one DefinitionListNode per paragraph
591
+ * block; the validator would need to coalesce them (deferred).
592
+ * - Caption position: assigned by adjacent-block heuristic (post-pass).
593
+ * `block` (resolved owner) is `undefined` for PR 2 per spec.
594
+ * - Multi-line paragraph marker ranges: SourceRange is approximated to
595
+ * the paragraph start line; intra-paragraph column tracking is correct
596
+ * only for single-line paragraphs.
597
+ */
598
+ export function buildBodyAst(body) {
599
+ if (!body.trim())
600
+ return [];
601
+ const tree = processor.parse(body);
602
+ const blocks = tree.children.map((node) => mapMdastNode(node, body));
603
+ // Post-pass: assign caption positions
604
+ return assignCaptionPositions(blocks);
605
+ }