@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
@@ -5,8 +5,10 @@
5
5
  * `- [DISPLAY_ID] Title` entry blocks and extract structured attributes.
6
6
  */
7
7
  import { IDENTITY_KEY, shapeFromIdValue } from "../model/mod.js";
8
- import { collateAttributes, parseAttributes, splitBodyAndAttributes, } from "./attributes.js";
8
+ import { ATTR_LINE_RE, collateAttributes, parseAttributes, splitBodyAndAttributes, } from "./attributes.js";
9
+ import { extractEntityRefs } from "./entity_refs.js";
9
10
  import { processor } from "./remark.js";
11
+ import { buildBodyAst } from "../ast/build.js";
10
12
  /**
11
13
  * Slug pattern for referenced-entry display IDs.
12
14
  *
@@ -17,6 +19,10 @@ import { processor } from "./remark.js";
17
19
  const SLUG_RE = /^[A-Za-z]([A-Za-z0-9._/-]*[A-Za-z0-9])?$/;
18
20
  /** Match `[...]` at the start of a list item paragraph. Captures: [1] = display ID, [2] = title. */
19
21
  const ENTRY_START_RE = /^\[([^\]]+)\]\s*(.*)$/;
22
+ /** Match `[]` at the start — empty brackets. */
23
+ const EMPTY_BRACKET_RE = /^\[\]\s*(.*)$/;
24
+ /** Match `[` at the start without a closing `]` on the same logical content — unterminated. */
25
+ const UNTERMINATED_BRACKET_RE = /^\[[^\]]*$/;
20
26
  /**
21
27
  * Find the `Id:` attribute on an entry. Returns undefined when absent. If
22
28
  * more than one `Id:` is present, returns the first — the validator flags
@@ -39,13 +45,14 @@ function findIdentityAttribute(attributes) {
39
45
  *
40
46
  * @param markdown - Markdown source text
41
47
  * @param options - Parse options (file path for source locations)
42
- * @returns Array of parsed entries
48
+ * @returns Parsed entries and any parse-level diagnostics
43
49
  */
