@agentshouse/mdmodel 0.1.0-cd90851746292 → 0.1.0-cdaa2262b2988

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