@agentshouse/mdmodel 0.1.0-ce4af152f38d8 → 0.1.0-ce6172ed6fa4c

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