@driftsys/markspec 0.4.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 (319) 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 +49 -4
  34. package/esm/formatter/mod.d.ts.map +1 -1
  35. package/esm/formatter/mod.js +362 -33
  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 +19 -6
  58. package/esm/mod.d.ts.map +1 -1
  59. package/esm/mod.js +14 -3
  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 +98 -3
  66. package/esm/model/mod.d.ts.map +1 -1
  67. package/esm/model/mod.js +57 -2
  68. package/esm/model/profile.d.ts +33 -27
  69. package/esm/model/profile.d.ts.map +1 -1
  70. package/esm/model/source_introspection.d.ts +26 -0
  71. package/esm/model/source_introspection.d.ts.map +1 -0
  72. package/esm/model/source_introspection.js +77 -0
  73. package/esm/model/type_hierarchy.d.ts +51 -0
  74. package/esm/model/type_hierarchy.d.ts.map +1 -0
  75. package/esm/model/type_hierarchy.js +126 -0
  76. package/esm/model/uri_scheme_map.d.ts +21 -0
  77. package/esm/model/uri_scheme_map.d.ts.map +1 -0
  78. package/esm/model/uri_scheme_map.js +66 -0
  79. package/esm/parser/attributes.d.ts.map +1 -1
  80. package/esm/parser/attributes.js +9 -6
  81. package/esm/parser/entity_refs.d.ts +53 -0
  82. package/esm/parser/entity_refs.d.ts.map +1 -0
  83. package/esm/parser/entity_refs.js +151 -0
  84. package/esm/parser/glossary.d.ts +43 -0
  85. package/esm/parser/glossary.d.ts.map +1 -0
  86. package/esm/parser/glossary.js +217 -0
  87. package/esm/parser/markdown.d.ts.map +1 -1
  88. package/esm/parser/markdown.js +223 -7
  89. package/esm/parser/mod.d.ts +1 -0
  90. package/esm/parser/mod.d.ts.map +1 -1
  91. package/esm/parser/mod.js +1 -0
  92. package/esm/parser/source.d.ts +20 -0
  93. package/esm/parser/source.d.ts.map +1 -1
  94. package/esm/parser/source.js +3 -3
  95. package/esm/profile/chain.js +3 -13
  96. package/esm/profile/colors.js +1 -1
  97. package/esm/profile/introspect.d.ts +135 -0
  98. package/esm/profile/introspect.d.ts.map +1 -0
  99. package/esm/profile/introspect.js +378 -0
  100. package/esm/profile/load.d.ts.map +1 -1
  101. package/esm/profile/load.js +67 -0
  102. package/esm/profile/manifest.d.ts.map +1 -1
  103. package/esm/profile/manifest.js +277 -88
  104. package/esm/profile/merge.js +139 -39
  105. package/esm/profile/mod.d.ts +2 -4
  106. package/esm/profile/mod.d.ts.map +1 -1
  107. package/esm/profile/mod.js +5 -2
  108. package/esm/reporter/mod.js +4 -4
  109. package/esm/util/fence.d.ts +30 -0
  110. package/esm/util/fence.d.ts.map +1 -0
  111. package/esm/util/fence.js +40 -0
  112. package/esm/validator/attributes.d.ts +3 -3
  113. package/esm/validator/attributes.d.ts.map +1 -1
  114. package/esm/validator/attributes.js +1 -18
  115. package/esm/validator/body_blocks.d.ts +38 -0
  116. package/esm/validator/body_blocks.d.ts.map +1 -0
  117. package/esm/validator/body_blocks.js +218 -0
  118. package/esm/validator/caption_convention.d.ts +29 -0
  119. package/esm/validator/caption_convention.d.ts.map +1 -0
  120. package/esm/validator/caption_convention.js +58 -0
  121. package/esm/validator/captions.d.ts +22 -0
  122. package/esm/validator/captions.d.ts.map +1 -0
  123. package/esm/validator/captions.js +137 -0
  124. package/esm/validator/component_schemes.d.ts +73 -0
  125. package/esm/validator/component_schemes.d.ts.map +1 -0
  126. package/esm/validator/component_schemes.js +375 -0
  127. package/esm/validator/feature_ac.d.ts +28 -0
  128. package/esm/validator/feature_ac.d.ts.map +1 -0
  129. package/esm/validator/feature_ac.js +102 -0
  130. package/esm/validator/listing.d.ts +42 -0
  131. package/esm/validator/listing.d.ts.map +1 -0
  132. package/esm/validator/listing.js +295 -0
  133. package/esm/validator/mod.d.ts +2 -0
  134. package/esm/validator/mod.d.ts.map +1 -1
  135. package/esm/validator/mod.js +253 -12
  136. package/esm/validator/modal_keywords.d.ts +23 -0
  137. package/esm/validator/modal_keywords.d.ts.map +1 -0
  138. package/esm/validator/modal_keywords.js +137 -0
  139. package/esm/validator/per_type_attrs.d.ts +29 -0
  140. package/esm/validator/per_type_attrs.d.ts.map +1 -0
  141. package/esm/validator/per_type_attrs.js +75 -0
  142. package/esm/validator/pipeline.d.ts +7 -2
  143. package/esm/validator/pipeline.d.ts.map +1 -1
  144. package/esm/validator/pipeline.js +40 -7
  145. package/esm/validator/trace_types.d.ts +26 -0
  146. package/esm/validator/trace_types.d.ts.map +1 -0
  147. package/esm/validator/trace_types.js +232 -0
  148. package/esm/validator/traceability.d.ts +3 -4
  149. package/esm/validator/traceability.d.ts.map +1 -1
  150. package/esm/validator/traceability.js +5 -10
  151. package/esm/validator/type_resolution.d.ts +67 -0
  152. package/esm/validator/type_resolution.d.ts.map +1 -0
  153. package/esm/validator/type_resolution.js +140 -0
  154. package/esm/validator/types.d.ts +45 -0
  155. package/esm/validator/types.d.ts.map +1 -1
  156. package/esm/validator/types.js +128 -16
  157. package/esm/validator/value_types.d.ts +8 -0
  158. package/esm/validator/value_types.d.ts.map +1 -1
  159. package/esm/validator/value_types.js +8 -1
  160. package/package.json +1 -1
  161. package/script/ast/build.d.ts +70 -0
  162. package/script/ast/build.d.ts.map +1 -0
  163. package/script/ast/build.js +610 -0
  164. package/script/ast/equivalence.d.ts +18 -0
  165. package/script/ast/equivalence.d.ts.map +1 -0
  166. package/script/ast/equivalence.js +59 -0
  167. package/script/ast/nodes.d.ts +221 -0
  168. package/script/ast/nodes.d.ts.map +1 -0
  169. package/script/ast/nodes.js +13 -0
  170. package/script/ast/normalize.d.ts +67 -0
  171. package/script/ast/normalize.d.ts.map +1 -0
  172. package/script/ast/normalize.js +258 -0
  173. package/script/ast/render.d.ts +34 -0
  174. package/script/ast/render.d.ts.map +1 -0
  175. package/script/ast/render.js +218 -0
  176. package/script/compiler/inverses.d.ts +2 -8
  177. package/script/compiler/inverses.d.ts.map +1 -1
  178. package/script/compiler/inverses.js +50 -14
  179. package/script/compiler/manifest.d.ts +59 -0
  180. package/script/compiler/manifest.d.ts.map +1 -0
  181. package/script/compiler/manifest.js +51 -0
  182. package/script/compiler/mod.d.ts +9 -1
  183. package/script/compiler/mod.d.ts.map +1 -1
  184. package/script/compiler/mod.js +21 -2
  185. package/script/compiler/ndjson_writer.d.ts +50 -0
  186. package/script/compiler/ndjson_writer.d.ts.map +1 -0
  187. package/script/compiler/ndjson_writer.js +78 -0
  188. package/script/compiler/schema.d.ts +18 -1
  189. package/script/compiler/schema.d.ts.map +1 -1
  190. package/script/compiler/schema.js +18 -8
  191. package/script/config/mod.d.ts.map +1 -1
  192. package/script/config/mod.js +54 -0
  193. package/script/formatter/mod.d.ts +49 -4
  194. package/script/formatter/mod.d.ts.map +1 -1
  195. package/script/formatter/mod.js +365 -33
  196. package/script/formatter/synth_ulid.d.ts +21 -0
  197. package/script/formatter/synth_ulid.d.ts.map +1 -0
  198. package/script/formatter/synth_ulid.js +67 -0
  199. package/script/lint/mod.d.ts +10 -0
  200. package/script/lint/mod.d.ts.map +1 -0
  201. package/script/lint/mod.js +12 -0
  202. package/script/lint/rules/lexicon.d.ts +24 -0
  203. package/script/lint/rules/lexicon.d.ts.map +1 -0
  204. package/script/lint/rules/lexicon.js +240 -0
  205. package/script/lint/rules/struct.d.ts +17 -0
  206. package/script/lint/rules/struct.d.ts.map +1 -0
  207. package/script/lint/rules/struct.js +59 -0
  208. package/script/lint/rules/suppression.d.ts +19 -0
  209. package/script/lint/rules/suppression.d.ts.map +1 -0
  210. package/script/lint/rules/suppression.js +80 -0
  211. package/script/lint/runner.d.ts +39 -0
  212. package/script/lint/runner.d.ts.map +1 -0
  213. package/script/lint/runner.js +116 -0
  214. package/script/lint/types.d.ts +19 -0
  215. package/script/lint/types.d.ts.map +1 -0
  216. package/script/lint/types.js +10 -0
  217. package/script/mod.d.ts +19 -6
  218. package/script/mod.d.ts.map +1 -1
  219. package/script/mod.js +56 -32
  220. package/script/model/attributes.d.ts.map +1 -1
  221. package/script/model/attributes.js +163 -2
  222. package/script/model/discriminating_attr.d.ts +33 -0
  223. package/script/model/discriminating_attr.d.ts.map +1 -0
  224. package/script/model/discriminating_attr.js +77 -0
  225. package/script/model/mod.d.ts +98 -3
  226. package/script/model/mod.d.ts.map +1 -1
  227. package/script/model/mod.js +64 -3
  228. package/script/model/profile.d.ts +33 -27
  229. package/script/model/profile.d.ts.map +1 -1
  230. package/script/model/source_introspection.d.ts +26 -0
  231. package/script/model/source_introspection.d.ts.map +1 -0
  232. package/script/model/source_introspection.js +80 -0
  233. package/script/model/type_hierarchy.d.ts +51 -0
  234. package/script/model/type_hierarchy.d.ts.map +1 -0
  235. package/script/model/type_hierarchy.js +130 -0
  236. package/script/model/uri_scheme_map.d.ts +21 -0
  237. package/script/model/uri_scheme_map.d.ts.map +1 -0
  238. package/script/model/uri_scheme_map.js +69 -0
  239. package/script/parser/attributes.d.ts.map +1 -1
  240. package/script/parser/attributes.js +9 -6
  241. package/script/parser/entity_refs.d.ts +53 -0
  242. package/script/parser/entity_refs.d.ts.map +1 -0
  243. package/script/parser/entity_refs.js +155 -0
  244. package/script/parser/glossary.d.ts +43 -0
  245. package/script/parser/glossary.d.ts.map +1 -0
  246. package/script/parser/glossary.js +221 -0
  247. package/script/parser/markdown.d.ts.map +1 -1
  248. package/script/parser/markdown.js +222 -6
  249. package/script/parser/mod.d.ts +1 -0
  250. package/script/parser/mod.d.ts.map +1 -1
  251. package/script/parser/mod.js +5 -1
  252. package/script/parser/source.d.ts +20 -0
  253. package/script/parser/source.d.ts.map +1 -1
  254. package/script/parser/source.js +3 -0
  255. package/script/profile/chain.js +3 -13
  256. package/script/profile/colors.js +1 -1
  257. package/script/profile/introspect.d.ts +135 -0
  258. package/script/profile/introspect.d.ts.map +1 -0
  259. package/script/profile/introspect.js +381 -0
  260. package/script/profile/load.d.ts.map +1 -1
  261. package/script/profile/load.js +67 -0
  262. package/script/profile/manifest.d.ts.map +1 -1
  263. package/script/profile/manifest.js +276 -87
  264. package/script/profile/merge.js +139 -39
  265. package/script/profile/mod.d.ts +2 -4
  266. package/script/profile/mod.d.ts.map +1 -1
  267. package/script/profile/mod.js +7 -6
  268. package/script/reporter/mod.js +4 -4
  269. package/script/util/fence.d.ts +30 -0
  270. package/script/util/fence.d.ts.map +1 -0
  271. package/script/util/fence.js +44 -0
  272. package/script/validator/attributes.d.ts +3 -3
  273. package/script/validator/attributes.d.ts.map +1 -1
  274. package/script/validator/attributes.js +1 -18
  275. package/script/validator/body_blocks.d.ts +38 -0
  276. package/script/validator/body_blocks.d.ts.map +1 -0
  277. package/script/validator/body_blocks.js +221 -0
  278. package/script/validator/caption_convention.d.ts +29 -0
  279. package/script/validator/caption_convention.d.ts.map +1 -0
  280. package/script/validator/caption_convention.js +61 -0
  281. package/script/validator/captions.d.ts +22 -0
  282. package/script/validator/captions.d.ts.map +1 -0
  283. package/script/validator/captions.js +140 -0
  284. package/script/validator/component_schemes.d.ts +73 -0
  285. package/script/validator/component_schemes.d.ts.map +1 -0
  286. package/script/validator/component_schemes.js +384 -0
  287. package/script/validator/feature_ac.d.ts +28 -0
  288. package/script/validator/feature_ac.d.ts.map +1 -0
  289. package/script/validator/feature_ac.js +105 -0
  290. package/script/validator/listing.d.ts +42 -0
  291. package/script/validator/listing.d.ts.map +1 -0
  292. package/script/validator/listing.js +298 -0
  293. package/script/validator/mod.d.ts +2 -0
  294. package/script/validator/mod.d.ts.map +1 -1
  295. package/script/validator/mod.js +256 -14
  296. package/script/validator/modal_keywords.d.ts +23 -0
  297. package/script/validator/modal_keywords.d.ts.map +1 -0
  298. package/script/validator/modal_keywords.js +140 -0
  299. package/script/validator/per_type_attrs.d.ts +29 -0
  300. package/script/validator/per_type_attrs.d.ts.map +1 -0
  301. package/script/validator/per_type_attrs.js +78 -0
  302. package/script/validator/pipeline.d.ts +7 -2
  303. package/script/validator/pipeline.d.ts.map +1 -1
  304. package/script/validator/pipeline.js +39 -6
  305. package/script/validator/trace_types.d.ts +26 -0
  306. package/script/validator/trace_types.d.ts.map +1 -0
  307. package/script/validator/trace_types.js +235 -0
  308. package/script/validator/traceability.d.ts +3 -4
  309. package/script/validator/traceability.d.ts.map +1 -1
  310. package/script/validator/traceability.js +5 -10
  311. package/script/validator/type_resolution.d.ts +67 -0
  312. package/script/validator/type_resolution.d.ts.map +1 -0
  313. package/script/validator/type_resolution.js +146 -0
  314. package/script/validator/types.d.ts +45 -0
  315. package/script/validator/types.d.ts.map +1 -1
  316. package/script/validator/types.js +131 -16
  317. package/script/validator/value_types.d.ts +8 -0
  318. package/script/validator/value_types.d.ts.map +1 -1
  319. package/script/validator/value_types.js +10 -2
