@agentshouse/mdmodel 0.1.0-alpha.8 → 0.1.0-c04c0d681d2d4

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 (407) hide show
  1. package/API.md +368 -0
  2. package/README.md +36 -180
  3. package/dist/blocks.d.ts +11 -0
  4. package/dist/blocks.d.ts.map +1 -0
  5. package/dist/blocks.js +69 -0
  6. package/dist/condition.d.ts +162 -0
  7. package/dist/condition.d.ts.map +1 -0
  8. package/dist/condition.js +616 -0
  9. package/dist/definition.d.ts +70 -25
  10. package/dist/definition.d.ts.map +1 -1
  11. package/dist/definition.js +726 -138
  12. package/dist/divide.d.ts +3 -0
  13. package/dist/divide.d.ts.map +1 -0
  14. package/dist/divide.js +320 -0
  15. package/dist/document.d.ts +12 -2
  16. package/dist/document.d.ts.map +1 -1
  17. package/dist/document.js +400 -177
  18. package/dist/fields.d.ts +6 -0
  19. package/dist/fields.d.ts.map +1 -0
  20. package/dist/fields.js +10 -0
  21. package/dist/index.d.ts +16 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +10 -4
  24. package/dist/links.d.ts +4 -0
  25. package/dist/links.d.ts.map +1 -1
  26. package/dist/links.js +633 -225
  27. package/dist/paths.d.ts +15 -4
  28. package/dist/paths.d.ts.map +1 -1
  29. package/dist/paths.js +149 -36
  30. package/dist/profile.js +1 -3
  31. package/dist/project.d.ts +20 -1
  32. package/dist/project.d.ts.map +1 -1
  33. package/dist/project.js +106 -74
  34. package/dist/references.d.ts +4 -0
  35. package/dist/references.d.ts.map +1 -0
  36. package/dist/references.js +30 -0
  37. package/dist/refuse.d.ts.map +1 -1
  38. package/dist/refuse.js +2 -10
  39. package/dist/schema.d.ts +7 -5
  40. package/dist/schema.d.ts.map +1 -1
  41. package/dist/schema.js +156 -41
  42. package/dist/sections.d.ts +2 -1
  43. package/dist/sections.d.ts.map +1 -1
  44. package/dist/sections.js +45 -67
  45. package/dist/types.d.ts +95 -3
  46. package/dist/types.d.ts.map +1 -1
  47. package/dist/types.js +1 -3
  48. package/dist/validate.d.ts +10 -2
  49. package/dist/validate.d.ts.map +1 -1
  50. package/dist/validate.js +283 -154
  51. package/dist/version.d.ts +1 -1
  52. package/dist/version.d.ts.map +1 -1
  53. package/dist/version.js +1 -3
  54. package/dist/yaml.d.ts +9 -3
  55. package/dist/yaml.d.ts.map +1 -1
  56. package/dist/yaml.js +301 -202
  57. package/fixtures/README.md +91 -55
  58. package/fixtures/cases/absent-link-dangles/library/item.md +8 -0
  59. package/fixtures/cases/absent-link-dangles/schema.yaml +6 -0
  60. package/fixtures/cases/absent-optional-field/context.json +1 -0
  61. package/fixtures/cases/absent-optional-field/expected.json +1 -0
  62. package/fixtures/cases/absent-optional-field/library/companies/acme.md +4 -0
  63. package/fixtures/cases/absent-optional-field/library/deals/lead.md +6 -0
  64. package/fixtures/cases/absent-optional-field/schema.yaml +56 -0
  65. package/fixtures/cases/absolute-link/context.json +1 -0
  66. package/fixtures/cases/absolute-link/expected.json +5 -0
  67. package/fixtures/cases/absolute-link/library/item.md +8 -0
  68. package/fixtures/cases/absolute-link/schema.yaml +6 -0
  69. package/fixtures/cases/attachment-reference-any-file/context.json +1 -0
  70. package/fixtures/cases/attachment-reference-any-file/expected.json +1 -0
  71. package/fixtures/cases/attachment-reference-any-file/library/companies/acme.md +4 -0
  72. package/fixtures/cases/attachment-reference-any-file/library/deals/renewal.md +15 -0
  73. package/fixtures/cases/attachment-reference-any-file/library/places/depot.md +4 -0
  74. package/fixtures/cases/attachment-reference-any-file/library/products/seats.md +4 -0
  75. package/fixtures/cases/attachment-reference-any-file/library/products/support.md +4 -0
  76. package/fixtures/cases/attachment-reference-any-file/schema.yaml +32 -0
  77. package/fixtures/cases/attachment-reference-dangles/context.json +1 -0
  78. package/fixtures/cases/attachment-reference-dangles/expected.json +1 -0
  79. package/fixtures/cases/attachment-reference-dangles/library/companies/acme.md +4 -0
  80. package/fixtures/cases/attachment-reference-dangles/library/deals/renewal.md +15 -0
  81. package/fixtures/cases/attachment-reference-dangles/library/places/depot.md +4 -0
  82. package/fixtures/cases/attachment-reference-dangles/library/products/seats.md +4 -0
  83. package/fixtures/cases/attachment-reference-dangles/library/products/support.md +4 -0
  84. package/fixtures/cases/attachment-reference-dangles/schema.yaml +32 -0
  85. package/fixtures/cases/attachment-reference-outside/context.json +1 -0
  86. package/fixtures/cases/attachment-reference-outside/expected.json +6 -0
  87. package/fixtures/cases/attachment-reference-outside/library/companies/acme.md +4 -0
  88. package/fixtures/cases/attachment-reference-outside/library/deals/renewal.md +15 -0
  89. package/fixtures/cases/attachment-reference-outside/library/places/depot.md +4 -0
  90. package/fixtures/cases/attachment-reference-outside/library/products/seats.md +4 -0
  91. package/fixtures/cases/attachment-reference-outside/library/products/support.md +4 -0
  92. package/fixtures/cases/attachment-reference-outside/schema.yaml +32 -0
  93. package/fixtures/cases/binary-any-reference/expected.json +1 -2
  94. package/fixtures/cases/binary-any-reference/schema.yaml +4 -0
  95. package/fixtures/cases/binary-document-collision/expected.json +1 -2
  96. package/fixtures/cases/binary-document-collision/schema.yaml +1 -0
  97. package/fixtures/cases/binary-image-dangles/expected.json +1 -0
  98. package/fixtures/cases/binary-image-dangles/schema.yaml +1 -0
  99. package/fixtures/cases/binary-link-dangles/expected.json +1 -0
  100. package/fixtures/cases/binary-link-dangles/schema.yaml +1 -0
  101. package/fixtures/cases/binary-link-outside-collection/expected.json +1 -2
  102. package/fixtures/cases/binary-link-outside-collection/schema.yaml +1 -0
  103. package/fixtures/cases/binary-prototype-reference/expected.json +1 -2
  104. package/fixtures/cases/binary-prototype-reference/schema.yaml +4 -0
  105. package/fixtures/cases/binary-typed-reference/expected.json +1 -2
  106. package/fixtures/cases/binary-typed-reference/schema.yaml +5 -0
  107. package/fixtures/cases/boolean-field/context.json +1 -0
  108. package/fixtures/cases/boolean-field/expected.json +6 -0
  109. package/fixtures/cases/boolean-field/library/companies/acme.md +4 -0
  110. package/fixtures/cases/boolean-field/library/deals/renewal.md +31 -0
  111. package/fixtures/cases/boolean-field/schema.yaml +56 -0
  112. package/fixtures/cases/bracketed-link-definition/schema.yaml +6 -0
  113. package/fixtures/cases/closed-nested-object/context.json +1 -0
  114. package/fixtures/cases/closed-nested-object/expected.json +6 -0
  115. package/fixtures/cases/closed-nested-object/library/companies/acme.md +4 -0
  116. package/fixtures/cases/closed-nested-object/library/deals/renewal.md +32 -0
  117. package/fixtures/cases/closed-nested-object/schema.yaml +56 -0
  118. package/fixtures/cases/composed-root-reference/context.json +1 -0
  119. package/fixtures/cases/composed-root-reference/expected.json +6 -0
  120. package/fixtures/cases/composed-root-reference/library/a.md +5 -0
  121. package/fixtures/cases/composed-root-reference/schema.yaml +13 -0
  122. package/fixtures/cases/cross-room-link/context.json +1 -0
  123. package/fixtures/cases/cross-room-link/expected.json +1 -0
  124. package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
  125. package/fixtures/cases/cross-room-link/schema.yaml +3 -0
  126. package/fixtures/cases/cross-room-reference/context.json +1 -0
  127. package/fixtures/cases/cross-room-reference/expected.json +1 -0
  128. package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
  129. package/fixtures/cases/cross-room-reference/schema.yaml +9 -0
  130. package/fixtures/cases/date-time-format/context.json +1 -0
  131. package/fixtures/cases/date-time-format/expected.json +6 -0
  132. package/fixtures/cases/date-time-format/library/companies/acme.md +4 -0
  133. package/fixtures/cases/date-time-format/library/deals/renewal.md +31 -0
  134. package/fixtures/cases/date-time-format/schema.yaml +56 -0
  135. package/fixtures/cases/declared-binary-links/schema.yaml +1 -0
  136. package/fixtures/cases/default-unfilled/context.json +1 -0
  137. package/fixtures/cases/default-unfilled/expected.json +6 -0
  138. package/fixtures/cases/default-unfilled/library/companies/acme.md +4 -0
  139. package/fixtures/cases/default-unfilled/library/deals/renewal.md +29 -0
  140. package/fixtures/cases/default-unfilled/schema.yaml +56 -0
  141. package/fixtures/cases/defs-pattern/context.json +1 -0
  142. package/fixtures/cases/defs-pattern/expected.json +6 -0
  143. package/fixtures/cases/defs-pattern/library/companies/acme.md +4 -0
  144. package/fixtures/cases/defs-pattern/library/deals/renewal.md +31 -0
  145. package/fixtures/cases/defs-pattern/schema.yaml +56 -0
  146. package/fixtures/cases/dependent-rule/context.json +1 -0
  147. package/fixtures/cases/dependent-rule/expected.json +6 -0
  148. package/fixtures/cases/dependent-rule/library/companies/acme.md +4 -0
  149. package/fixtures/cases/dependent-rule/library/deals/renewal.md +30 -0
  150. package/fixtures/cases/dependent-rule/schema.yaml +56 -0
  151. package/fixtures/cases/duplicate-link-definition/schema.yaml +6 -0
  152. package/fixtures/cases/email-format/context.json +1 -0
  153. package/fixtures/cases/email-format/expected.json +6 -0
  154. package/fixtures/cases/email-format/library/companies/acme.md +4 -0
  155. package/fixtures/cases/email-format/library/deals/renewal.md +31 -0
  156. package/fixtures/cases/email-format/schema.yaml +56 -0
  157. package/fixtures/cases/fenced-link-definition/schema.yaml +6 -0
  158. package/fixtures/cases/field-enum/expected.json +2 -3
  159. package/fixtures/cases/field-enum/schema.yaml +7 -0
  160. package/fixtures/cases/frontmatter-schema/context.json +1 -0
  161. package/fixtures/cases/frontmatter-schema/expected.json +5 -0
  162. package/fixtures/cases/frontmatter-schema/schema.yaml +5 -0
  163. package/fixtures/cases/integer-field/context.json +1 -0
  164. package/fixtures/cases/integer-field/expected.json +6 -0
  165. package/fixtures/cases/integer-field/library/companies/acme.md +4 -0
  166. package/fixtures/cases/integer-field/library/deals/renewal.md +31 -0
  167. package/fixtures/cases/integer-field/schema.yaml +56 -0
  168. package/fixtures/cases/interrupted-link-definition/schema.yaml +1 -0
  169. package/fixtures/cases/json-schema-constructs/context.json +1 -0
  170. package/fixtures/cases/json-schema-constructs/expected.json +1 -0
  171. package/fixtures/cases/json-schema-constructs/library/companies/acme.md +4 -0
  172. package/fixtures/cases/json-schema-constructs/library/deals/renewal.md +31 -0
  173. package/fixtures/cases/json-schema-constructs/schema.yaml +56 -0
  174. package/fixtures/cases/list-of-objects-closed/context.json +1 -0
  175. package/fixtures/cases/list-of-objects-closed/expected.json +6 -0
  176. package/fixtures/cases/list-of-objects-closed/library/companies/acme.md +4 -0
  177. package/fixtures/cases/list-of-objects-closed/library/deals/renewal.md +32 -0
  178. package/fixtures/cases/list-of-objects-closed/schema.yaml +56 -0
  179. package/fixtures/cases/list-of-objects-item/context.json +1 -0
  180. package/fixtures/cases/list-of-objects-item/expected.json +6 -0
  181. package/fixtures/cases/list-of-objects-item/library/companies/acme.md +4 -0
  182. package/fixtures/cases/list-of-objects-item/library/deals/renewal.md +31 -0
  183. package/fixtures/cases/list-of-objects-item/schema.yaml +56 -0
  184. package/fixtures/cases/list-of-objects-reference/context.json +1 -0
  185. package/fixtures/cases/list-of-objects-reference/expected.json +6 -0
  186. package/fixtures/cases/list-of-objects-reference/library/companies/acme.md +4 -0
  187. package/fixtures/cases/list-of-objects-reference/library/deals/renewal.md +14 -0
  188. package/fixtures/cases/list-of-objects-reference/library/places/depot.md +4 -0
  189. package/fixtures/cases/list-of-objects-reference/library/products/seats.md +4 -0
  190. package/fixtures/cases/list-of-objects-reference/library/products/support.md +4 -0
  191. package/fixtures/cases/list-of-objects-reference/schema.yaml +32 -0
  192. package/fixtures/cases/list-size/context.json +1 -0
  193. package/fixtures/cases/list-size/expected.json +6 -0
  194. package/fixtures/cases/list-size/library/companies/acme.md +4 -0
  195. package/fixtures/cases/list-size/library/deals/renewal.md +31 -0
  196. package/fixtures/cases/list-size/schema.yaml +56 -0
  197. package/fixtures/cases/long-fence-link-definition/schema.yaml +1 -0
  198. package/fixtures/cases/malformed-definition/expected.json +2 -4
  199. package/fixtures/cases/malformed-definition/schema.yaml +3 -0
  200. package/fixtures/cases/member-document/context.json +1 -0
  201. package/fixtures/cases/member-document/expected.json +1 -0
  202. package/fixtures/cases/member-document/library/people/ana.md +5 -0
  203. package/fixtures/cases/member-document/schema.yaml +5 -0
  204. package/fixtures/cases/missing-required-field/expected.json +2 -3
  205. package/fixtures/cases/missing-required-field/schema.yaml +7 -0
  206. package/fixtures/cases/missing-section-item-kind/context.json +1 -0
  207. package/fixtures/cases/missing-section-item-kind/expected.json +5 -0
  208. package/fixtures/cases/missing-section-item-kind/schema.yaml +6 -0
  209. package/fixtures/cases/misspelled-key/context.json +1 -0
  210. package/fixtures/cases/misspelled-key/expected.json +6 -0
  211. package/fixtures/cases/misspelled-key/library/companies/acme.md +4 -0
  212. package/fixtures/cases/misspelled-key/library/deals/renewal.md +32 -0
  213. package/fixtures/cases/misspelled-key/schema.yaml +56 -0
  214. package/fixtures/cases/nested-defs/context.json +1 -0
  215. package/fixtures/cases/nested-defs/expected.json +6 -0
  216. package/fixtures/cases/nested-defs/library/deal.md +6 -0
  217. package/fixtures/cases/nested-defs/schema.yaml +11 -0
  218. package/fixtures/cases/nested-object-reference/context.json +1 -0
  219. package/fixtures/cases/nested-object-reference/expected.json +6 -0
  220. package/fixtures/cases/nested-object-reference/library/companies/acme.md +4 -0
  221. package/fixtures/cases/nested-object-reference/library/deals/renewal.md +14 -0
  222. package/fixtures/cases/nested-object-reference/library/places/depot.md +4 -0
  223. package/fixtures/cases/nested-object-reference/library/products/seats.md +4 -0
  224. package/fixtures/cases/nested-object-reference/library/products/support.md +4 -0
  225. package/fixtures/cases/nested-object-reference/schema.yaml +32 -0
  226. package/fixtures/cases/nested-reference/context.json +1 -0
  227. package/fixtures/cases/nested-reference/expected.json +1 -0
  228. package/fixtures/cases/nested-reference/library/companies/acme.md +4 -0
  229. package/fixtures/cases/nested-reference/library/deals/renewal.md +15 -0
  230. package/fixtures/cases/nested-reference/library/places/depot.md +4 -0
  231. package/fixtures/cases/nested-reference/library/products/seats.md +4 -0
  232. package/fixtures/cases/nested-reference/library/products/support.md +4 -0
  233. package/fixtures/cases/nested-reference/schema.yaml +32 -0
  234. package/fixtures/cases/nested-required-field/context.json +1 -0
  235. package/fixtures/cases/nested-required-field/expected.json +6 -0
  236. package/fixtures/cases/nested-required-field/library/companies/acme.md +4 -0
  237. package/fixtures/cases/nested-required-field/library/deals/renewal.md +30 -0
  238. package/fixtures/cases/nested-required-field/schema.yaml +56 -0
  239. package/fixtures/cases/null-refused/context.json +1 -0
  240. package/fixtures/cases/null-refused/expected.json +6 -0
  241. package/fixtures/cases/null-refused/library/companies/acme.md +4 -0
  242. package/fixtures/cases/null-refused/library/deals/renewal.md +31 -0
  243. package/fixtures/cases/null-refused/schema.yaml +56 -0
  244. package/fixtures/cases/numeric-range/context.json +1 -0
  245. package/fixtures/cases/numeric-range/expected.json +6 -0
  246. package/fixtures/cases/numeric-range/library/companies/acme.md +4 -0
  247. package/fixtures/cases/numeric-range/library/deals/renewal.md +31 -0
  248. package/fixtures/cases/numeric-range/schema.yaml +56 -0
  249. package/fixtures/cases/one-of-variant/context.json +1 -0
  250. package/fixtures/cases/one-of-variant/expected.json +6 -0
  251. package/fixtures/cases/one-of-variant/library/companies/acme.md +4 -0
  252. package/fixtures/cases/one-of-variant/library/deals/renewal.md +31 -0
  253. package/fixtures/cases/one-of-variant/schema.yaml +56 -0
  254. package/fixtures/cases/open-map-value/context.json +1 -0
  255. package/fixtures/cases/open-map-value/expected.json +6 -0
  256. package/fixtures/cases/open-map-value/library/companies/acme.md +4 -0
  257. package/fixtures/cases/open-map-value/library/deals/renewal.md +31 -0
  258. package/fixtures/cases/open-map-value/schema.yaml +56 -0
  259. package/fixtures/cases/other-room-reference/context.json +1 -0
  260. package/fixtures/cases/other-room-reference/expected.json +6 -0
  261. package/fixtures/cases/other-room-reference/library/companies/acme.md +4 -0
  262. package/fixtures/cases/other-room-reference/library/deals/renewal.md +14 -0
  263. package/fixtures/cases/other-room-reference/library/places/depot.md +4 -0
  264. package/fixtures/cases/other-room-reference/library/products/seats.md +4 -0
  265. package/fixtures/cases/other-room-reference/library/products/support.md +4 -0
  266. package/fixtures/cases/other-room-reference/schema.yaml +32 -0
  267. package/fixtures/cases/paragraph-link-definition/schema.yaml +1 -0
  268. package/fixtures/cases/prototype-field/context.json +1 -0
  269. package/fixtures/cases/prototype-field/expected.json +6 -0
  270. package/fixtures/cases/prototype-field/library/item.md +9 -0
  271. package/fixtures/cases/prototype-field/schema.yaml +6 -0
  272. package/fixtures/cases/quoted-link-definition/expected.json +1 -2
  273. package/fixtures/cases/quoted-link-definition/library/notes/draft.md +1 -1
  274. package/fixtures/cases/quoted-link-definition/schema.yaml +1 -0
  275. package/fixtures/cases/referenced-missing-file/expected.json +0 -1
  276. package/fixtures/cases/referenced-missing-file/schema.yaml +11 -0
  277. package/fixtures/cases/remote-ref/context.json +1 -0
  278. package/fixtures/cases/remote-ref/expected.json +5 -0
  279. package/fixtures/cases/remote-ref/schema.yaml +3 -0
  280. package/fixtures/cases/second-member-document/context.json +1 -0
  281. package/fixtures/cases/second-member-document/expected.json +5 -0
  282. package/fixtures/cases/second-member-document/schema.yaml +4 -0
  283. package/fixtures/cases/section-item-enum/context.json +1 -0
  284. package/fixtures/cases/section-item-enum/expected.json +6 -0
  285. package/fixtures/cases/section-item-enum/library/task.md +8 -0
  286. package/fixtures/cases/section-item-enum/schema.yaml +3 -0
  287. package/fixtures/cases/section-item-kind/context.json +1 -0
  288. package/fixtures/cases/section-item-kind/expected.json +6 -0
  289. package/fixtures/cases/section-item-kind/library/task.md +8 -0
  290. package/fixtures/cases/section-item-kind/schema.yaml +3 -0
  291. package/fixtures/cases/section-items/context.json +1 -0
  292. package/fixtures/cases/section-items/expected.json +1 -0
  293. package/fixtures/cases/section-items/library/other.md +3 -0
  294. package/fixtures/cases/section-items/library/page.md +42 -0
  295. package/fixtures/cases/section-items/schema.yaml +10 -0
  296. package/fixtures/cases/section-reference-path/context.json +1 -0
  297. package/fixtures/cases/section-reference-path/expected.json +6 -0
  298. package/fixtures/cases/section-reference-path/library/other.md +3 -0
  299. package/fixtures/cases/section-reference-path/library/page.md +7 -0
  300. package/fixtures/cases/section-reference-path/schema.yaml +3 -0
  301. package/fixtures/cases/section-reference-type/context.json +1 -0
  302. package/fixtures/cases/section-reference-type/expected.json +6 -0
  303. package/fixtures/cases/section-reference-type/library/note.md +1 -0
  304. package/fixtures/cases/section-reference-type/library/page.md +7 -0
  305. package/fixtures/cases/section-reference-type/schema.yaml +3 -0
  306. package/fixtures/cases/shortcut-reference-link/context.json +1 -0
  307. package/fixtures/cases/shortcut-reference-link/expected.json +5 -0
  308. package/fixtures/cases/shortcut-reference-link/library/item.md +10 -0
  309. package/fixtures/cases/shortcut-reference-link/schema.yaml +6 -0
  310. package/fixtures/cases/string-length/context.json +1 -0
  311. package/fixtures/cases/string-length/expected.json +6 -0
  312. package/fixtures/cases/string-length/library/companies/acme.md +4 -0
  313. package/fixtures/cases/string-length/library/deals/renewal.md +31 -0
  314. package/fixtures/cases/string-length/schema.yaml +56 -0
  315. package/fixtures/cases/structured-section/expected.json +1 -2
  316. package/fixtures/cases/structured-section/schema.yaml +7 -0
  317. package/fixtures/cases/submission-keys/context.json +1 -0
  318. package/fixtures/cases/submission-keys/expected.json +1 -0
  319. package/fixtures/cases/submission-keys/library/notes/visitor.md +8 -0
  320. package/fixtures/cases/submission-keys/schema.yaml +4 -0
  321. package/fixtures/cases/text-field-kind/context.json +1 -0
  322. package/fixtures/cases/text-field-kind/expected.json +6 -0
  323. package/fixtures/cases/text-field-kind/library/page.md +4 -0
  324. package/fixtures/cases/text-field-kind/schema.yaml +4 -0
  325. package/fixtures/cases/truncated-link-definition/expected.json +1 -2
  326. package/fixtures/cases/truncated-link-definition/library/notes/draft.md +1 -1
  327. package/fixtures/cases/truncated-link-definition/schema.yaml +1 -0
  328. package/fixtures/cases/types-folder-content/context.json +1 -0
  329. package/fixtures/cases/types-folder-content/expected.json +1 -0
  330. package/fixtures/cases/types-folder-content/library/types/task.md +4 -0
  331. package/fixtures/cases/types-folder-content/schema.yaml +4 -0
  332. package/fixtures/cases/unclosed-frontmatter/expected.json +1 -2
  333. package/fixtures/cases/undeclared-field/context.json +1 -0
  334. package/fixtures/cases/undeclared-field/expected.json +6 -0
  335. package/fixtures/cases/undeclared-field/library/item.md +9 -0
  336. package/fixtures/cases/undeclared-field/schema.yaml +6 -0
  337. package/fixtures/cases/unevaluated-items-closed/context.json +1 -0
  338. package/fixtures/cases/unevaluated-items-closed/expected.json +6 -0
  339. package/fixtures/cases/unevaluated-items-closed/library/trip.md +6 -0
  340. package/fixtures/cases/unevaluated-items-closed/schema.yaml +10 -0
  341. package/fixtures/cases/unknown-type/context.json +1 -0
  342. package/fixtures/cases/unknown-type/expected.json +6 -0
  343. package/fixtures/cases/unknown-type/library/item.md +3 -0
  344. package/fixtures/cases/unknown-type/schema.yaml +3 -0
  345. package/fixtures/cases/unlisted-reference-type/context.json +1 -0
  346. package/fixtures/cases/unlisted-reference-type/expected.json +5 -0
  347. package/fixtures/cases/unlisted-reference-type/schema.yaml +3 -0
  348. package/fixtures/cases/unresolved-link/expected.json +1 -2
  349. package/fixtures/cases/unresolved-link/library/item.md +1 -1
  350. package/fixtures/cases/unresolved-link/schema.yaml +6 -0
  351. package/fixtures/cases/valid-typed-document/library/tasks/one.md +1 -0
  352. package/fixtures/cases/valid-typed-document/schema.yaml +16 -0
  353. package/fixtures/cases/wide-item-fence-link/schema.yaml +1 -0
  354. package/fixtures/division.json +409 -0
  355. package/fixtures/projection.json +109 -28
  356. package/package.json +6 -13
  357. package/dist/definition.js.map +0 -1
  358. package/dist/document.js.map +0 -1
  359. package/dist/index.js.map +0 -1
  360. package/dist/links.js.map +0 -1
  361. package/dist/paths.js.map +0 -1
  362. package/dist/profile.js.map +0 -1
  363. package/dist/project.js.map +0 -1
  364. package/dist/refuse.js.map +0 -1
  365. package/dist/schema.js.map +0 -1
  366. package/dist/sections.js.map +0 -1
  367. package/dist/types.js.map +0 -1
  368. package/dist/validate.js.map +0 -1
  369. package/dist/version.js.map +0 -1
  370. package/dist/yaml.js.map +0 -1
  371. package/fixtures/cases/binary-any-reference/library/types/note.md +0 -5
  372. package/fixtures/cases/binary-document-collision/library/types/note.md +0 -3
  373. package/fixtures/cases/binary-link-outside-collection/library/types/note.md +0 -3
  374. package/fixtures/cases/binary-prototype-reference/library/types/note.md +0 -5
  375. package/fixtures/cases/binary-typed-reference/library/types/note.md +0 -5
  376. package/fixtures/cases/binary-typed-reference/library/types/person.md +0 -3
  377. package/fixtures/cases/bracketed-link-definition/library/types/task.md +0 -7
  378. package/fixtures/cases/declared-binary-links/library/types/note.md +0 -3
  379. package/fixtures/cases/duplicate-link-definition/library/types/task.md +0 -7
  380. package/fixtures/cases/fenced-link-definition/library/types/task.md +0 -7
  381. package/fixtures/cases/field-enum/library/types/task.md +0 -8
  382. package/fixtures/cases/interrupted-link-definition/library/types/note.md +0 -3
  383. package/fixtures/cases/long-fence-link-definition/library/types/note.md +0 -3
  384. package/fixtures/cases/malformed-definition/library/types/task.md +0 -5
  385. package/fixtures/cases/missing-binary-image/expected.json +0 -6
  386. package/fixtures/cases/missing-binary-image/library/types/note.md +0 -3
  387. package/fixtures/cases/missing-binary-link/expected.json +0 -6
  388. package/fixtures/cases/missing-binary-link/library/types/note.md +0 -3
  389. package/fixtures/cases/missing-required-field/library/types/task.md +0 -8
  390. package/fixtures/cases/paragraph-link-definition/library/types/note.md +0 -3
  391. package/fixtures/cases/prd-definition/library/types/task.md +0 -15
  392. package/fixtures/cases/quoted-link-definition/library/types/note.md +0 -3
  393. package/fixtures/cases/referenced-missing-file/library/types/person.md +0 -5
  394. package/fixtures/cases/referenced-missing-file/library/types/task.md +0 -8
  395. package/fixtures/cases/structured-section/library/types/task.md +0 -8
  396. package/fixtures/cases/truncated-link-definition/library/types/note.md +0 -3
  397. package/fixtures/cases/unresolved-link/library/types/task.md +0 -7
  398. package/fixtures/cases/valid-typed-document/library/types/person.md +0 -5
  399. package/fixtures/cases/valid-typed-document/library/types/task.md +0 -12
  400. package/fixtures/cases/wide-item-fence-link/library/types/note.md +0 -3
  401. package/markdown-syntax-profile.md +0 -9
  402. /package/fixtures/cases/{prd-definition → absent-link-dangles}/context.json +0 -0
  403. /package/fixtures/cases/{prd-definition → absent-link-dangles}/expected.json +0 -0
  404. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/context.json +0 -0
  405. /package/fixtures/cases/{missing-binary-image → binary-image-dangles}/library/notes/draft.md +0 -0
  406. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/context.json +0 -0
  407. /package/fixtures/cases/{missing-binary-link → binary-link-dangles}/library/notes/draft.md +0 -0
