@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,221 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/validator/body_blocks
4
+ *
5
+ * Body-block exclusion validator (spec §2.4.1). Detects constructs
6
+ * forbidden inside entry bodies:
7
+ *
8
+ * - MSL-B040 — headings
9
+ * - MSL-B041 — horizontal rules
10
+ * - MSL-B042 — task lists
11
+ * - MSL-B043 — raw HTML other than `<!-- markspec:* -->` directive
12
+ * comments
13
+ *
14
+ * Each excluded construct maps to a distinct AST node kind or property:
15
+ *
16
+ * - Headings → `UnknownNode` with `subkind: "heading"`
17
+ * - HR → `UnknownNode` with `subkind: "thematic-break"`
18
+ * - Task list → `ListNode` with `hasTaskItems: true`
19
+ * - Block HTML → `UnknownNode` with `subkind: "html"` (raw checked for
20
+ * the markspec-directive carve-out)
21
+ * - Inline HTML — remains inside `ParagraphNode.content.text` (remark
22
+ * does not extract inline HTML nodes into block-level nodes); each
23
+ * paragraph's text is scanned line-by-line using the same regex
24
+ * approach as the old walkProseLines path, but bounded to prose-only
25
+ * nodes (code/feature/math blocks are automatically excluded because
26
+ * the builder does not emit prose-bearing nodes for verbatim content).
27
+ *
28
+ * Code, Feature, and Math blocks are automatically excluded because the
29
+ * builder emits opaque nodes for verbatim content — no prose text to scan.
30
+ */
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.validateBodyBlocks = validateBodyBlocks;
33
+ /**
34
+ * HTML tag detection. Matches an opening, closing, or self-closing tag
35
+ * (`<tag>`, `</tag>`, `<tag/>`). Doesn't match HTML comments — those
36
+ * are handled by {@linkcode HTML_COMMENT_RE} below so we can allow
37
+ * markspec directive comments while still flagging arbitrary HTML
38
+ * comments (which spec §2.4.1 forbids).
39
+ */
40
+ const HTML_TAG_RE = /<\/?[A-Za-z][A-Za-z0-9]*(\s[^>]*)?\/?>/;
41
+ /** Any HTML comment, `<!--…-->`. */
42
+ const HTML_COMMENT_RE = /<!--[\s\S]*?-->/;
43
+ /**
44
+ * A whole-line markspec directive comment: `<!-- markspec:<rest> -->`
45
+ * occupying the line on its own (optional leading/trailing
46
+ * whitespace). The directive form is the one exception spec §2.4.1
47
+ * carves out from the "no raw HTML" rule.
48
+ */
49
+ const MARKSPEC_DIRECTIVE_LINE_RE = /^\s*<!--\s*markspec:[\s\S]*?-->\s*$/;
50
+ /**
51
+ * Return `true` when `line` contains raw HTML the body model forbids:
52
+ * any tag, or any comment that isn't a standalone markspec directive.
53
+ */
54
+ function hasForbiddenHtml(line) {
55
+ if (HTML_TAG_RE.test(line))
56
+ return true;
57
+ if (HTML_COMMENT_RE.test(line) && !MARKSPEC_DIRECTIVE_LINE_RE.test(line)) {
58
+ return true;
59
+ }
60
+ return false;
61
+ }
62
+ const HEADING_DIAG = {
63
+ code: "MSL-B040",
64
+ severity: "error",
65
+ summary: "heading inside entry body — entries are flat (spec §2.4.1)",
66
+ };
67
+ const HR_DIAG = {
68
+ code: "MSL-B041",
69
+ severity: "error",
70
+ summary: "horizontal rule inside entry body — entry boundaries already separate content (spec §2.4.1)",
71
+ };
72
+ const TASK_LIST_DIAG = {
73
+ code: "MSL-B042",
74
+ severity: "error",
75
+ summary: "task list inside entry body — semantics conflict with traceability state (spec §2.4.1)",
76
+ };
77
+ const RAW_HTML_DIAG = {
78
+ code: "MSL-B043",
79
+ severity: "error",
80
+ summary: "raw HTML inside entry body — only `<!-- markspec:* -->` directive comments are permitted (spec §2.4.1)",
81
+ };
82
+ /**
83
+ * Scan `text` line-by-line for forbidden inline HTML, starting at
84
+ * `startLine` (1-based body-relative). Returns one `{ diag, bodyLine }`
85
+ * pair per violating line — the same shape returned by
86
+ * {@linkcode violationsFromBlock}.
87
+ *
88
+ * Each branch in `violationsFromBlock` that checks for inline HTML
89
+ * supplies its own `text` source (prose text for paragraph/note/blockquote,
90
+ * verbatim raw source for table) and its own `startLine` anchor; this
91
+ * helper factors the shared scan loop while preserving per-branch inputs.
92
+ */
93
+ function htmlViolations(text, startLine) {
94
+ const out = [];
95
+ const lines = text.split("\n");
96
+ for (let li = 0; li < lines.length; li++) {
97
+ const line = lines[li];
98
+ if (line.trim() === "")
99
+ continue;
100
+ if (hasForbiddenHtml(line)) {
101
+ out.push({ diag: RAW_HTML_DIAG, bodyLine: startLine + li });
102
+ }
103
+ }
104
+ return out;
105
+ }
106
+ // ---------------------------------------------------------------------------
107
+ // AST-based exclusion walker
108
+ // ---------------------------------------------------------------------------
109
+ /**
110
+ * Collect body-block exclusion violations from a single BodyBlock.
111
+ * Returns an array of `{ diag, bodyLine }` pairs where `bodyLine` is the
112
+ * 1-based body-relative line number of the violation (maps to file line via
113
+ * `entry.location.line + bodyLine`).
114
+ */
115
+ function violationsFromBlock(block) {
116
+ const out = [];
117
+ switch (block.kind) {
118
+ case "unknown": {
119
+ const bodyLine = block.range.start.line;
120
+ if (block.subkind === "heading") {
121
+ out.push({ diag: HEADING_DIAG, bodyLine });
122
+ }
123
+ else if (block.subkind === "thematic-break") {
124
+ out.push({ diag: HR_DIAG, bodyLine });
125
+ }
126
+ else if (block.subkind === "html") {
127
+ // Block-level HTML: check if it is a markspec directive (exempt)
128
+ // or forbidden HTML. The `raw` field carries the verbatim source.
129
+ if (!MARKSPEC_DIRECTIVE_LINE_RE.test(block.raw)) {
130
+ out.push({ diag: RAW_HTML_DIAG, bodyLine });
131
+ }
132
+ }
133
+ break;
134
+ }
135
+ case "list": {
136
+ if (block.hasTaskItems) {
137
+ out.push({ diag: TASK_LIST_DIAG, bodyLine: block.range.start.line });
138
+ }
139
+ else {
140
+ // Non-task list: recurse into items to catch nested excluded blocks.
141
+ for (const item of block.items) {
142
+ for (const sub of item.blocks) {
143
+ out.push(...violationsFromBlock(sub));
144
+ }
145
+ }
146
+ }
147
+ break;
148
+ }
149
+ case "paragraph": {
150
+ // Inline HTML remains inside paragraph text (remark does not
151
+ // surface it as a separate block node). Scan each line of the
152
+ // paragraph's prose text for forbidden HTML.
153
+ out.push(...htmlViolations(block.content.text, block.range.start.line));
154
+ break;
155
+ }
156
+ // Prose-bearing nodes that are not forbidden — scan for inline HTML.
157
+ case "note":
158
+ case "blockquote": {
159
+ out.push(...htmlViolations(block.content.text, block.range.start.line));
160
+ break;
161
+ }
162
+ // Table cells may contain inline HTML.
163
+ case "table": {
164
+ // Tables are in-scope for HTML scanning but their cell text is
165
+ // structured. Scan the raw table source line-by-line instead,
166
+ // since the `raw` field contains the verbatim source and avoids
167
+ // needing to reconstruct cell content per-line. The raw field's
168
+ // line offsets start at `range.start.line`.
169
+ out.push(...htmlViolations(block.raw, block.range.start.line));
170
+ break;
171
+ }
172
+ case "definition-list": {
173
+ // Definition list items may contain inline HTML in term/definition.
174
+ for (const item of block.items) {
175
+ out.push(...htmlViolations(item.term.text, block.range.start.line));
176
+ out.push(...htmlViolations(item.definition.text, block.range.start.line));
177
+ }
178
+ break;
179
+ }
180
+ // Verbatim / structural nodes: no prose to scan.
181
+ case "code":
182
+ case "feature":
183
+ case "math":
184
+ case "figure":
185
+ case "caption":
186
+ break;
187
+ default:
188
+ break;
189
+ }
190
+ return out;
191
+ }
192
+ // ---------------------------------------------------------------------------
193
+ // Public API
194
+ // ---------------------------------------------------------------------------
195
+ /**
196
+ * Validate that an entry's body contains none of the excluded body
197
+ * constructs. Emits at most one diagnostic per excluded construct per
198
+ * line (so a paragraph with `<div>foo</div><span>bar</span>` still
199
+ * fires MSL-B043 once for that line).
200
+ */
201
+ function validateBodyBlocks(entry) {
202
+ const diagnostics = [];
203
+ const blocks = entry.bodyAst ?? [];
204
+ for (const block of blocks) {
205
+ for (const { diag, bodyLine } of violationsFromBlock(block)) {
206
+ diagnostics.push({
207
+ code: diag.code,
208
+ severity: diag.severity,
209
+ message: `${entry.displayId}: ${diag.summary}`,
210
+ location: {
211
+ file: entry.location.file,
212
+ // bodyLine is 1-based body-relative. Body line 1 = file line
213
+ // entry.location.line + 1 (the line after the title).
214
+ line: entry.location.line + bodyLine,
215
+ column: 1,
216
+ },
217
+ });
218
+ }
219
+ }
220
+ return diagnostics;
221
+ }
@@ -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,61 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/validator/caption_convention
4
+ *
5
+ * MSL-C072 validator — caption position violates project-configured
6
+ * convention (docs/specs/markspec-core-data-model.md §4.7).
7
+ *
8
+ * When `project.yaml` carries a `caption-conventions` map, each caption
9
+ * whose `position` disagrees with the configured position for its keyword
10
+ * fires MSL-C072 (warning). Keywords not present in the map are
11
+ * unconstrained and this validator is silent for them.
12
+ *
13
+ * If no conventions are configured (the map is empty or absent) the
14
+ * validator emits no diagnostics — the rule is inactive.
15
+ *
16
+ * This is an AST-only check: `CaptionNode.position` is set by the builder
17
+ * (`core/ast/build.ts`) from the source order of the caption relative to
18
+ * its captionable block.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.validateCaptionConvention = validateCaptionConvention;
22
+ /**
23
+ * Validate caption positions against the project-configured conventions.
24
+ *
25
+ * @param entry - The entry whose body AST is scanned for captions.
26
+ * @param conventions - The configured position conventions from
27
+ * `ProjectConfig.captionConventions`. An empty record means no
28
+ * conventions are set and the function returns immediately.
29
+ */
30
+ function validateCaptionConvention(entry, conventions) {
31
+ // Fast-path: no conventions configured → rule inactive.
32
+ if (Object.keys(conventions).length === 0)
33
+ return [];
34
+ const blocks = entry.bodyAst ?? [];
35
+ const diagnostics = [];
36
+ for (const block of blocks) {
37
+ if (block.kind !== "caption")
38
+ continue;
39
+ const expected = conventions[block.keyword];
40
+ // No convention configured for this keyword → skip.
41
+ if (expected === undefined)
42
+ continue;
43
+ // Convention is satisfied → no diagnostic.
44
+ if (block.position === expected)
45
+ continue;
46
+ const fileLine = entry.location.line + block.range.start.line;
47
+ diagnostics.push({
48
+ code: "MSL-C072",
49
+ severity: "warning",
50
+ message: `${entry.displayId}: ${block.keyword}: caption appears ${block.position} ` +
51
+ `its block but the project convention requires it to be ${expected} ` +
52
+ `(spec §4.7; configure under 'caption-conventions' in project.yaml)`,
53
+ location: {
54
+ file: entry.location.file,
55
+ line: fileLine,
56
+ column: 1,
57
+ },
58
+ });
59
+ }
60
+ return diagnostics;
61
+ }
@@ -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,140 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/validator/captions
4
+ *
5
+ * Caption-adjacency validation per spec §2.6. Emits `MSL-C070` for
6
+ * orphaned captions (no captionable neighbour) and `MSL-C071` for
7
+ * wrong-type adjacency. The builder emits `CaptionNode` blocks with a
8
+ * `keyword` field (Figure, Table, etc.) and a `position` hint
9
+ * ("above"/"below"); the validator checks each caption against its
10
+ * nearest non-blank neighbour. Captions inside verbatim blocks are
11
+ * automatically excluded — the builder does not emit `CaptionNode`s for
12
+ * verbatim content. The "Listing or Feature" ambiguity (a fenced block
13
+ * without a lang tag is ambiguous) is preserved in the mismatch message.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.validateCaptions = validateCaptions;
17
+ /** Caption keywords recognised by the core (spec §2.6). */
18
+ const CAPTION_KEYWORDS = [
19
+ "Figure",
20
+ "Table",
21
+ "Listing",
22
+ "Feature",
23
+ "Equation",
24
+ "List",
25
+ ];
26
+ // ---------------------------------------------------------------------------
27
+ // Block-type → caption-keyword classification
28
+ // ---------------------------------------------------------------------------
29
+ /**
30
+ * Map an AST block kind to the caption keyword whose captionable-block
31
+ * this block represents, or `undefined` when the block is not captionable
32
+ * (e.g. paragraph, unknown, note, blockquote, definition-list).
33
+ *
34
+ * `code` maps to `Listing` (first in the CAPTION_KEYWORDS order) — the
35
+ * ambiguity with `Feature`/Gherkin is handled by the caller which emits
36
+ * "Listing or Feature (fenced)" for `CodeNode`.
37
+ */
38
+ function blockKindToCaption(block) {
39
+ switch (block.kind) {
40
+ case "figure":
41
+ return "Figure";
42
+ case "table":
43
+ return "Table";
44
+ case "code":
45
+ return "Listing"; // possibly also Feature — ambiguous without lang tag
46
+ case "feature":
47
+ return "Feature";
48
+ case "math":
49
+ return "Equation";
50
+ case "list":
51
+ return "List";
52
+ default:
53
+ return undefined;
54
+ }
55
+ }
56
+ // ---------------------------------------------------------------------------
57
+ // Public API
58
+ // ---------------------------------------------------------------------------
59
+ /**
60
+ * Validate caption adjacency for one entry. Emits `MSL-C070` for any
61
+ * caption whose nearest non-blank neighbour (above or below) is not a
62
+ * captionable block of the matching type, and `MSL-C071` when there is
63
+ * a captionable block of the *wrong* type adjacent.
64
+ */
65
+ function validateCaptions(entry) {
66
+ const diagnostics = [];
67
+ const blocks = entry.bodyAst ?? [];
68
+ for (let i = 0; i < blocks.length; i++) {
69
+ const block = blocks[i];
70
+ if (block.kind !== "caption")
71
+ continue;
72
+ const keyword = block.keyword; // safe: CaptionNode.keyword and CaptionKeyword are the same 6-string set
73
+ // Immediate preceding block (no caption-skipping — a CaptionNode
74
+ // neighbour is not a captionable block, matching baseline semantics).
75
+ const prevIdx = i - 1;
76
+ const prevBlock = prevIdx >= 0 ? blocks[prevIdx] : undefined;
77
+ // Immediate following block (no caption-skipping — same rationale).
78
+ const nextIdx = i + 1;
79
+ const nextBlock = nextIdx < blocks.length ? blocks[nextIdx] : undefined;
80
+ // Check if either neighbour is a captionable block of the matching type.
81
+ const prevKind = prevBlock ? blockKindToCaption(prevBlock) : undefined;
82
+ const nextKind = nextBlock ? blockKindToCaption(nextBlock) : undefined;
83
+ // A `CodeNode` may be either Listing or Feature (Gherkin) — both
84
+ // `blockKindToCaption` returns "Listing" for `code`, so a `Feature:`
85
+ // caption below a `CodeNode` block is considered matching (the
86
+ // closing fence has no lang tag; we can't distinguish at this point).
87
+ const prevMatches = prevBlock !== undefined &&
88
+ (prevKind === keyword ||
89
+ (keyword === "Feature" && prevBlock.kind === "code") ||
90
+ (keyword === "Listing" && prevBlock.kind === "feature"));
91
+ const nextMatches = nextBlock !== undefined &&
92
+ (nextKind === keyword ||
93
+ (keyword === "Feature" && nextBlock.kind === "code") ||
94
+ (keyword === "Listing" && nextBlock.kind === "feature"));
95
+ if (prevMatches || nextMatches) {
96
+ // Adjacent to a matching captionable block — valid.
97
+ continue;
98
+ }
99
+ // No matching block adjacent. Decide between C070 (orphan) and C071
100
+ // (wrong-type adjacency).
101
+ const mismatchKind = prevKind ?? nextKind;
102
+ const mismatchBlock = mismatchKind !== undefined
103
+ ? (prevKind !== undefined ? prevBlock : nextBlock)
104
+ : undefined;
105
+ // File line: body-relative 1-based start line → entry.location.line + bodyLine
106
+ const fileLine = entry.location.line + block.range.start.line;
107
+ if (mismatchKind !== undefined && mismatchBlock !== undefined) {
108
+ // Listing and Feature share a fence-only matcher — a CodeNode or
109
+ // FeatureNode is ambiguous without the opening fence's language tag.
110
+ const mismatchLabel = mismatchBlock.kind === "code" || mismatchBlock.kind === "feature"
111
+ ? "Listing or Feature (fenced)"
112
+ : mismatchKind;
113
+ diagnostics.push({
114
+ code: "MSL-C071",
115
+ severity: "error",
116
+ message: `${entry.displayId}: ${keyword}: caption is adjacent to a ` +
117
+ `${mismatchLabel} block, not a ${keyword} block (spec §4.7)`,
118
+ location: {
119
+ file: entry.location.file,
120
+ line: fileLine,
121
+ column: 1,
122
+ },
123
+ });
124
+ }
125
+ else {
126
+ diagnostics.push({
127
+ code: "MSL-C070",
128
+ severity: "error",
129
+ message: `${entry.displayId}: ${keyword}: caption is not adjacent to a ` +
130
+ `captionable block of type ${keyword}`,
131
+ location: {
132
+ file: entry.location.file,
133
+ line: fileLine,
134
+ column: 1,
135
+ },
136
+ });
137
+ }
138
+ }
139
+ return diagnostics;
140
+ }
@@ -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"}