@agentshouse/mdmodel 0.1.0-c2987f5d89720 → 0.1.0-c2e6f0cf254e0

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