@@ -0,0 +1,218 @@
1
+ /**
2
+ * @module core/validator/body_blocks
3
+ *
4
+ * Body-block exclusion validator (spec §2.4.1). Detects constructs
5
+ * forbidden inside entry bodies:
6
+ *
7
+ * - MSL-B040 — headings
8
+ * - MSL-B041 — horizontal rules
9
+ * - MSL-B042 — task lists
10
+ * - MSL-B043 — raw HTML other than `<!-- markspec:* -->` directive
11
+ * comments
12
+ *
13
+ * Each excluded construct maps to a distinct AST node kind or property:
14
+ *
15
+ * - Headings → `UnknownNode` with `subkind: "heading"`
16
+ * - HR → `UnknownNode` with `subkind: "thematic-break"`
17
+ * - Task list → `ListNode` with `hasTaskItems: true`
18
+ * - Block HTML → `UnknownNode` with `subkind: "html"` (raw checked for
19
+ * the markspec-directive carve-out)
20
+ * - Inline HTML — remains inside `ParagraphNode.content.text` (remark
21
+ * does not extract inline HTML nodes into block-level nodes); each
22
+ * paragraph's text is scanned line-by-line using the same regex
23
+ * approach as the old walkProseLines path, but bounded to prose-only
24
+ * nodes (code/feature/math blocks are automatically excluded because
25
+ * the builder does not emit prose-bearing nodes for verbatim content).
26
+ *
27
+ * Code, Feature, and Math blocks are automatically excluded because the
28
+ * builder emits opaque nodes for verbatim content — no prose text to scan.
29
+ */
30
+ /**
31
+ * HTML tag detection. Matches an opening, closing, or self-closing tag
32
+ * (`<tag>`, `</tag>`, `<tag/>`). Doesn't match HTML comments — those
33
+ * are handled by {@linkcode HTML_COMMENT_RE} below so we can allow
34
+ * markspec directive comments while still flagging arbitrary HTML
35
+ * comments (which spec §2.4.1 forbids).
36
+ */
37
+ const HTML_TAG_RE = /<\/?[A-Za-z][A-Za-z0-9]*(\s[^>]*)?\/?>/;
38
+ /** Any HTML comment, `<!--…-->`. */
39
+ const HTML_COMMENT_RE = /<!--[\s\S]*?-->/;
40
+ /**
41
+ * A whole-line markspec directive comment: `<!-- markspec:<rest> -->`
42
+ * occupying the line on its own (optional leading/trailing
43
+ * whitespace). The directive form is the one exception spec §2.4.1
44
+ * carves out from the "no raw HTML" rule.
45
+ */
46
+ const MARKSPEC_DIRECTIVE_LINE_RE = /^\s*<!--\s*markspec:[\s\S]*?-->\s*$/;
47
+ /**
48
+ * Return `true` when `line` contains raw HTML the body model forbids:
49
+ * any tag, or any comment that isn't a standalone markspec directive.
50
+ */
51
+ function hasForbiddenHtml(line) {
52
+ if (HTML_TAG_RE.test(line))
53
+ return true;
54
+ if (HTML_COMMENT_RE.test(line) && !MARKSPEC_DIRECTIVE_LINE_RE.test(line)) {
55
+ return true;
56
+ }
57
+ return false;
58
+ }
59
+ const HEADING_DIAG = {
60
+ code: "MSL-B040",
61
+ severity: "error",
62
+ summary: "heading inside entry body — entries are flat (spec §2.4.1)",
63
+ };
64
+ const HR_DIAG = {
65
+ code: "MSL-B041",
66
+ severity: "error",
67
+ summary: "horizontal rule inside entry body — entry boundaries already separate content (spec §2.4.1)",
68
+ };
69
+ const TASK_LIST_DIAG = {
70
+ code: "MSL-B042",
71
+ severity: "error",
72
+ summary: "task list inside entry body — semantics conflict with traceability state (spec §2.4.1)",
73
+ };
74
+ const RAW_HTML_DIAG = {
75
+ code: "MSL-B043",
76
+ severity: "error",
77
+ summary: "raw HTML inside entry body — only `<!-- markspec:* -->` directive comments are permitted (spec §2.4.1)",
78
+ };
79
+ /**
80
+ * Scan `text` line-by-line for forbidden inline HTML, starting at
81
+ * `startLine` (1-based body-relative). Returns one `{ diag, bodyLine }`
82
+ * pair per violating line — the same shape returned by
83
+ * {@linkcode violationsFromBlock}.
84
+ *
85
+ * Each branch in `violationsFromBlock` that checks for inline HTML
86
+ * supplies its own `text` source (prose text for paragraph/note/blockquote,
87
+ * verbatim raw source for table) and its own `startLine` anchor; this
88
+ * helper factors the shared scan loop while preserving per-branch inputs.
89
+ */
90
+ function htmlViolations(text, startLine) {
91
+ const out = [];
92
+ const lines = text.split("\n");
93
+ for (let li = 0; li < lines.length; li++) {
94
+ const line = lines[li];
95
+ if (line.trim() === "")
96
+ continue;
97
+ if (hasForbiddenHtml(line)) {
98
+ out.push({ diag: RAW_HTML_DIAG, bodyLine: startLine + li });
99
+ }
100
+ }
101
+ return out;
102
+ }
103
+ // ---------------------------------------------------------------------------
104
+ // AST-based exclusion walker
105
+ // ---------------------------------------------------------------------------
106
+ /**
107
+ * Collect body-block exclusion violations from a single BodyBlock.
108
+ * Returns an array of `{ diag, bodyLine }` pairs where `bodyLine` is the
109
+ * 1-based body-relative line number of the violation (maps to file line via
110
+ * `entry.location.line + bodyLine`).
111
+ */
112
+ function violationsFromBlock(block) {
113
+ const out = [];
114
+ switch (block.kind) {
115
+ case "unknown": {
116
+ const bodyLine = block.range.start.line;
117
+ if (block.subkind === "heading") {
118
+ out.push({ diag: HEADING_DIAG, bodyLine });
119
+ }
120
+ else if (block.subkind === "thematic-break") {
121
+ out.push({ diag: HR_DIAG, bodyLine });
122
+ }
123
+ else if (block.subkind === "html") {
124
+ // Block-level HTML: check if it is a markspec directive (exempt)
125
+ // or forbidden HTML. The `raw` field carries the verbatim source.
126
+ if (!MARKSPEC_DIRECTIVE_LINE_RE.test(block.raw)) {
127
+ out.push({ diag: RAW_HTML_DIAG, bodyLine });
128
+ }
129
+ }
130
+ break;
131
+ }
132
+ case "list": {
133
+ if (block.hasTaskItems) {
134
+ out.push({ diag: TASK_LIST_DIAG, bodyLine: block.range.start.line });
135
+ }
136
+ else {
137
+ // Non-task list: recurse into items to catch nested excluded blocks.
138
+ for (const item of block.items) {
139
+ for (const sub of item.blocks) {
140
+ out.push(...violationsFromBlock(sub));
141
+ }
142
+ }
143
+ }
144
+ break;
145
+ }
146
+ case "paragraph": {
147
+ // Inline HTML remains inside paragraph text (remark does not
148
+ // surface it as a separate block node). Scan each line of the
149
+ // paragraph's prose text for forbidden HTML.
150
+ out.push(...htmlViolations(block.content.text, block.range.start.line));
151
+ break;
152
+ }
153
+ // Prose-bearing nodes that are not forbidden — scan for inline HTML.
154
+ case "note":
155
+ case "blockquote": {
156
+ out.push(...htmlViolations(block.content.text, block.range.start.line));
157
+ break;
158
+ }
159
+ // Table cells may contain inline HTML.
160
+ case "table": {
161
+ // Tables are in-scope for HTML scanning but their cell text is
162
+ // structured. Scan the raw table source line-by-line instead,
163
+ // since the `raw` field contains the verbatim source and avoids
164
+ // needing to reconstruct cell content per-line. The raw field's
165
+ // line offsets start at `range.start.line`.
166
+ out.push(...htmlViolations(block.raw, block.range.start.line));
167
+ break;
168
+ }
169
+ case "definition-list": {
170
+ // Definition list items may contain inline HTML in term/definition.
171
+ for (const item of block.items) {
172
+ out.push(...htmlViolations(item.term.text, block.range.start.line));
173
+ out.push(...htmlViolations(item.definition.text, block.range.start.line));
174
+ }
175
+ break;
176
+ }
177
+ // Verbatim / structural nodes: no prose to scan.
178
+ case "code":
179
+ case "feature":
180
+ case "math":
181
+ case "figure":
182
+ case "caption":
183
+ break;
184
+ default:
185
+ break;
186
+ }
187
+ return out;
188
+ }
189
+ // ---------------------------------------------------------------------------
190
+ // Public API
191
+ // ---------------------------------------------------------------------------
192
+ /**
193
+ * Validate that an entry's body contains none of the excluded body
194
+ * constructs. Emits at most one diagnostic per excluded construct per
195
+ * line (so a paragraph with `<div>foo</div><span>bar</span>` still
196
+ * fires MSL-B043 once for that line).
197
+ */
198
+ export function validateBodyBlocks(entry) {
199
+ const diagnostics = [];
200
+ const blocks = entry.bodyAst ?? [];
201
+ for (const block of blocks) {
202
+ for (const { diag, bodyLine } of violationsFromBlock(block)) {
203
+ diagnostics.push({
204
+ code: diag.code,
205
+ severity: diag.severity,
206
+ message: `${entry.displayId}: ${diag.summary}`,
207
+ location: {
208
+ file: entry.location.file,
209
+ // bodyLine is 1-based body-relative. Body line 1 = file line
210
+ // entry.location.line + 1 (the line after the title).
211
+ line: entry.location.line + bodyLine,
212
+ column: 1,
213
+ },
214
+ });
215
+ }
216
+ }
217
+ return diagnostics;
218
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @module core/validator/caption_convention
3
+ *
4
+ * MSL-C072 validator — caption position violates project-configured
5
+ * convention (docs/specs/markspec-core-data-model.md §4.7).
6
+ *
7
+ * When `project.yaml` carries a `caption-conventions` map, each caption
8
+ * whose `position` disagrees with the configured position for its keyword
9
+ * fires MSL-C072 (warning). Keywords not present in the map are
10
+ * unconstrained and this validator is silent for them.
11
+ *
12
+ * If no conventions are configured (the map is empty or absent) the
13
+ * validator emits no diagnostics — the rule is inactive.
14
+ *
15
+ * This is an AST-only check: `CaptionNode.position` is set by the builder
16
+ * (`core/ast/build.ts`) from the source order of the caption relative to
17
+ * its captionable block.
18
+ */
19
+ import type { CaptionConventions, Diagnostic, Entry } from "../model/mod.js";
20
+ /**
21
+ * Validate caption positions against the project-configured conventions.
22
+ *
23
+ * @param entry - The entry whose body AST is scanned for captions.
24
+ * @param conventions - The configured position conventions from
25
+ * `ProjectConfig.captionConventions`. An empty record means no
26
+ * conventions are set and the function returns immediately.
27
+ */
28
+ export declare function validateCaptionConvention(entry: Entry, conventions: CaptionConventions): readonly Diagnostic[];
29
+ //# sourceMappingURL=caption_convention.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caption_convention.d.ts","sourceRoot":"","sources":["../../src/validator/caption_convention.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7E;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,kBAAkB,GAC9B,SAAS,UAAU,EAAE,CAmCvB"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @module core/validator/caption_convention
3
+ *
4
+ * MSL-C072 validator — caption position violates project-configured
5
+ * convention (docs/specs/markspec-core-data-model.md §4.7).
6
+ *
7
+ * When `project.yaml` carries a `caption-conventions` map, each caption
8
+ * whose `position` disagrees with the configured position for its keyword
9
+ * fires MSL-C072 (warning). Keywords not present in the map are
10
+ * unconstrained and this validator is silent for them.
11
+ *
12
+ * If no conventions are configured (the map is empty or absent) the
13
+ * validator emits no diagnostics — the rule is inactive.
14
+ *
15
+ * This is an AST-only check: `CaptionNode.position` is set by the builder
16
+ * (`core/ast/build.ts`) from the source order of the caption relative to
17
+ * its captionable block.
18
+ */
19
+ /**
20
+ * Validate caption positions against the project-configured conventions.
21
+ *
22
+ * @param entry - The entry whose body AST is scanned for captions.
23
+ * @param conventions - The configured position conventions from
24
+ * `ProjectConfig.captionConventions`. An empty record means no
25
+ * conventions are set and the function returns immediately.
26
+ */
27
+ export function validateCaptionConvention(entry, conventions) {
28
+ // Fast-path: no conventions configured → rule inactive.
29
+ if (Object.keys(conventions).length === 0)
30
+ return [];
31
+ const blocks = entry.bodyAst ?? [];
32
+ const diagnostics = [];
33
+ for (const block of blocks) {
34
+ if (block.kind !== "caption")
35
+ continue;
36
+ const expected = conventions[block.keyword];
37
+ // No convention configured for this keyword → skip.
38
+ if (expected === undefined)
39
+ continue;
40
+ // Convention is satisfied → no diagnostic.
41
+ if (block.position === expected)
42
+ continue;
43
+ const fileLine = entry.location.line + block.range.start.line;
44
+ diagnostics.push({
45
+ code: "MSL-C072",
46
+ severity: "warning",
47
+ message: `${entry.displayId}: ${block.keyword}: caption appears ${block.position} ` +
48
+ `its block but the project convention requires it to be ${expected} ` +
49
+ `(spec §4.7; configure under 'caption-conventions' in project.yaml)`,
50
+ location: {
51
+ file: entry.location.file,
52
+ line: fileLine,
53
+ column: 1,
54
+ },
55
+ });
56
+ }
57
+ return diagnostics;
58
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @module core/validator/captions
3
+ *
4
+ * Caption-adjacency validation per spec §2.6. Emits `MSL-C070` for
5
+ * orphaned captions (no captionable neighbour) and `MSL-C071` for
6
+ * wrong-type adjacency. The builder emits `CaptionNode` blocks with a
7
+ * `keyword` field (Figure, Table, etc.) and a `position` hint
8
+ * ("above"/"below"); the validator checks each caption against its
9
+ * nearest non-blank neighbour. Captions inside verbatim blocks are
10
+ * automatically excluded — the builder does not emit `CaptionNode`s for
11
+ * verbatim content. The "Listing or Feature" ambiguity (a fenced block
12
+ * without a lang tag is ambiguous) is preserved in the mismatch message.
13
+ */
14
+ import type { Diagnostic, Entry } from "../model/mod.js";
15
+ /**
16
+ * Validate caption adjacency for one entry. Emits `MSL-C070` for any
17
+ * caption whose nearest non-blank neighbour (above or below) is not a
18
+ * captionable block of the matching type, and `MSL-C071` when there is
19
+ * a captionable block of the *wrong* type adjacent.
20
+ */
21
+ export declare function validateCaptions(entry: Entry): readonly Diagnostic[];
22
+ //# sourceMappingURL=captions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"captions.d.ts","sourceRoot":"","sources":["../../src/validator/captions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAoDzD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,UAAU,EAAE,CAsFpE"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * @module core/validator/captions
3
+ *
4
+ * Caption-adjacency validation per spec §2.6. Emits `MSL-C070` for
5
+ * orphaned captions (no captionable neighbour) and `MSL-C071` for
6
+ * wrong-type adjacency. The builder emits `CaptionNode` blocks with a
7
+ * `keyword` field (Figure, Table, etc.) and a `position` hint
8
+ * ("above"/"below"); the validator checks each caption against its
9
+ * nearest non-blank neighbour. Captions inside verbatim blocks are
10
+ * automatically excluded — the builder does not emit `CaptionNode`s for
11
+ * verbatim content. The "Listing or Feature" ambiguity (a fenced block
12
+ * without a lang tag is ambiguous) is preserved in the mismatch message.
13
+ */
14
+ /** Caption keywords recognised by the core (spec §2.6). */
15
+ const CAPTION_KEYWORDS = [
16
+ "Figure",
17
+ "Table",
18
+ "Listing",
19
+ "Feature",
20
+ "Equation",
21
+ "List",
22
+ ];
23
+ // ---------------------------------------------------------------------------
24
+ // Block-type → caption-keyword classification
25
+ // ---------------------------------------------------------------------------
26
+ /**
27
+ * Map an AST block kind to the caption keyword whose captionable-block
28
+ * this block represents, or `undefined` when the block is not captionable
29
+ * (e.g. paragraph, unknown, note, blockquote, definition-list).
30
+ *
31
+ * `code` maps to `Listing` (first in the CAPTION_KEYWORDS order) — the
32
+ * ambiguity with `Feature`/Gherkin is handled by the caller which emits
33
+ * "Listing or Feature (fenced)" for `CodeNode`.
34
+ */
35
+ function blockKindToCaption(block) {
36
+ switch (block.kind) {
37
+ case "figure":
38
+ return "Figure";
39
+ case "table":
40
+ return "Table";
41
+ case "code":
42
+ return "Listing"; // possibly also Feature — ambiguous without lang tag
43
+ case "feature":
44
+ return "Feature";
45
+ case "math":
46
+ return "Equation";
47
+ case "list":
48
+ return "List";
49
+ default:
50
+ return undefined;
51
+ }
52
+ }
53
+ // ---------------------------------------------------------------------------
54
+ // Public API
55
+ // ---------------------------------------------------------------------------
56
+ /**
57
+ * Validate caption adjacency for one entry. Emits `MSL-C070` for any
58
+ * caption whose nearest non-blank neighbour (above or below) is not a
59
+ * captionable block of the matching type, and `MSL-C071` when there is
60
+ * a captionable block of the *wrong* type adjacent.
61
+ */
62
+ export function validateCaptions(entry) {
63
+ const diagnostics = [];
64
+ const blocks = entry.bodyAst ?? [];
65
+ for (let i = 0; i < blocks.length; i++) {
66
+ const block = blocks[i];
67
+ if (block.kind !== "caption")
68
+ continue;
69
+ const keyword = block.keyword; // safe: CaptionNode.keyword and CaptionKeyword are the same 6-string set
70
+ // Immediate preceding block (no caption-skipping — a CaptionNode
71
+ // neighbour is not a captionable block, matching baseline semantics).
72
+ const prevIdx = i - 1;
73
+ const prevBlock = prevIdx >= 0 ? blocks[prevIdx] : undefined;
74
+ // Immediate following block (no caption-skipping — same rationale).
75
+ const nextIdx = i + 1;
76
+ const nextBlock = nextIdx < blocks.length ? blocks[nextIdx] : undefined;
77
+ // Check if either neighbour is a captionable block of the matching type.
78
+ const prevKind = prevBlock ? blockKindToCaption(prevBlock) : undefined;
79
+ const nextKind = nextBlock ? blockKindToCaption(nextBlock) : undefined;
80
+ // A `CodeNode` may be either Listing or Feature (Gherkin) — both
81
+ // `blockKindToCaption` returns "Listing" for `code`, so a `Feature:`
82
+ // caption below a `CodeNode` block is considered matching (the
83
+ // closing fence has no lang tag; we can't distinguish at this point).
84
+ const prevMatches = prevBlock !== undefined &&
85
+ (prevKind === keyword ||
86
+ (keyword === "Feature" && prevBlock.kind === "code") ||
87
+ (keyword === "Listing" && prevBlock.kind === "feature"));
88
+ const nextMatches = nextBlock !== undefined &&
89
+ (nextKind === keyword ||
90
+ (keyword === "Feature" && nextBlock.kind === "code") ||
91
+ (keyword === "Listing" && nextBlock.kind === "feature"));
92
+ if (prevMatches || nextMatches) {
93
+ // Adjacent to a matching captionable block — valid.
94
+ continue;
95
+ }
96
+ // No matching block adjacent. Decide between C070 (orphan) and C071
97
+ // (wrong-type adjacency).
98
+ const mismatchKind = prevKind ?? nextKind;
99
+ const mismatchBlock = mismatchKind !== undefined
100
+ ? (prevKind !== undefined ? prevBlock : nextBlock)
101
+ : undefined;
102
+ // File line: body-relative 1-based start line → entry.location.line + bodyLine
103
+ const fileLine = entry.location.line + block.range.start.line;
104
+ if (mismatchKind !== undefined && mismatchBlock !== undefined) {
105
+ // Listing and Feature share a fence-only matcher — a CodeNode or
106
+ // FeatureNode is ambiguous without the opening fence's language tag.
107
+ const mismatchLabel = mismatchBlock.kind === "code" || mismatchBlock.kind === "feature"
108
+ ? "Listing or Feature (fenced)"
109
+ : mismatchKind;
110
+ diagnostics.push({
111
+ code: "MSL-C071",
112
+ severity: "error",
113
+ message: `${entry.displayId}: ${keyword}: caption is adjacent to a ` +
114
+ `${mismatchLabel} block, not a ${keyword} block (spec §4.7)`,
115
+ location: {
116
+ file: entry.location.file,
117
+ line: fileLine,
118
+ column: 1,
119
+ },
120
+ });
121
+ }
122
+ else {
123
+ diagnostics.push({
124
+ code: "MSL-C070",
125
+ severity: "error",
126
+ message: `${entry.displayId}: ${keyword}: caption is not adjacent to a ` +
127
+ `captionable block of type ${keyword}`,
128
+ location: {
129
+ file: entry.location.file,
130
+ line: fileLine,
131
+ column: 1,
132
+ },
133
+ });
134
+ }
135
+ }
136
+ return diagnostics;
137
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @module validator/component_schemes
3
+ *
4
+ * Component Id-scheme parsers for `markspec:components` listings.
5
+ *
6
+ * Each exported parser accepts a raw `Id:` URI string and returns either
7
+ * `{ ok: true, type: string }` (accepted, with the inferred Item type) or
8
+ * `{ ok: false, code: "MSL-Lxxx", message: string }` (rejected with a
9
+ * specific diagnostic code). Parsers are pure: no I/O, no external fetches.
10
+ *
11
+ * Spec §5 fixes the grammars; this module is their TypeScript implementation.
12
+ */
13
+ /** Result from a component scheme parser. */
14
+ export type SchemeParseResult = {
15
+ readonly ok: true;
16
+ readonly type: string;
17
+ } | {
18
+ readonly ok: false;
19
+ readonly code: string;
20
+ readonly message: string;
21
+ };
22
+ /** Guard: does the Id: value look like a URI for a known or generic scheme? */
23
+ export declare function isSchemeQualifiedUri(value: string): boolean;
24
+ /**
25
+ * Parse a `pkg:` URI per the Package URL specification.
26
+ *
27
+ * Validates: scheme is "pkg", type and name are non-empty, subpath
28
+ * presence → SoftwareUnit. Accepts any well-formed purl and classifies it;
29
+ * rejects malformed purls with MSL-L031.
30
+ */
31
+ export declare function parsePurl(value: string): SchemeParseResult;
32
+ /**
33
+ * Parse a `mfg:vendor:partno` URI per spec §5.2.
34
+ *
35
+ * Rules: literal "mfg:" prefix, non-empty vendor token, ":", non-empty
36
+ * partno (may contain further ":"). Invalid → MSL-L032.
37
+ */
38
+ export declare function parseMfgId(value: string): SchemeParseResult;
39
+ /**
40
+ * Parse a `gtin:` URI per spec §5.3 and GS1 General Specifications.
41
+ *
42
+ * Validates: exactly 8/12/13/14 digits, correct GS1 check digit.
43
+ * Errors: MSL-L033 (wrong length), MSL-L034 (bad check digit).
44
+ */
45
+ export declare function parseGtinId(value: string): SchemeParseResult;
46
+ /**
47
+ * Parse a `cpe:` URI per spec §5.4 and NIST IR 7695.
48
+ *
49
+ * Accepts only the CPE 2.3 formatted-string binding (`cpe:2.3:…`).
50
+ * Errors: MSL-L035 (legacy 2.2 URI binding), MSL-L036 (invalid part).
51
+ */
52
+ export declare function parseCpeId(value: string): SchemeParseResult;
53
+ /**
54
+ * Parse a `urn:system:` or `urn:tool:` URI per spec §5.5.
55
+ *
56
+ * Validates: non-empty segments separated by ":", all chars in
57
+ * ALPHA/DIGIT/-/./_ . Invalid → MSL-L037.
58
+ */
59
+ export declare function parseUrnSystemOrTool(value: string): SchemeParseResult;
60
+ /**
61
+ * Classify a component entry's `Id:` value against the six core schemes.
62
+ *
63
+ * Returns a {@linkcode SchemeParseResult}:
64
+ * - `{ ok: true, type }` on recognition (may still emit MSL-L030 for
65
+ * unknown purl types — the caller handles that).
66
+ * - `{ ok: false, code, message }` for scheme-level parse errors.
67
+ * - `null` when the value doesn't look like any component scheme (caller
68
+ * should check if it's a valid RFC 3986 URI for the generic fallback).
69
+ *
70
+ * Matching is longest-declared-prefix-wins per spec §5.
71
+ */
72
+ export declare function parseComponentScheme(value: string): SchemeParseResult | null;
73
+ //# sourceMappingURL=component_schemes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component_schemes.d.ts","sourceRoot":"","sources":["../../src/validator/component_schemes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,6CAA6C;AAC7C,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,+EAA+E;AAC/E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE3D;AAwBD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAyE1D;AASD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAmE3D;AAyBD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CA0C5D;AAQD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAuD3D;AASD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CA8CrE;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAS5E"}