44
50
  export function parseMarkdown(markdown, options) {
45
51
  const file = options?.file ?? "<unknown>";
46
52
  const isReferencesDoc = detectReferencesDocument(file, options?.isReferencesDoc);
47
53
  const tree = processor.parse(markdown);
48
54
  const entries = [];
55
+ const diagnostics = [];
49
56
  // Collect link definition identifiers for shortcut reference exclusion.
50
57
  const definitions = new Set(tree.children
51
58
  .filter((n) => n.type === "definition")
@@ -58,12 +65,12 @@ export function parseMarkdown(markdown, options) {
58
65
  if (list.ordered)
59
66
  continue;
60
67
  for (const item of list.children) {
61
- const entry = extractEntry(item, markdown, file, definitions, isReferencesDoc);
68
+ const entry = extractEntry(item, markdown, file, definitions, isReferencesDoc, diagnostics);
62
69
  if (entry)
63
70
  entries.push(entry);
64
71
  }
65
72
  }
66
- return entries;
73
+ return { entries, diagnostics };
67
74
  }
68
75
  /**
69
76
  * Detect if a file is a references document.
@@ -80,8 +87,9 @@ function detectReferencesDocument(file, explicit) {
80
87
  /**
81
88
  * Attempt to extract a MarkSpec entry from a list item.
82
89
  * Returns undefined if the list item is not an entry block.
90
+ * Diagnostics (e.g., deprecation warnings) are pushed into the accumulator.
83
91
  */
84
- function extractEntry(item, markdown, file, definitions, isReferencesDoc) {
92
+ function extractEntry(item, markdown, file, definitions, isReferencesDoc, diagnostics) {
85
93
  // Task list items (remark-gfm sets checked to true/false) are not entries.
86
94
  if (item.checked != null)
87
95
  return undefined;
@@ -103,11 +111,36 @@ function extractEntry(item, markdown, file, definitions, isReferencesDoc) {
103
111
  let title;
104
112
  if (firstInline.type === "text") {
105
113
  // remark may parse `[ID] Title` as a single text node
106
- const match = ENTRY_START_RE.exec(firstInline.value);
114
+ const textValue = firstInline.value;
115
+ const match = ENTRY_START_RE.exec(textValue);
107
116
  if (match) {
108
117
  displayId = match[1];
109
118
  title = match[2].trim();
110
119
  }
120
+ else if (EMPTY_BRACKET_RE.test(textValue)) {
121
+ // MSL-P001: bracketed content is empty — `- [] Title`
122
+ const entryLine = item.position?.start.line ?? 1;
123
+ diagnostics.push({
124
+ code: "MSL-P001",
125
+ severity: "error",
126
+ message: "list item starts with `[]` but the bracketed content is empty " +
127
+ "(spec section 4.1)",
128
+ location: { file, line: entryLine, column: 1 },
129
+ });
130
+ return undefined;
131
+ }
132
+ else if (UNTERMINATED_BRACKET_RE.test(textValue)) {
133
+ // MSL-P003: display-ID brackets unterminated (missing `]`)
134
+ const entryLine = item.position?.start.line ?? 1;
135
+ diagnostics.push({
136
+ code: "MSL-P003",
137
+ severity: "error",
138
+ message: "display-ID brackets unterminated -- missing `]` before end of " +
139
+ "title line (spec section 4.1)",
140
+ location: { file, line: entryLine, column: 1 },
141
+ });
142
+ return undefined;
143
+ }
111
144
  }
112
145
  // Try linkReference pattern: remark sometimes parses [ID] as a linkReference
113
146
  if (!displayId && firstInline.type === "linkReference") {
@@ -138,10 +171,180 @@ function extractEntry(item, markdown, file, definitions, isReferencesDoc) {
138
171
  // citation compatibility. Canonical slug never contains `@`.
139
172
  if (displayId.startsWith("@"))
140
173
  displayId = displayId.slice(1);
174
+ // MSL-I005: Display ID is empty (after `@` stripping).
175
+ if (displayId.length === 0) {
176
+ const entryLine = item.position?.start.line ?? 1;
177
+ diagnostics.push({
178
+ code: "MSL-I005",
179
+ severity: "error",
180
+ message: "display ID is empty (spec section 4.2)",
181
+ location: { file, line: entryLine, column: 1 },
182
+ });
183
+ return undefined;
184
+ }
185
+ // MSL-P002: title text missing after `]`. The title capture is empty
186
+ // and was not populated from subsequent nodes (linkReference path sets
187
+ // title from rest nodes).
188
+ if (title !== undefined && title.length === 0) {
189
+ const entryLine = item.position?.start.line ?? 1;
190
+ diagnostics.push({
191
+ code: "MSL-P002",
192
+ severity: "error",
193
+ message: `${displayId}: title line missing title text after ']' (spec section 4.1)`,
194
+ location: { file, line: entryLine, column: 1 },
195
+ });
196
+ // Continue parsing — entry is still structurally valid for downstream
197
+ // validation (MSL-P010 also fires from the validator for empty titles).
198
+ }
141
199
  // Extract body content and attributes.
142
200
  const bodyContent = extractBodyContent(item, markdown);
143
201
  const [body, attrLines] = splitBodyAndAttributes(bodyContent);
144
202
  const attributes = parseAttributes(attrLines);
203
+ const bodyAst = buildBodyAst(body);
204
+ const entryLine = item.position?.start.line ?? 1;
205
+ // MSL-P020: trailers block is not the final indented code block.
206
+ // Detect `Key: Value` lines in the body that likely should be trailers
207
+ // but are not at the final position (body content follows them).
208
+ // Exclude caption keywords (Figure:, Table:, etc.) which are legitimate
209
+ // body content, not misplaced trailer attributes.
210
+ const CAPTION_KEYWORDS = new Set([
211
+ "Figure",
212
+ "Table",
213
+ "Listing",
214
+ "Feature",
215
+ "Equation",
216
+ "List",
217
+ ]);
218
+ if (body.length > 0) {
219
+ const bodyLines = body.split("\n");
220
+ let inFencedBlock = false;
221
+ for (let i = 0; i < bodyLines.length; i++) {
222
+ const trimmed = bodyLines[i].trim();
223
+ // Track fenced code blocks (``` or ~~~) to skip their contents
224
+ if (/^(`{3,}|~{3,})/.test(trimmed)) {
225
+ inFencedBlock = !inFencedBlock;
226
+ continue;
227
+ }
228
+ if (inFencedBlock)
229
+ continue;
230
+ if (!ATTR_LINE_RE.test(trimmed))
231
+ continue;
232
+ // Extract the key portion to check against caption keywords
233
+ const keyMatch = trimmed.match(/^([A-Z][A-Za-z-]*):/);
234
+ if (keyMatch && CAPTION_KEYWORDS.has(keyMatch[1]))
235
+ continue;
236
+ // Found a Key: Value line in the body — non-final position
237
+ diagnostics.push({
238
+ code: "MSL-P020",
239
+ severity: "error",
240
+ message: `${displayId}: trailers block is not the final indented code ` +
241
+ `block of the entry -- content appears after trailer-like ` +
242
+ `lines (spec section 4.1)`,
243
+ location: { file, line: entryLine, column: 1 },
244
+ });
245
+ break; // One diagnostic per entry is sufficient
246
+ }
247
+ }
248
+ // MSL-P021 / MSL-P022: validate trailer lines for syntax correctness.
249
+ // The trailer block is the final indented code block. Lines within it
250
+ // should all match `Key: Value` syntax. We check both the parsed
251
+ // attrLines AND the trailing body lines that might be in a code block
252
+ // but failed ATTR_LINE_RE (thus stayed in the body).
253
+ const TRAILER_KEY_RE = /^[A-Za-z][A-Za-z0-9-]*$/;
254
+ const COLON_SPLIT_RE = /^([^:]+):\s*(.*)$/;
255
+ // Check lines that DID end up in attrLines but might have key issues
256
+ for (const rawLine of attrLines) {
257
+ const trimmed = rawLine.trim();
258
+ if (!trimmed)
259
+ continue;
260
+ if (!ATTR_LINE_RE.test(trimmed)) {
261
+ const colonMatch = COLON_SPLIT_RE.exec(trimmed);
262
+ if (colonMatch) {
263
+ const key = colonMatch[1].trim();
264
+ if (!TRAILER_KEY_RE.test(key)) {
265
+ diagnostics.push({
266
+ code: "MSL-P022",
267
+ severity: "error",
268
+ message: `${displayId}: trailer key '${key}' contains characters ` +
269
+ `outside [A-Za-z][A-Za-z0-9-]* (spec section 4.1)`,
270
+ location: { file, line: entryLine, column: 1 },
271
+ });
272
+ }
273
+ else {
274
+ diagnostics.push({
275
+ code: "MSL-P021",
276
+ severity: "error",
277
+ message: `${displayId}: trailer line does not match 'Key: Value' ` +
278
+ `syntax (spec section 4.1): "${trimmed}"`,
279
+ location: { file, line: entryLine, column: 1 },
280
+ });
281
+ }
282
+ }
283
+ else {
284
+ diagnostics.push({
285
+ code: "MSL-P021",
286
+ severity: "error",
287
+ message: `${displayId}: trailer line does not match 'Key: Value' ` +
288
+ `syntax (spec section 4.1): "${trimmed}"`,
289
+ location: { file, line: entryLine, column: 1 },
290
+ });
291
+ }
292
+ }
293
+ }
294
+ // Also scan trailing body lines for suspected misplaced trailers.
295
+ // If the body's last non-empty lines look like they belong to an
296
+ // indented code block with colon-separated content that has invalid
297
+ // keys, emit P022. Lines without colons that appear in what looks
298
+ // like a trailer block emit P021.
299
+ if (body.length > 0) {
300
+ const bodyLines = body.split("\n");
301
+ // Walk backward from the end of the body to find lines in a trailing
302
+ // code-block-like region that have colons (suspected trailers).
303
+ for (let i = bodyLines.length - 1; i >= 0; i--) {
304
+ const trimmed = bodyLines[i].trim();
305
+ if (!trimmed)
306
+ continue; // skip trailing blanks
307
+ const colonMatch = COLON_SPLIT_RE.exec(trimmed);
308
+ if (!colonMatch)
309
+ break; // stop at non-colon line
310
+ const key = colonMatch[1].trim();
311
+ if (ATTR_LINE_RE.test(trimmed)) {
312
+ // Valid attr line in body → already caught by P020
313
+ continue;
314
+ }
315
+ if (!TRAILER_KEY_RE.test(key)) {
316
+ diagnostics.push({
317
+ code: "MSL-P022",
318
+ severity: "error",
319
+ message: `${displayId}: trailer key '${key}' contains characters ` +
320
+ `outside [A-Za-z][A-Za-z0-9-]* (spec section 4.1)`,
321
+ location: { file, line: entryLine, column: 1 },
322
+ });
323
+ }
324
+ else if (colonMatch[2].trim().length === 0) {
325
+ diagnostics.push({
326
+ code: "MSL-P021",
327
+ severity: "error",
328
+ message: `${displayId}: trailer line does not match 'Key: Value' ` +
329
+ `syntax (spec section 4.1): "${trimmed}"`,
330
+ location: { file, line: entryLine, column: 1 },
331
+ });
332
+ }
333
+ break; // one diagnostic per trailing suspect line is sufficient
334
+ }
335
+ }
336
+ // Detect legacy paragraph + trailing-backslash attribute form and warn.
337
+ if (attributes.length > 0 &&
338
+ attrLines.some((line) => line.trimEnd().endsWith("\\"))) {
339
+ const entryLine = item.position?.start.line ?? 1;
340
+ diagnostics.push({
341
+ code: "MSL-DEPRECATED-ATTR-001",
342
+ severity: "warning",
343
+ message: "legacy attribute block (paragraph with trailing `\\`) is deprecated; " +
344
+ "run `markspec format` to convert to the canonical indented code block",
345
+ location: { file, line: entryLine, column: 1 },
346
+ });
347
+ }
145
348
  // Discriminate shape by the `Id:` attribute's value format.
146
349
  let shape;
147
350
  let id;
@@ -153,45 +356,72 @@ function extractEntry(item, markdown, file, definitions, isReferencesDoc) {
153
356
  // `Id:` is neither a ULID nor a scheme-qualified URI. Accept as an
154
357
  // identified entry so the validator can surface MSL-R004; missing
155
358
  // shape on a parsed entry is not useful downstream.
156
- shape = "identified";
359
+ shape = "Authored";
157
360
  }
158
361
  }
159
362
  else {
160
363
  // No `Id:`. Fall back on display-ID shape + document context to decide
161
364
  // whether to admit the entry at all.
162
365
  if (isReferencesDoc && SLUG_RE.test(displayId)) {
163
- shape = "referenced";
366
+ shape = "Reference";
164
367
  }
165
368
  else {
166
369
  // No identity attribute and no references-doc context — admit as
167
370
  // identified so the validator can surface the missing-`Id:` error.
168
- shape = "identified";
371
+ shape = "Authored";
169
372
  }
170
373
  }
171
374
  // Inferred type from display-ID prefix — left to the profile layer. For
172
375
  // now the core records no type; downstream profile-aware code populates
173
376
  // this field when a profile is loaded.
174
377
  const type = undefined;
378
+ // MSL-P030: Authored entry has no body block (title + trailers only).
379
+ // For Reference shape, body is optional (ADR-002 section Part 3). For Authored,
380
+ // the body is required. We also emit P030 when the body is empty (all
381
+ // content was consumed as attributes).
382
+ if (shape === "Authored" && body.trim().length === 0) {
383
+ diagnostics.push({
384
+ code: "MSL-P030",
385
+ severity: "error",
386
+ message: `${displayId}: Authored entry has no body block -- entries must ` +
387
+ `have body content between title and trailers (spec section 4.1)`,
388
+ location: { file, line: entryLine, column: 1 },
389
+ });
390
+ }
175
391
  // Body requirement: identified entries require a body; referenced entries
176
392
  // may omit it. If there's only one child (the title paragraph), admit
177
393
  // only referenced entries.
178
- if (shape !== "referenced" && item.children.length < 2)
394
+ if (shape !== "Reference" && item.children.length < 2)
179
395
  return undefined;
180
396
  // Source location
181
397
  const line = item.position?.start.line ?? 1;
182
398
  const column = item.position?.start.column ?? 1;
399
+ const entryLocation = { file, line, column };
400
+ // Inline `$Identifier` entity references (spec section 2.5.2). Resolution
401
+ // into the project's entity registry is left to the validator's
402
+ // marker pass; the parser only emits the lexical hits.
403
+ // Pass the already-built bodyAst to avoid a redundant mdast parse.
404
+ const entityRefs = extractEntityRefs(body, {
405
+ file,
406
+ // Body content starts on the line after the title; +1 keeps
407
+ // emitted line numbers 1-based relative to the file.
408
+ line: line + 1,
409
+ column: 1,
410
+ }, bodyAst);
183
411
  return {
184
412
  displayId,
185
413
  title: title ?? "",
186
414
  body,
415
+ bodyAst,
187
416
  rawAttributes: attributes,
188
417
  typedAttributes: collateAttributes(attributes),
189
418
  id,
190
419
  type,
191
420
  shape,
192
- location: { file, line, column },
421
+ location: entryLocation,
193
422
  source: "markdown",
194
423
  properties: { file: { path: file, line, column } },
424
+ entityRefs: entityRefs.length > 0 ? entityRefs : undefined,
195
425
  };
196
426
  }
197
427
  /**
@@ -20,6 +20,7 @@ export { detectInlineRefs } from "./references.js";
20
20
  export type { DetectInlineRefsOptions } from "./references.js";
21
21
  export { parseSource } from "./source.js";
22
22
  export type { ParseSourceOptions, ParseSourceResult } from "./source.js";
23
+ export { stripBlockCommentPrefix, stripLineCommentPrefix, wrapAsListItem, } from "./source.js";
23
24
  export { isSupportedExtension, loadGrammar } from "./grammars.js";
24
25
  /** Options for {@linkcode parse}. */
25
26
  export interface ParseOptions {
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/parser/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAK5E,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EACV,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAElE,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,YAAY,GACrB,KAAK,EAAE,CAET;AAED,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAYD;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC,OAAO,CAAC,eAAe,CAAC,CAiC1B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,EAAE,CAEX"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/parser/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAK5E,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EACV,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAElE,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,YAAY,GACrB,KAAK,EAAE,CAET;AAED,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAYD;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC,OAAO,CAAC,eAAe,CAAC,CAiC1B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,EAAE,CAEX"}
package/esm/parser/mod.js CHANGED
@@ -19,6 +19,7 @@ export { detectDirectives } from "./directives.js";
19
19
  export { extractFrontMatter } from "./frontmatter.js";
20
20
  export { detectInlineRefs } from "./references.js";
21
21
  export { parseSource } from "./source.js";
22
+ export { stripBlockCommentPrefix, stripLineCommentPrefix, wrapAsListItem, } from "./source.js";
22
23
  export { isSupportedExtension, loadGrammar } from "./grammars.js";
23
24
  /**
24
25
  * Parse a Markdown string and return all MarkSpec entries found.
@@ -28,7 +29,7 @@ export { isSupportedExtension, loadGrammar } from "./grammars.js";
28
29
  * @returns Array of parsed entries
29
30
  */
30
31
  export function parse(markdown, options) {
31
- return parseMarkdown(markdown, options);
32
+ return parseMarkdown(markdown, options).entries;
32
33
  }
33
34
  /**
34
35
  * Detect if a file is a references document.
@@ -60,7 +61,7 @@ export async function parseFile(content, options) {
60
61
  const fm = extractFrontMatter(content, { file: options.file });
61
62
  const body = fm.hadFrontMatter ? fm.markdown : content;
62
63
  const isReferencesDoc = isReferencesDocument(options.file);
63
- const entries = parseMarkdown(body, {
64
+ const { entries, diagnostics: parseDiagnostics } = parseMarkdown(body, {
64
65
  file: options.file,
65
66
  isReferencesDoc,
66
67
  });
@@ -74,7 +75,7 @@ export async function parseFile(content, options) {
74
75
  return {
75
76
  entries,
76
77
  document,
77
- diagnostics: fm.diagnostics,
78
+ diagnostics: [...fm.diagnostics, ...parseDiagnostics],
78
79
  };
79
80
  }
80
81
  /**
@@ -5,6 +5,7 @@
5
5
  * comments in Rust, Kotlin, C, C++, and Java source files. Delegates parsed
6
6
  * content to the markdown parser for entry extraction.
7
7
  */
8
+ import type { SyntaxNode } from "web-tree-sitter";
8
9
  import Parser from "web-tree-sitter";
9
10
  import type { Entry } from "../model/mod.js";
10
11
  /** Options for {@linkcode parseSource}. */
@@ -30,4 +31,23 @@ export interface ParseSourceResult {
30
31
  * @param options - Parse options (language grammar, file path)
31
32
  */
32
33
  export declare function parseSource(content: string, options: ParseSourceOptions): ParseSourceResult;
34
+ /**
35
+ * Strip the `///` prefix from a line comment node.
36
+ * Uses the `doc_comment` child if available, otherwise strips manually.
37
+ */
38
+ export declare function stripLineCommentPrefix(node: SyntaxNode): string;
39
+ /**
40
+ * Strip block comment delimiters and leading ` * ` prefixes.
41
+ * Returns cleaned lines.
42
+ */
43
+ export declare function stripBlockCommentPrefix(text: string): string[];
44
+ /**
45
+ * Wrap cleaned doc comment lines as a Markdown list item so the
46
+ * existing `parseMarkdown()` can extract entries.
47
+ *
48
+ * Doc comments use `[DISPLAY_ID] Title` without the `- ` bullet.
49
+ * This wraps to `- [DISPLAY_ID] Title\n\n body...` which parseMarkdown
50
+ * recognizes as an entry block.
51
+ */
52
+ export declare function wrapAsListItem(lines: string[]): string;
33
53
  //# sourceMappingURL=source.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/parser/source.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,2CAA2C;AAC3C,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;CACpC;AAED,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;CAC3B;AAYD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC1B,iBAAiB,CAsCnB"}
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/parser/source.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,2CAA2C;AAC3C,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;CACpC;AAED,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;CAC3B;AAYD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC1B,iBAAiB,CAsCnB;AAiFD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAe/D;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAgC9D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAKtD"}
@@ -27,7 +27,7 @@ export function parseSource(content, options) {
27
27
  const entries = [];
28
28
  for (const block of blocks) {
29
29
  const markdown = wrapAsListItem(block.lines);
30
- const parsed = parseMarkdown(markdown, { file });
30
+ const { entries: parsed } = parseMarkdown(markdown, { file });
31
31
  for (const entry of parsed) {
32
32
  const location = {
33
33
  file,
@@ -122,7 +122,7 @@ function isOuterDocComment(node) {
122
122
  * Strip the `///` prefix from a line comment node.
123
123
  * Uses the `doc_comment` child if available, otherwise strips manually.
124
124
  */
125
- function stripLineCommentPrefix(node) {
125
+ export function stripLineCommentPrefix(node) {
126
126
  for (let i = 0; i < node.childCount; i++) {
127
127
  const child = node.child(i);
128
128
  if (child.type === "doc_comment") {
@@ -145,7 +145,7 @@ function stripLineCommentPrefix(node) {
145
145
  * Strip block comment delimiters and leading ` * ` prefixes.
146
146
  * Returns cleaned lines.
147
147
  */
148
- function stripBlockCommentPrefix(text) {
148
+ export function stripBlockCommentPrefix(text) {
149
149
  const rawLines = text.split("\n");
150
150
  const result = [];
151
151
  for (let i = 0; i < rawLines.length; i++) {
@@ -183,7 +183,7 @@ function stripBlockCommentPrefix(text) {
183
183
  * This wraps to `- [DISPLAY_ID] Title\n\n body...` which parseMarkdown
184
184
  * recognizes as an entry block.
185
185
  */
186
- function wrapAsListItem(lines) {
186
+ export function wrapAsListItem(lines) {
187
187
  if (lines.length === 0)
188
188
  return "";
189
189
  const first = `- ${lines[0]}`;
@@ -171,22 +171,12 @@ function stringifySpec(spec) {
171
171
  * contents are irrelevant.
172
172
  */
173
173
  function buildPlaceholderEffective(tiers) {
174
- const leafOrigin = tiers[tiers.length - 1]?.id ?? "<unknown>";
174
+ const _leafOrigin = tiers[tiers.length - 1]?.id ?? "<unknown>";
175
175
  return {
176
- required: { value: [], origin: leafOrigin },
177
176
  attributes: new Map(),
178
- labels: { value: [], origin: leafOrigin },
177
+ labels: new Map(),
178
+ conventions: new Map(),
179
179
  colors: new Map(),
180
- identified: {
181
- required: { value: [], origin: leafOrigin },
182
- attributes: new Map(),
183
- traceability: new Map(),
184
- },
185
- referenced: {
186
- required: { value: [], origin: leafOrigin },
187
- attributes: new Map(),
188
- traceability: new Map(),
189
- },
190
180
  types: new Map(),
191
181
  documents: { types: new Map(), frontMatter: new Map() },
192
182
  };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @module core/profile/colors
3
+ *
4
+ * Profile-driven entry color resolution. Pure function that maps an entry
5
+ * and the active profile to a palette hue name (or `null` for uncolored).
6
+ *
7
+ * Lives in core/profile so both rendering layers (Typst PDF and HTML book)
8
+ * can call it without crossing the peer-module boundary defined in AGENTS.md.
9
+ *
10
+ * See docs/superpowers/specs/2026-05-06-profile-driven-entry-colors-design.md
11
+ * for the resolution table.
12
+ */
13
+ import type { EffectiveProfile, Entry } from "../model/mod.js";
14
+ import { type PaletteHue } from "../model/palette.js";
15
+ /**
16
+ * Resolve the palette hue for an entry under the active profile.
17
+ *
18
+ * Returns `null` for referenced-shape entries (uncolored block).
19
+ * Returns a palette hue name for identified entries — using the type's
20
+ * declared color when available, falling back to `"blue"` otherwise.
21
+ *
22
+ * The fallback is the palette hue directly (not the `primary` semantic
23
+ * name) so the renderer works for files compiled without a profile.
24
+ */
25
+ export declare function resolveEntryColor(entry: Entry, profile: EffectiveProfile | undefined): PaletteHue | null;
26
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/profile/colors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKpE;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,GAAG,SAAS,GACpC,UAAU,GAAG,IAAI,CAmBnB"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @module core/profile/colors
3
+ *
4
+ * Profile-driven entry color resolution. Pure function that maps an entry
5
+ * and the active profile to a palette hue name (or `null` for uncolored).
6
+ *
7
+ * Lives in core/profile so both rendering layers (Typst PDF and HTML book)
8
+ * can call it without crossing the peer-module boundary defined in AGENTS.md.
9
+ *
10
+ * See docs/superpowers/specs/2026-05-06-profile-driven-entry-colors-design.md
11
+ * for the resolution table.
12
+ */
13
+ import { PALETTE_HUES } from "../model/palette.js";
14
+ /** Default identified-entry hue when no profile / no type color resolves. */
15
+ const DEFAULT_HUE = "blue";
16
+ /**
17
+ * Resolve the palette hue for an entry under the active profile.
18
+ *
19
+ * Returns `null` for referenced-shape entries (uncolored block).
20
+ * Returns a palette hue name for identified entries — using the type's
21
+ * declared color when available, falling back to `"blue"` otherwise.
22
+ *
23
+ * The fallback is the palette hue directly (not the `primary` semantic
24
+ * name) so the renderer works for files compiled without a profile.
25
+ */
26
+ export function resolveEntryColor(entry, profile) {
27
+ if (entry.shape === "Reference")
28
+ return null;
29
+ if (!profile || !entry.type)
30
+ return DEFAULT_HUE;
31
+ const typeDef = profile.types.get(entry.type);
32
+ const colorName = typeDef?.value.color.value;
33
+ if (!colorName)
34
+ return DEFAULT_HUE;
35
+ const hueEntry = profile.colors.get(colorName);
36
+ if (!hueEntry)
37
+ return DEFAULT_HUE;
38
+ // Defense in depth: the manifest parser already enforces PALETTE_HUES, but
39
+ // EffectiveProfile can in principle be constructed programmatically (tests,
40
+ // future APIs) without going through parseManifest. Guard the cast so an
41
+ // invalid hue can never reach downstream interpolation.
42
+ const hue = hueEntry.value;
43
+ if (!PALETTE_HUES.includes(hue))
44
+ return DEFAULT_HUE;
45
+ return hue;
46
+ }