package/dist/links.js CHANGED
@@ -1,11 +1,34 @@
1
1
  const TAB_STOP = 4;
2
2
  const CLOSING_FENCE_INDENT = 3;
3
+ const CODE_INDENT = 4;
3
4
  const HEADING = /^#{1,6}(?:[ \t]|$)/;
4
5
  const BREAK = /^(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})$/;
5
6
  const SETEXT = /^(?:=+|-+)[ \t]*$/;
6
- const LABEL = /^\[((?:[^\\\]\n]|\\.)+)\]:[ \t]*/;
7
- const DESTINATION = /^(?:(<[^<>\n\r]*>)|([^\s<][^\s]*))/d;
8
- const TITLE = /^(?:"[^"\n]*"|'[^'\n]*'|\([^()\n]*\))[ \t]*$/;
7
+ const BLANK = /^[ \t\v\f]*\r?$/;
8
+ const HTML_CLOSED = [
9
+ [/^<(?:script|pre|style)(?:[ \t\v\f>]|$)/i, /<\/(?:script|pre|style)>/i],
10
+ [/^<!--/, /-->/],
11
+ [/^<\?/, /\?>/],
12
+ [/^<![A-Z]/, />/],
13
+ [/^<!\[CDATA\[/, /\]\]>/],
14
+ ];
15
+ const HTML_BLOCK_TAG = /^<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:[ \t\v\f>]|\/>|$)/i;
16
+ const HTML_TAG_LINE = /^(?:<[A-Za-z][A-Za-z0-9-]*(?:[ \t\v\f]+[A-Za-z_:][A-Za-z0-9_.:-]*(?:[ \t\v\f]*=[ \t\v\f]*(?:[^ \t\v\f\r\n"'=<>`]+|'[^']*'|"[^"]*"))?)*[ \t\v\f]*\/?>|<\/[A-Za-z][A-Za-z0-9-]*[ \t\v\f]*>)[ \t\v\f]*$/;
17
+ const ORDERED = /^(\d{1,9})[.)]/;
18
+ const LABEL_LENGTH = 999;
19
+ const PUNCTUATION = /^[!-/:-@[-`{-~]$/;
20
+ const INLINE_RAW = new RegExp([
21
+ '<[A-Za-z][A-Za-z0-9-]*(?:[ \\t\\n\\v\\f\\r]+[A-Za-z_:][A-Za-z0-9_.:-]*(?:[ \\t\\n\\v\\f\\r]*=[ \\t\\n\\v\\f\\r]*(?:[^ \\t\\n\\v\\f\\r"\'=<>`]+|\'[^\']*\'|"[^"]*"))?)*[ \\t\\n\\v\\f\\r]*\\/?>',
22
+ '<\\/[A-Za-z][A-Za-z0-9-]*[ \\t\\n\\v\\f\\r]*>',
23
+ '<!--(?!-?>)(?:-?[^-])*-->',
24
+ '<\\?[\\s\\S]*?\\?>',
25
+ '<![A-Z]+[ \\t\\n\\v\\f\\r]+[^>]*>',
26
+ '<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
27
+ '<[A-Za-z][A-Za-z0-9+.-]{1,31}:[^\\x00-\\x20<>]*>',
28
+ "<[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*>",
29
+ ].join('|'), 'y');
30
+ const DELIMITER_ROW = /^\|?[ \t]*:?-+:?[ \t]*(?:\|[ \t]*:?-+:?[ \t]*)*\|?[ \t]*$/;
31
+ const GAP = /^[ \t\v\f]+/;
9
32
  function endOfLine(text, from) {
10
33
  const nl = text.indexOf('\n', from);
11
34
  return nl === -1 ? text.length : nl;
@@ -16,16 +39,21 @@ function afterLine(text, end) {
16
39
  function itemMarker(text, index, end) {
17
40
  let i = index;
18
41
  const bullet = text[i];
19
- if (bullet === '-' || bullet === '*' || bullet === '+') i += 1;
42
+ if (bullet === '-' || bullet === '*' || bullet === '+')
43
+ i += 1;
20
44
  else {
21
45
  let digits = 0;
22
- while(digits < 9 && i + digits < end && text[i + digits] >= '0' && text[i + digits] <= '9')digits += 1;
46
+ while (digits < 9 && i + digits < end && text[i + digits] >= '0' && text[i + digits] <= '9')
47
+ digits += 1;
23
48
  const delimiter = text[i + digits];
24
- if (digits === 0 || delimiter !== '.' && delimiter !== ')') return null;
49
+ if (digits === 0 || (delimiter !== '.' && delimiter !== ')'))
50
+ return null;
25
51
  i += digits + 1;
26
52
  }
27
- if (i >= end) return i;
28
- if (text[i] !== ' ' && text[i] !== '\t') return null;
53
+ if (i >= end)
54
+ return i;
55
+ if (text[i] !== ' ' && text[i] !== '\t')
56
+ return null;
29
57
  return i + 1;
30
58
  }
31
59
  function readLine(text, start, end) {
@@ -33,41 +61,38 @@ function readLine(text, start, end) {
33
61
  let depth = 0;
34
62
  let item = false;
35
63
  let inner = start;
36
- for(;;){
64
+ for (;;) {
37
65
  let spaces = 0;
38
- while(spaces < 3 && i < end && text[i] === ' '){
66
+ while (spaces < 3 && i < end && text[i] === ' ') {
39
67
  i += 1;
40
68
  spaces += 1;
41
69
  }
42
70
  if (i < end && text[i] === '>') {
43
71
  depth += 1;
44
72
  i += 1;
45
- if (i < end && text[i] === ' ') i += 1;
73
+ if (i < end && text[i] === ' ')
74
+ i += 1;
46
75
  inner = i;
47
76
  continue;
48
77
  }
49
78
  const after = i < end ? itemMarker(text, i, end) : null;
50
- if (after === null) break;
79
+ if (after === null)
80
+ break;
51
81
  item = true;
52
82
  i = after;
53
83
  }
54
- return {
55
- start,
56
- end,
57
- content: i,
58
- depth,
59
- item,
60
- inner
61
- };
84
+ return { start, end, content: i, depth, item, inner };
62
85
  }
63
86
  function widthOf(text, from, to) {
64
87
  let width = 0;
65
- for(let i = from; i < to; i += 1)width += text[i] === '\t' ? TAB_STOP - width % TAB_STOP : 1;
88
+ for (let i = from; i < to; i += 1)
89
+ width += text[i] === '\t' ? TAB_STOP - (width % TAB_STOP) : 1;
66
90
  return width;
67
91
  }
68
92
  function afterIndent(text, line) {
69
93
  let i = line.inner;
70
- while(i < line.end && (text[i] === ' ' || text[i] === '\t'))i += 1;
94
+ while (i < line.end && (text[i] === ' ' || text[i] === '\t'))
95
+ i += 1;
71
96
  return i;
72
97
  }
73
98
  function indentWidth(text, line) {
@@ -79,302 +104,685 @@ function lineText(text, line) {
79
104
  }
80
105
  function fenceRun(text, at, end) {
81
106
  const char = text[at];
82
- if (char !== '`' && char !== '~') return null;
107
+ if (char !== '`' && char !== '~')
108
+ return null;
83
109
  let length = 0;
84
- while(at + length < end && text[at + length] === char)length += 1;
85
- return length < 3 ? null : {
86
- char,
87
- length
88
- };
110
+ while (at + length < end && text[at + length] === char)
111
+ length += 1;
112
+ return length < 3 ? null : { char, length };
89
113
  }
90
114
  function fenceAt(text, line) {
91
115
  const run = fenceRun(text, line.content, line.end);
92
- if (run === null) return null;
116
+ if (run === null)
117
+ return null;
93
118
  return {
94
119
  char: run.char,
95
120
  length: run.length,
96
121
  depth: line.depth,
97
122
  column: line.item ? widthOf(text, line.inner, line.content) : 0,
98
- item: line.item
123
+ item: line.item,
99
124
  };
100
125
  }
101
126
  function closesFence(text, line, open) {
102
- if (line.depth !== open.depth || line.item) return false;
127
+ if (line.depth !== open.depth || line.item)
128
+ return false;
103
129
  const indent = indentWidth(text, line);
104
- if (indent < open.column || indent > open.column + CLOSING_FENCE_INDENT) return false;
130
+ if (indent < open.column || indent > open.column + CLOSING_FENCE_INDENT)
131
+ return false;
105
132
  const at = afterIndent(text, line);
106
133
  const run = fenceRun(text, at, line.end);
107
- if (run === null || run.char !== open.char || run.length < open.length) return false;
134
+ if (run === null || run.char !== open.char || run.length < open.length)
135
+ return false;
108
136
  return text.slice(at + run.length, line.end).trim() === '';
109
137
  }
110
138
  function leavesContainer(text, line, open) {
111
- if (line.depth < open.depth) return true;
112
- if (!open.item || lineText(text, line).trim() === '') return false;
139
+ if (line.depth < open.depth)
140
+ return true;
141
+ if (!open.item || lineText(text, line).trim() === '')
142
+ return false;
113
143
  return indentWidth(text, line) < open.column;
114
144
  }
115
145
  function fenceSpan(text, line, open) {
116
146
  let cursor = afterLine(text, line.end);
117
- while(cursor < text.length){
147
+ while (cursor < text.length) {
118
148
  const end = endOfLine(text, cursor);
119
149
  const next = readLine(text, cursor, end);
120
- if (leavesContainer(text, next, open)) return cursor;
121
- if (closesFence(text, next, open)) return afterLine(text, end);
150
+ if (leavesContainer(text, next, open))
151
+ return cursor;
152
+ if (closesFence(text, next, open))
153
+ return afterLine(text, end);
122
154
  cursor = afterLine(text, end);
123
155
  }
124
156
  return text.length;
125
157
  }
126
- function skipInlineCode(text, index) {
158
+ function skipInlineCode(text, index, joins, unclosed) {
127
159
  let ticks = 0;
128
- while(text[index + ticks] === '`')ticks += 1;
129
- const close = text.indexOf('`'.repeat(ticks), index + ticks);
130
- if (close === -1) return text.length;
131
- return close + ticks;
160
+ while (text[index + ticks] === '`')
161
+ ticks += 1;
162
+ if (index < unclosed.stop && (unclosed.runs.get(ticks) ?? -1) <= index)
163
+ return index + ticks;
164
+ const runs = new Map();
165
+ let i = index + ticks;
166
+ while (i < text.length) {
167
+ const ch = text[i];
168
+ if (ch === '`') {
169
+ let run = 0;
170
+ while (text[i + run] === '`')
171
+ run += 1;
172
+ if (run === ticks)
173
+ return i + run;
174
+ runs.set(run, i);
175
+ i += run;
176
+ continue;
177
+ }
178
+ if (ch === '\r' && text[i + 1] !== '\n')
179
+ break;
180
+ if (ch === '\n' && !joins.has(i))
181
+ break;
182
+ i += 1;
183
+ }
184
+ unclosed.stop = i;
185
+ unclosed.runs = runs;
186
+ return index + ticks;
132
187
  }
133
188
  function skipLinkSpace(text, start) {
134
189
  let i = start;
135
- while(text[i] === ' ' || text[i] === '\t')i += 1;
190
+ while (text[i] === ' ' || text[i] === '\t')
191
+ i += 1;
136
192
  return i;
137
193
  }
138
- function skipTitle(text, start) {
139
- const open = text[start];
140
- if (open !== '"' && open !== "'" && open !== '(') return start;
194
+ function skipInlineSpace(text, start, joins) {
195
+ let i = skipLinkSpace(text, start);
196
+ if (text[i] === '\r' && text[i + 1] === '\n')
197
+ i += 1;
198
+ if (text[i] !== '\n' || !joins.has(i))
199
+ return i;
200
+ return afterIndent(text, readLine(text, i + 1, endOfLine(text, i + 1)));
201
+ }
202
+ function closeEnd(text, start, open, joins) {
141
203
  const close = open === '(' ? ')' : open;
142
- let i = start + 1;
143
- while(i < text.length){
204
+ let i = start;
205
+ while (i < text.length) {
144
206
  const ch = text[i];
145
- if (ch === close) return i + 1;
146
- if (ch === '\n' || ch === '\r') return null;
207
+ if (escapes(text, i)) {
208
+ i += 2;
209
+ continue;
210
+ }
211
+ if (ch === close)
212
+ return i + 1;
213
+ if (open === '(' && ch === '(')
214
+ return null;
215
+ if (ch === '\r' && text[i + 1] !== '\n')
216
+ return null;
217
+ if (ch === '\n' && !joins.has(i))
218
+ return null;
147
219
  i += 1;
148
220
  }
149
221
  return null;
150
222
  }
151
- function destination(text, start) {
152
- let i = skipLinkSpace(text, start + 1);
153
- let occurrence;
154
- if (text[i] === '<') {
155
- const close = text.indexOf('>', i + 1);
156
- if (close === -1) return null;
157
- occurrence = {
158
- href: text.slice(i + 1, close),
159
- start: i,
160
- end: close + 1,
161
- bracketed: true
162
- };
163
- i = close + 1;
164
- } else {
165
- const from = i;
166
- let depth = 0;
167
- while(i < text.length){
168
- const ch = text[i];
169
- if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') break;
170
- if (ch === '(') depth += 1;
171
- else if (ch === ')') {
172
- if (depth === 0) break;
173
- depth -= 1;
174
- }
223
+ function skipTitle(text, start, joins) {
224
+ const open = text[start];
225
+ if (open !== '"' && open !== "'" && open !== '(')
226
+ return start;
227
+ return closeEnd(text, start + 1, open, joins);
228
+ }
229
+ function destinationAt(text, at, end) {
230
+ if (text[at] === '<') {
231
+ let close = at + 1;
232
+ while (close < end && text[close] !== '>') {
233
+ if (text[close] === '<')
234
+ return null;
235
+ close += escapes(text, close) ? 2 : 1;
236
+ }
237
+ if (close >= end)
238
+ return null;
239
+ return { href: text.slice(at + 1, close), start: at, end: close + 1, bracketed: true };
240
+ }
241
+ let i = at;
242
+ let depth = 0;
243
+ while (i < end) {
244
+ if (escapes(text, i)) {
245
+ i += 2;
246
+ continue;
247
+ }
248
+ const ch = text[i];
249
+ if (ch <= ' ' || ch === '\x7f')
250
+ break;
251
+ if (ch === '(')
252
+ depth += 1;
253
+ else if (ch === ')') {
254
+ if (depth === 0)
255
+ break;
256
+ depth -= 1;
257
+ }
258
+ i += 1;
259
+ }
260
+ if (depth !== 0)
261
+ return null;
262
+ return { href: text.slice(at, i), start: at, end: i, bracketed: false };
263
+ }
264
+ function destination(text, start, joins) {
265
+ let i = skipInlineSpace(text, start + 1, joins);
266
+ const occurrence = destinationAt(text, i, endOfLine(text, i));
267
+ if (occurrence === null)
268
+ return null;
269
+ i = occurrence.end;
270
+ const spaced = skipInlineSpace(text, i, joins);
271
+ if (spaced === i && text[i] !== ')')
272
+ return null;
273
+ i = spaced;
274
+ const afterTitle = skipTitle(text, i, joins);
275
+ if (afterTitle === null)
276
+ return null;
277
+ i = skipInlineSpace(text, afterTitle, joins);
278
+ if (text[i] !== ')')
279
+ return null;
280
+ return { occurrence, end: i + 1 };
281
+ }
282
+ function cellCount(row) {
283
+ return row
284
+ .trim()
285
+ .replace(/^\|/, '')
286
+ .replace(/(?<!\\)\|$/, '')
287
+ .split(/(?<!\\)\|/).length;
288
+ }
289
+ function headsTable(text, header, end) {
290
+ if (end >= text.length)
291
+ return false;
292
+ const row = lineText(text, readLine(text, end + 1, endOfLine(text, end + 1)));
293
+ return row.includes('|') && DELIMITER_ROW.test(row) && cellCount(row) === cellCount(header);
294
+ }
295
+ function blockText(text, line) {
296
+ if (!line.item)
297
+ return lineText(text, line);
298
+ const raw = text.slice(afterIndent(text, line), line.end);
299
+ return raw.endsWith('\r') ? raw.slice(0, -1) : raw;
300
+ }
301
+ function interruptsWithHtml(head) {
302
+ return HTML_CLOSED.some(([open]) => open.test(head)) || HTML_BLOCK_TAG.test(head);
303
+ }
304
+ function markerColumn(text, line) {
305
+ return widthOf(text, line.inner, afterIndent(text, line));
306
+ }
307
+ function markerEnd(text, at, end) {
308
+ const after = itemMarker(text, at, end);
309
+ if (after === null)
310
+ return null;
311
+ return after > at && (text[after - 1] === ' ' || text[after - 1] === '\t') ? after - 1 : after;
312
+ }
313
+ function itemContent(text, line) {
314
+ let marker = markerEnd(text, afterIndent(text, line), line.end);
315
+ for (;;) {
316
+ let next = marker + 1;
317
+ let spaces = 0;
318
+ while (spaces < 3 && text[next] === ' ') {
319
+ next += 1;
320
+ spaces += 1;
321
+ }
322
+ const nested = next < line.end ? markerEnd(text, next, line.end) : null;
323
+ if (nested === null)
324
+ break;
325
+ marker = nested;
326
+ }
327
+ const at = skipLinkSpace(text, marker);
328
+ const rest = text.slice(at, line.end).trim();
329
+ const column = widthOf(text, line.inner, at);
330
+ const start = widthOf(text, line.inner, marker);
331
+ if (rest !== '' && column - start <= CODE_INDENT)
332
+ return { column, code: null };
333
+ return { column: start + 1, code: rest === '' ? null : marker + 1 };
334
+ }
335
+ function joinsParagraph(text, line, depth, item) {
336
+ if (line.depth > depth)
337
+ return false;
338
+ const head = blockText(text, line);
339
+ if (head.trim() === '' || endsBlock(head) || interruptsWithHtml(head))
340
+ return false;
341
+ if (fenceAt(text, line) !== null)
342
+ return false;
343
+ if (!line.item)
344
+ return true;
345
+ if (item !== undefined && markerColumn(text, line) < item)
346
+ return false;
347
+ if (lineText(text, line).trim() === '')
348
+ return true;
349
+ const ordered = ORDERED.exec(head);
350
+ return ordered !== null && Number(ordered[1]) !== 1;
351
+ }
352
+ function startsParagraph(text, line) {
353
+ return lineText(text, line).trim() !== '' && !endsBlock(blockText(text, line));
354
+ }
355
+ function lineColumn(text, line) {
356
+ return line.item ? markerColumn(text, line) : indentWidth(text, line);
357
+ }
358
+ function endsTable(text, line, depth) {
359
+ const head = blockText(text, line);
360
+ return (head.trim() === '' ||
361
+ line.depth !== depth ||
362
+ line.item ||
363
+ endsBlock(head) ||
364
+ interruptsWithHtml(head) ||
365
+ fenceAt(text, line) !== null);
366
+ }
367
+ function quoteInner(text, start, end, depth) {
368
+ let i = start;
369
+ for (let level = 0; level < depth; level += 1) {
370
+ let spaces = 0;
371
+ while (spaces < 3 && i < end && text[i] === ' ') {
175
372
  i += 1;
373
+ spaces += 1;
176
374
  }
177
- occurrence = {
178
- href: text.slice(from, i),
179
- start: from,
180
- end: i,
181
- bracketed: false
182
- };
375
+ if (text[i] !== '>')
376
+ return null;
377
+ i += 1;
378
+ if (text[i] === ' ')
379
+ i += 1;
183
380
  }
184
- i = skipLinkSpace(text, i);
185
- const afterTitle = skipTitle(text, i);
186
- if (afterTitle === null) return null;
187
- i = skipLinkSpace(text, afterTitle);
188
- if (text[i] !== ')') return null;
189
- return {
190
- occurrence,
191
- end: i + 1
192
- };
381
+ return i;
382
+ }
383
+ function htmlEnd(text, line, item) {
384
+ const head = lineText(text, line);
385
+ const closed = HTML_CLOSED.find(([open]) => open.test(head));
386
+ if (closed === undefined && !HTML_BLOCK_TAG.test(head) && !HTML_TAG_LINE.test(head))
387
+ return null;
388
+ if (closed !== undefined && closed[1].test(head))
389
+ return afterLine(text, line.end);
390
+ let cursor = afterLine(text, line.end);
391
+ while (cursor < text.length) {
392
+ const end = endOfLine(text, cursor);
393
+ const inner = quoteInner(text, cursor, end, line.depth);
394
+ if (inner === null)
395
+ return cursor;
396
+ const at = skipLinkSpace(text, inner);
397
+ const body = text.slice(inner, end);
398
+ const blank = BLANK.test(text.slice(at, end));
399
+ if (item !== undefined && !blank && widthOf(text, inner, at) < item)
400
+ return cursor;
401
+ if (closed === undefined && blank)
402
+ return cursor;
403
+ if (closed !== undefined && closed[1].test(body))
404
+ return afterLine(text, end);
405
+ cursor = afterLine(text, end);
406
+ if (cursor === end)
407
+ break;
408
+ }
409
+ return text.length;
410
+ }
411
+ function codeEnd(text, line, base) {
412
+ let stop = afterLine(text, line.end);
413
+ let cursor = stop;
414
+ while (cursor < text.length) {
415
+ const end = endOfLine(text, cursor);
416
+ const current = readLine(text, cursor, end);
417
+ if (current.depth !== line.depth)
418
+ break;
419
+ const blank = lineText(text, current).trim() === '' && !current.item;
420
+ if (!blank && (current.item || indentWidth(text, current) < base + CODE_INDENT))
421
+ break;
422
+ cursor = afterLine(text, end);
423
+ if (!blank)
424
+ stop = cursor;
425
+ if (cursor === end)
426
+ break;
427
+ }
428
+ return stop;
429
+ }
430
+ function structure(text) {
431
+ const joins = new Set();
432
+ const raw = [];
433
+ const items = [];
434
+ let paragraph = null;
435
+ let table = null;
436
+ let depth = 0;
437
+ let cursor = 0;
438
+ while (cursor < text.length) {
439
+ const end = endOfLine(text, cursor);
440
+ const line = readLine(text, cursor, end);
441
+ const content = lineText(text, line);
442
+ const blank = content.trim() === '' && !line.item;
443
+ if (table !== null && endsTable(text, line, table))
444
+ table = null;
445
+ if (table !== null) {
446
+ cursor = afterLine(text, end);
447
+ if (cursor === end)
448
+ break;
449
+ continue;
450
+ }
451
+ if (paragraph !== null && joinsParagraph(text, line, paragraph, items.at(-1))) {
452
+ if (headsTable(text, content, end)) {
453
+ table = line.depth;
454
+ paragraph = null;
455
+ }
456
+ else
457
+ joins.add(cursor - 1);
458
+ cursor = afterLine(text, end);
459
+ if (cursor === end)
460
+ break;
461
+ continue;
462
+ }
463
+ paragraph = null;
464
+ if (line.depth !== depth)
465
+ items.length = 0;
466
+ depth = line.depth;
467
+ if (!blank) {
468
+ while (items.length > 0 && items.at(-1) > lineColumn(text, line))
469
+ items.pop();
470
+ }
471
+ if (line.item && !BREAK.test(blockText(text, line))) {
472
+ const opened = itemContent(text, line);
473
+ items.push(opened.column);
474
+ if (opened.code !== null) {
475
+ const stop = codeEnd(text, line, opened.column);
476
+ raw.push([opened.code, stop]);
477
+ cursor = stop;
478
+ continue;
479
+ }
480
+ }
481
+ const open = fenceAt(text, line);
482
+ if (open !== null) {
483
+ const stop = fenceSpan(text, line, open);
484
+ raw.push([cursor, stop]);
485
+ cursor = stop;
486
+ continue;
487
+ }
488
+ const base = items.at(-1) ?? 0;
489
+ if (!blank && !line.item && indentWidth(text, line) >= base + CODE_INDENT) {
490
+ const stop = codeEnd(text, line, base);
491
+ raw.push([cursor, stop]);
492
+ cursor = stop;
493
+ continue;
494
+ }
495
+ const html = htmlEnd(text, line, items.at(-1));
496
+ if (html !== null) {
497
+ raw.push([cursor, html]);
498
+ cursor = html;
499
+ continue;
500
+ }
501
+ if (startsParagraph(text, line)) {
502
+ if (headsTable(text, content, end))
503
+ table = line.depth;
504
+ else
505
+ paragraph = line.depth;
506
+ }
507
+ cursor = afterLine(text, end);
508
+ if (cursor === end)
509
+ break;
510
+ }
511
+ return { joins, raw };
512
+ }
513
+ export function escapes(text, index) {
514
+ return text[index] === '\\' && PUNCTUATION.test(text[index + 1] ?? '');
193
515
  }
194
- function labelEnd(text, start) {
516
+ function referenceEnd(text, start, joins) {
195
517
  let i = start;
196
- let depth = 1;
197
- while(i < text.length && depth > 0){
518
+ while (i < text.length) {
198
519
  const ch = text[i];
199
- if (ch === '\\') {
520
+ if (escapes(text, i)) {
200
521
  i += 2;
201
522
  continue;
202
523
  }
203
- if (ch === '[') depth += 1;
204
- else if (ch === ']') depth -= 1;
205
- else if (ch === '\n' || ch === '\r') return -1;
524
+ if (ch === ']')
525
+ return i + 1;
526
+ if (ch === '[')
527
+ return -1;
528
+ if (ch === '\r' && text[i + 1] !== '\n')
529
+ return -1;
530
+ if (ch === '\n' && !joins.has(i))
531
+ return -1;
206
532
  i += 1;
207
533
  }
208
- return depth === 0 ? i : -1;
209
- }
210
- function takeLink(text, index, start, found, defs) {
211
- const end = labelEnd(text, index + 1);
212
- if (end === -1) return index + 1;
213
- const label = text.slice(index + 1, end - 1);
214
- let i = end;
215
- if (text[i] === '(') {
216
- const dest = destination(text, i);
217
- if (dest === null) return index + 1;
218
- found.push({
219
- start,
220
- end: dest.end,
221
- labelStart: index + 1,
222
- labelEnd: end - 1,
223
- destination: dest.occurrence
224
- });
225
- return dest.end;
534
+ return -1;
535
+ }
536
+ function labelText(text, from, to) {
537
+ let label = '';
538
+ let cursor = from;
539
+ let newline = text.indexOf('\n', cursor);
540
+ while (newline !== -1 && newline < to) {
541
+ label += `${text.slice(cursor, newline)}\n`;
542
+ cursor = afterIndent(text, readLine(text, newline + 1, endOfLine(text, newline + 1)));
543
+ newline = text.indexOf('\n', cursor);
226
544
  }
227
- if (text[i] === '[') {
228
- const close = labelEnd(text, i + 1);
229
- if (close === -1) return index + 1;
230
- const id = (text.slice(i + 1, close - 1) || label).trim().toLowerCase();
231
- const defined = defs.get(id);
232
- if (defined !== undefined) {
233
- found.push({
234
- start,
235
- end: close,
236
- labelStart: index + 1,
237
- labelEnd: end - 1,
238
- destination: defined
239
- });
545
+ return label + text.slice(cursor, to);
546
+ }
547
+ function labelKey(label) {
548
+ return label
549
+ .replace(/[ \t\n\v\f\r]+/g, ' ')
550
+ .replace(/^ | $/g, '')
551
+ .toLowerCase()
552
+ .split('\u0131')
553
+ .map((part) => part.toUpperCase())
554
+ .join('\u0131');
555
+ }
556
+ function labelKeyAt(text, from, to) {
557
+ const label = labelText(text, from, to);
558
+ if (label.length > LABEL_LENGTH && [...label].length > LABEL_LENGTH)
559
+ return '';
560
+ return labelKey(label);
561
+ }
562
+ function closeLink(text, opener, close, defs, joins) {
563
+ const end = close + 1;
564
+ const use = (destination, to) => ({
565
+ start: opener.start,
566
+ end: to,
567
+ labelStart: opener.at + 1,
568
+ labelEnd: close,
569
+ destination,
570
+ });
571
+ if (text[end] === '(') {
572
+ const dest = destination(text, end, joins);
573
+ if (dest !== null)
574
+ return use(dest.occurrence, dest.end);
575
+ }
576
+ if (text[end] === '[') {
577
+ const second = referenceEnd(text, end + 1, joins);
578
+ const collapsed = second === end + 2;
579
+ const named = collapsed
580
+ ? opener.bracketAfter
581
+ ? ''
582
+ : labelKeyAt(text, opener.at + 1, close)
583
+ : labelKeyAt(text, end + 1, second - 1);
584
+ if (second !== -1 && (named !== '' || collapsed)) {
585
+ const defined = defs.get(named);
586
+ return defined === undefined ? null : use(defined, second);
240
587
  }
241
- return close;
242
588
  }
243
- return i;
589
+ if (opener.bracketAfter)
590
+ return null;
591
+ const shortcut = defs.get(labelKeyAt(text, opener.at + 1, close));
592
+ return shortcut === undefined ? null : use(shortcut, end);
244
593
  }
245
594
  function definitionDestination(text, from, to) {
246
- let i = from;
247
- while(i < to && (text[i] === ' ' || text[i] === '\t'))i += 1;
248
- const match = DESTINATION.exec(text.slice(i, to));
249
- if (match === null) return null;
250
- const bracketed = match[1];
251
- const span = match.indices?.[1] ?? match.indices?.[2];
252
- const href = bracketed === undefined ? match[2] : bracketed.slice(1, -1);
253
- if (href === undefined || span === undefined) return null;
254
- return {
255
- href,
256
- start: i + span[0],
257
- end: i + span[1],
258
- bracketed: bracketed !== undefined
259
- };
595
+ const occurrence = destinationAt(text, skipLinkSpace(text, from), to);
596
+ return occurrence === null || (occurrence.href === '' && !occurrence.bracketed)
597
+ ? null
598
+ : occurrence;
260
599
  }
261
- function definitionAt(text, line) {
262
- const head = LABEL.exec(lineText(text, line));
263
- if (head === null) return null;
264
- const id = head[1]?.trim().toLowerCase();
265
- if (id === undefined || id === '') return null;
266
- const from = line.content + head[0].length;
267
- let occurrence = definitionDestination(text, from, line.end);
268
- let next = afterLine(text, line.end);
600
+ function titleEnd(text, at, joins) {
601
+ const open = text[at];
602
+ if (open !== '"' && open !== "'" && open !== '(')
603
+ return null;
604
+ const closed = closeEnd(text, at + 1, open, joins);
605
+ if (closed === null)
606
+ return null;
607
+ const end = endOfLine(text, closed);
608
+ return BLANK.test(text.slice(closed, end)) ? afterLine(text, end) : null;
609
+ }
610
+ function definitionAt(text, line, joins) {
611
+ if (text[line.content] !== '[')
612
+ return null;
613
+ const close = referenceEnd(text, line.content + 1, joins);
614
+ if (close === -1 || text[close] !== ':')
615
+ return null;
616
+ const id = labelKeyAt(text, line.content + 1, close - 1);
617
+ if (id === '')
618
+ return null;
619
+ const from = close + 1;
620
+ let end = endOfLine(text, from);
621
+ let occurrence = definitionDestination(text, from, end);
269
622
  if (occurrence === null) {
270
- if (text.slice(from, line.end).trim() !== '' || next >= text.length) return null;
271
- const end = endOfLine(text, next);
272
- occurrence = definitionDestination(text, readLine(text, next, end).content, end);
273
- if (occurrence === null) return null;
274
- next = afterLine(text, end);
623
+ if (text.slice(from, end).trim() !== '' || !joins.has(end))
624
+ return null;
625
+ const start = end + 1;
626
+ end = endOfLine(text, start);
627
+ occurrence = definitionDestination(text, afterIndent(text, readLine(text, start, end)), end);
628
+ if (occurrence === null)
629
+ return null;
275
630
  }
276
- if (next < text.length) {
277
- const end = endOfLine(text, next);
278
- if (TITLE.test(lineText(text, readLine(text, next, end)))) next = afterLine(text, end);
631
+ const rest = text.slice(occurrence.end, end);
632
+ if (!BLANK.test(rest)) {
633
+ const gap = GAP.exec(rest);
634
+ const titled = gap === null ? null : titleEnd(text, occurrence.end + gap[0].length, joins);
635
+ return titled === null ? null : { id, occurrence, next: titled };
279
636
  }
280
- return {
281
- id,
282
- occurrence,
283
- next
284
- };
637
+ const next = afterLine(text, end);
638
+ if (joins.has(end)) {
639
+ const titled = titleEnd(text, afterIndent(text, readLine(text, next, endOfLine(text, next))), joins);
640
+ if (titled !== null)
641
+ return { id, occurrence, next: titled };
642
+ }
643
+ return { id, occurrence, next };
285
644
  }
286
645
  function endsBlock(content) {
287
646
  return HEADING.test(content) || BREAK.test(content) || SETEXT.test(content);
288
647
  }
289
648
  function scanBlocks(text) {
290
- const fences = [];
649
+ const { joins, raw } = structure(text);
650
+ const rawEnd = spanCursor(raw);
291
651
  const definitions = new Map();
292
652
  const blocks = [];
293
- let paragraph = false;
294
- let depth = 0;
653
+ let fresh = 0;
295
654
  let i = 0;
296
- while(i < text.length){
297
- const line = readLine(text, i, endOfLine(text, i));
298
- if (line.depth !== depth || line.item) paragraph = false;
299
- depth = line.depth;
300
- const open = fenceAt(text, line);
301
- if (open !== null) {
302
- const stop = fenceSpan(text, line, open);
303
- fences.push([
304
- i,
305
- stop
306
- ]);
307
- paragraph = false;
308
- i = stop;
309
- continue;
310
- }
311
- const content = lineText(text, line);
312
- if (content.trim() === '') {
313
- paragraph = false;
314
- i = afterLine(text, line.end);
655
+ while (i < text.length) {
656
+ const skip = rawEnd(i);
657
+ if (skip !== undefined) {
658
+ i = skip;
315
659
  continue;
316
660
  }
317
- const definition = paragraph ? null : definitionAt(text, line);
661
+ const line = readLine(text, i, endOfLine(text, i));
662
+ const definition = lineText(text, line).trim() === '' || (i !== fresh && joins.has(i - 1))
663
+ ? null
664
+ : definitionAt(text, line, joins);
318
665
  if (definition !== null) {
319
- if (!definitions.has(definition.id)) definitions.set(definition.id, definition.occurrence);
320
- blocks.push({
321
- start: line.start,
322
- end: definition.next,
323
- destination: definition.occurrence
324
- });
666
+ if (!definitions.has(definition.id))
667
+ definitions.set(definition.id, definition.occurrence);
668
+ blocks.push({ start: line.start, end: definition.next, destination: definition.occurrence });
325
669
  i = definition.next;
670
+ fresh = i;
326
671
  continue;
327
672
  }
328
- paragraph = !endsBlock(content);
329
673
  i = afterLine(text, line.end);
330
674
  }
331
- return {
332
- fences,
333
- definitions,
334
- blocks
675
+ return { raw, definitions, blocks, joins };
676
+ }
677
+ export function spanCursor(spans) {
678
+ let next = 0;
679
+ return (index) => {
680
+ while (next < spans.length && spans[next][1] <= index)
681
+ next += 1;
682
+ const span = spans[next];
683
+ return span !== undefined && span[0] <= index ? span[1] : undefined;
335
684
  };
336
685
  }
337
- function fenceEndAt(spans, index) {
338
- for (const [start, end] of spans){
339
- if (index >= start && index < end) return end;
686
+ export function fenceSpans(text) {
687
+ const fences = [];
688
+ let i = 0;
689
+ while (i < text.length) {
690
+ const line = readLine(text, i, endOfLine(text, i));
691
+ const open = fenceAt(text, line);
692
+ if (open === null) {
693
+ i = afterLine(text, line.end);
694
+ continue;
695
+ }
696
+ const stop = fenceSpan(text, line, open);
697
+ fences.push([i, stop]);
698
+ i = stop;
699
+ }
700
+ return fences;
701
+ }
702
+ function paragraphEnd(text, from, joins) {
703
+ let i = from;
704
+ while (i < text.length) {
705
+ if (text[i] === '\n' && !joins.has(i))
706
+ return i;
707
+ if (text[i] === '\r' && text[i + 1] !== '\n')
708
+ return i;
709
+ i += 1;
340
710
  }
341
- return undefined;
711
+ return i;
342
712
  }
343
713
  export function linkInventory(body) {
344
- const { fences, definitions, blocks } = scanBlocks(body);
714
+ const { raw, definitions, blocks, joins } = scanBlocks(body);
715
+ const rawEnd = spanCursor(raw);
716
+ const blockEnd = spanCursor(blocks.map((block) => [block.start, block.end]));
345
717
  const uses = [];
718
+ const openers = [];
719
+ const unclosed = { stop: 0, runs: new Map() };
720
+ let paragraph = { start: 0, end: -1, text: '' };
346
721
  let i = 0;
347
- while(i < body.length){
348
- const fenceEnd = fenceEndAt(fences, i);
349
- if (fenceEnd !== undefined) {
350
- i = fenceEnd;
722
+ while (i < body.length) {
723
+ const skipEnd = rawEnd(i) ?? blockEnd(i);
724
+ if (skipEnd !== undefined) {
725
+ openers.length = 0;
726
+ i = skipEnd;
727
+ continue;
728
+ }
729
+ const ch = body[i];
730
+ if (escapes(body, i)) {
731
+ i += 2;
351
732
  continue;
352
733
  }
353
- if (body[i] === '`') {
354
- i = skipInlineCode(body, i);
734
+ if (ch === '`') {
735
+ i = skipInlineCode(body, i, joins, unclosed);
355
736
  continue;
356
737
  }
357
- if (body[i] === '!' && body[i + 1] === '[') {
358
- i = takeLink(body, i + 1, i, uses, definitions);
738
+ if (ch === '<') {
739
+ if (i >= paragraph.end) {
740
+ const end = paragraphEnd(body, i, joins);
741
+ paragraph = { start: i, end, text: body.slice(i, end) };
742
+ }
743
+ INLINE_RAW.lastIndex = i - paragraph.start;
744
+ const raw = INLINE_RAW.exec(paragraph.text);
745
+ if (raw !== null) {
746
+ i += raw[0].length;
747
+ continue;
748
+ }
749
+ }
750
+ if ((ch === '\n' && !joins.has(i)) || (ch === '\r' && body[i + 1] !== '\n'))
751
+ openers.length = 0;
752
+ if (ch === '[' || (ch === '!' && body[i + 1] === '[')) {
753
+ const previous = openers.at(-1);
754
+ if (previous !== undefined)
755
+ previous.bracketAfter = true;
756
+ const image = ch === '!';
757
+ openers.push({ at: image ? i + 1 : i, start: i, image, active: true, bracketAfter: false });
758
+ i += image ? 2 : 1;
359
759
  continue;
360
760
  }
361
- if (body[i] === '[') {
362
- i = takeLink(body, i, i, uses, definitions);
761
+ if (ch === ']') {
762
+ const opener = openers.pop();
763
+ const use = opener?.active ? closeLink(body, opener, i, definitions, joins) : null;
764
+ if (opener === undefined || use === null) {
765
+ i += 1;
766
+ continue;
767
+ }
768
+ uses.push(use);
769
+ if (!opener.image)
770
+ for (const earlier of openers)
771
+ if (!earlier.image)
772
+ earlier.active = false;
773
+ i = use.end;
363
774
  continue;
364
775
  }
365
776
  i += 1;
366
777
  }
367
- return {
368
- uses,
369
- blocks
370
- };
778
+ return { uses, blocks };
371
779
  }
372
- export function hrefOccurrences(body) {
780
+ export function destinations(inventory) {
373
781
  const byStart = new Map();
374
- for (const use of linkInventory(body).uses)byStart.set(use.destination.start, use.destination);
375
- return [
376
- ...byStart.values()
377
- ].sort((left, right)=>left.start - right.start);
782
+ for (const use of inventory.uses)
783
+ byStart.set(use.destination.start, use.destination);
784
+ return [...byStart.values()].sort((left, right) => left.start - right.start);
785
+ }
786
+ export function hrefOccurrences(body) {
787
+ return destinations(linkInventory(body));
378
788
  }
379
-
380
- //# sourceMappingURL=links.js.map