@tickernelz/paperclip-pro-server 2026.927.0 → 2026.927.1

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 (202) hide show
  1. package/dist/build-info.json +1 -1
  2. package/dist/routes/issues.d.ts.map +1 -1
  3. package/dist/routes/issues.js +174 -45
  4. package/dist/routes/issues.js.map +1 -1
  5. package/dist/routes/openapi.d.ts.map +1 -1
  6. package/dist/routes/openapi.js +1 -0
  7. package/dist/routes/openapi.js.map +1 -1
  8. package/dist/services/instance-settings.d.ts.map +1 -1
  9. package/dist/services/instance-settings.js +3 -1
  10. package/dist/services/instance-settings.js.map +1 -1
  11. package/node_modules/mdast-util-to-markdown/index.d.ts +2 -0
  12. package/node_modules/mdast-util-to-markdown/lib/configure.d.ts +5 -0
  13. package/node_modules/mdast-util-to-markdown/lib/configure.d.ts.map +1 -1
  14. package/node_modules/mdast-util-to-markdown/lib/configure.js +19 -0
  15. package/node_modules/mdast-util-to-markdown/lib/handle/blockquote.d.ts +7 -0
  16. package/node_modules/mdast-util-to-markdown/lib/handle/blockquote.d.ts.map +1 -1
  17. package/node_modules/mdast-util-to-markdown/lib/handle/blockquote.js +12 -1
  18. package/node_modules/mdast-util-to-markdown/lib/handle/break.d.ts +7 -0
  19. package/node_modules/mdast-util-to-markdown/lib/handle/break.d.ts.map +1 -1
  20. package/node_modules/mdast-util-to-markdown/lib/handle/break.js +16 -5
  21. package/node_modules/mdast-util-to-markdown/lib/handle/code.d.ts +7 -0
  22. package/node_modules/mdast-util-to-markdown/lib/handle/code.d.ts.map +1 -1
  23. package/node_modules/mdast-util-to-markdown/lib/handle/code.js +13 -2
  24. package/node_modules/mdast-util-to-markdown/lib/handle/definition.d.ts +7 -0
  25. package/node_modules/mdast-util-to-markdown/lib/handle/definition.d.ts.map +1 -1
  26. package/node_modules/mdast-util-to-markdown/lib/handle/definition.js +7 -0
  27. package/node_modules/mdast-util-to-markdown/lib/handle/emphasis.d.ts +30 -2
  28. package/node_modules/mdast-util-to-markdown/lib/handle/emphasis.d.ts.map +1 -1
  29. package/node_modules/mdast-util-to-markdown/lib/handle/emphasis.js +39 -41
  30. package/node_modules/mdast-util-to-markdown/lib/handle/heading.d.ts +7 -0
  31. package/node_modules/mdast-util-to-markdown/lib/handle/heading.d.ts.map +1 -1
  32. package/node_modules/mdast-util-to-markdown/lib/handle/heading.js +11 -2
  33. package/node_modules/mdast-util-to-markdown/lib/handle/html.d.ts +7 -0
  34. package/node_modules/mdast-util-to-markdown/lib/handle/html.d.ts.map +1 -1
  35. package/node_modules/mdast-util-to-markdown/lib/handle/html.js +7 -0
  36. package/node_modules/mdast-util-to-markdown/lib/handle/image-reference.d.ts +10 -0
  37. package/node_modules/mdast-util-to-markdown/lib/handle/image-reference.d.ts.map +1 -1
  38. package/node_modules/mdast-util-to-markdown/lib/handle/image-reference.js +17 -2
  39. package/node_modules/mdast-util-to-markdown/lib/handle/image.d.ts +10 -0
  40. package/node_modules/mdast-util-to-markdown/lib/handle/image.d.ts.map +1 -1
  41. package/node_modules/mdast-util-to-markdown/lib/handle/image.js +10 -0
  42. package/node_modules/mdast-util-to-markdown/lib/handle/inline-code.d.ts +9 -0
  43. package/node_modules/mdast-util-to-markdown/lib/handle/inline-code.d.ts.map +1 -1
  44. package/node_modules/mdast-util-to-markdown/lib/handle/inline-code.js +14 -4
  45. package/node_modules/mdast-util-to-markdown/lib/handle/link-reference.d.ts +10 -0
  46. package/node_modules/mdast-util-to-markdown/lib/handle/link-reference.d.ts.map +1 -1
  47. package/node_modules/mdast-util-to-markdown/lib/handle/link-reference.js +17 -2
  48. package/node_modules/mdast-util-to-markdown/lib/handle/link.d.ts +13 -0
  49. package/node_modules/mdast-util-to-markdown/lib/handle/link.d.ts.map +1 -1
  50. package/node_modules/mdast-util-to-markdown/lib/handle/link.js +24 -9
  51. package/node_modules/mdast-util-to-markdown/lib/handle/list-item.d.ts +7 -0
  52. package/node_modules/mdast-util-to-markdown/lib/handle/list-item.d.ts.map +1 -1
  53. package/node_modules/mdast-util-to-markdown/lib/handle/list-item.js +12 -1
  54. package/node_modules/mdast-util-to-markdown/lib/handle/list.d.ts +7 -0
  55. package/node_modules/mdast-util-to-markdown/lib/handle/list.d.ts.map +1 -1
  56. package/node_modules/mdast-util-to-markdown/lib/handle/list.js +7 -0
  57. package/node_modules/mdast-util-to-markdown/lib/handle/paragraph.d.ts +7 -0
  58. package/node_modules/mdast-util-to-markdown/lib/handle/paragraph.d.ts.map +1 -1
  59. package/node_modules/mdast-util-to-markdown/lib/handle/paragraph.js +7 -0
  60. package/node_modules/mdast-util-to-markdown/lib/handle/root.d.ts +7 -0
  61. package/node_modules/mdast-util-to-markdown/lib/handle/root.d.ts.map +1 -1
  62. package/node_modules/mdast-util-to-markdown/lib/handle/root.js +13 -2
  63. package/node_modules/mdast-util-to-markdown/lib/handle/strong.d.ts +30 -2
  64. package/node_modules/mdast-util-to-markdown/lib/handle/strong.d.ts.map +1 -1
  65. package/node_modules/mdast-util-to-markdown/lib/handle/strong.js +39 -41
  66. package/node_modules/mdast-util-to-markdown/lib/handle/text.d.ts +7 -0
  67. package/node_modules/mdast-util-to-markdown/lib/handle/text.d.ts.map +1 -1
  68. package/node_modules/mdast-util-to-markdown/lib/handle/text.js +7 -0
  69. package/node_modules/mdast-util-to-markdown/lib/handle/thematic-break.d.ts +6 -0
  70. package/node_modules/mdast-util-to-markdown/lib/handle/thematic-break.d.ts.map +1 -1
  71. package/node_modules/mdast-util-to-markdown/lib/handle/thematic-break.js +6 -0
  72. package/node_modules/mdast-util-to-markdown/lib/index.d.ts.map +1 -1
  73. package/node_modules/mdast-util-to-markdown/lib/index.js +34 -8
  74. package/node_modules/mdast-util-to-markdown/lib/join.d.ts.map +1 -1
  75. package/node_modules/mdast-util-to-markdown/lib/join.js +18 -1
  76. package/node_modules/mdast-util-to-markdown/lib/types.d.ts +50 -30
  77. package/node_modules/mdast-util-to-markdown/lib/unsafe.d.ts.map +1 -1
  78. package/node_modules/mdast-util-to-markdown/lib/unsafe.js +15 -1
  79. package/node_modules/mdast-util-to-markdown/lib/util/character.d.ts +23 -0
  80. package/node_modules/mdast-util-to-markdown/lib/util/character.d.ts.map +1 -0
  81. package/node_modules/mdast-util-to-markdown/lib/util/character.js +32 -0
  82. package/node_modules/mdast-util-to-markdown/lib/util/check-bullet-ordered.d.ts +4 -0
  83. package/node_modules/mdast-util-to-markdown/lib/util/check-bullet-ordered.d.ts.map +1 -1
  84. package/node_modules/mdast-util-to-markdown/lib/util/check-bullet-ordered.js +4 -0
  85. package/node_modules/mdast-util-to-markdown/lib/util/check-bullet-other.d.ts +4 -0
  86. package/node_modules/mdast-util-to-markdown/lib/util/check-bullet-other.d.ts.map +1 -1
  87. package/node_modules/mdast-util-to-markdown/lib/util/check-bullet-other.js +4 -0
  88. package/node_modules/mdast-util-to-markdown/lib/util/check-bullet.d.ts +4 -0
  89. package/node_modules/mdast-util-to-markdown/lib/util/check-bullet.d.ts.map +1 -1
  90. package/node_modules/mdast-util-to-markdown/lib/util/check-bullet.js +4 -0
  91. package/node_modules/mdast-util-to-markdown/lib/util/check-emphasis.d.ts +4 -0
  92. package/node_modules/mdast-util-to-markdown/lib/util/check-emphasis.d.ts.map +1 -1
  93. package/node_modules/mdast-util-to-markdown/lib/util/check-emphasis.js +4 -0
  94. package/node_modules/mdast-util-to-markdown/lib/util/check-fence.d.ts +4 -0
  95. package/node_modules/mdast-util-to-markdown/lib/util/check-fence.d.ts.map +1 -1
  96. package/node_modules/mdast-util-to-markdown/lib/util/check-fence.js +4 -0
  97. package/node_modules/mdast-util-to-markdown/lib/util/check-list-item-indent.d.ts +4 -0
  98. package/node_modules/mdast-util-to-markdown/lib/util/check-list-item-indent.d.ts.map +1 -1
  99. package/node_modules/mdast-util-to-markdown/lib/util/check-list-item-indent.js +4 -0
  100. package/node_modules/mdast-util-to-markdown/lib/util/check-quote.d.ts +4 -0
  101. package/node_modules/mdast-util-to-markdown/lib/util/check-quote.d.ts.map +1 -1
  102. package/node_modules/mdast-util-to-markdown/lib/util/check-quote.js +4 -0
  103. package/node_modules/mdast-util-to-markdown/lib/util/check-rule-repetition.d.ts +4 -0
  104. package/node_modules/mdast-util-to-markdown/lib/util/check-rule-repetition.d.ts.map +1 -1
  105. package/node_modules/mdast-util-to-markdown/lib/util/check-rule-repetition.js +4 -0
  106. package/node_modules/mdast-util-to-markdown/lib/util/check-rule.d.ts +4 -0
  107. package/node_modules/mdast-util-to-markdown/lib/util/check-rule.d.ts.map +1 -1
  108. package/node_modules/mdast-util-to-markdown/lib/util/check-rule.js +4 -0
  109. package/node_modules/mdast-util-to-markdown/lib/util/check-strong.d.ts +4 -0
  110. package/node_modules/mdast-util-to-markdown/lib/util/check-strong.d.ts.map +1 -1
  111. package/node_modules/mdast-util-to-markdown/lib/util/check-strong.js +4 -0
  112. package/node_modules/mdast-util-to-markdown/lib/util/compile-pattern.js +3 -1
  113. package/node_modules/mdast-util-to-markdown/lib/util/container-flow.d.ts +2 -0
  114. package/node_modules/mdast-util-to-markdown/lib/util/container-flow.d.ts.map +1 -1
  115. package/node_modules/mdast-util-to-markdown/lib/util/container-flow.js +9 -0
  116. package/node_modules/mdast-util-to-markdown/lib/util/container-phrasing.d.ts +95 -4
  117. package/node_modules/mdast-util-to-markdown/lib/util/container-phrasing.d.ts.map +1 -1
  118. package/node_modules/mdast-util-to-markdown/lib/util/container-phrasing.js +636 -57
  119. package/node_modules/mdast-util-to-markdown/lib/util/encode-info.d.ts +2 -2
  120. package/node_modules/mdast-util-to-markdown/lib/util/encode-info.d.ts.map +1 -1
  121. package/node_modules/mdast-util-to-markdown/lib/util/encode-info.js +1 -1
  122. package/node_modules/mdast-util-to-markdown/lib/util/format-code-as-indented.d.ts +5 -0
  123. package/node_modules/mdast-util-to-markdown/lib/util/format-code-as-indented.d.ts.map +1 -1
  124. package/node_modules/mdast-util-to-markdown/lib/util/format-code-as-indented.js +12 -7
  125. package/node_modules/mdast-util-to-markdown/lib/util/format-heading-as-setext.d.ts +5 -0
  126. package/node_modules/mdast-util-to-markdown/lib/util/format-heading-as-setext.d.ts.map +1 -1
  127. package/node_modules/mdast-util-to-markdown/lib/util/format-heading-as-setext.js +7 -2
  128. package/node_modules/mdast-util-to-markdown/lib/util/format-link-as-autolink.d.ts +5 -0
  129. package/node_modules/mdast-util-to-markdown/lib/util/format-link-as-autolink.d.ts.map +1 -1
  130. package/node_modules/mdast-util-to-markdown/lib/util/format-link-as-autolink.js +20 -15
  131. package/node_modules/mdast-util-to-markdown/lib/util/html-kind.d.ts +31 -0
  132. package/node_modules/mdast-util-to-markdown/lib/util/html-kind.d.ts.map +1 -0
  133. package/node_modules/mdast-util-to-markdown/lib/util/html-kind.js +63 -0
  134. package/node_modules/mdast-util-to-markdown/lib/util/indent-lines.js +5 -0
  135. package/node_modules/mdast-util-to-markdown/lib/util/pattern-in-scope.d.ts +5 -0
  136. package/node_modules/mdast-util-to-markdown/lib/util/pattern-in-scope.d.ts.map +1 -1
  137. package/node_modules/mdast-util-to-markdown/lib/util/pattern-in-scope.js +11 -0
  138. package/node_modules/mdast-util-to-markdown/lib/util/safe.d.ts +2 -2
  139. package/node_modules/mdast-util-to-markdown/lib/util/safe.d.ts.map +1 -1
  140. package/node_modules/mdast-util-to-markdown/lib/util/safe.js +71 -7
  141. package/node_modules/mdast-util-to-markdown/package.json +13 -57
  142. package/node_modules/mdast-util-to-markdown/readme.md +139 -84
  143. package/package.json +21 -21
  144. package/ui-dist/assets/{AgentAvatar-RxjiAwO8.js → AgentAvatar-PT82VwmU.js} +1 -1
  145. package/ui-dist/assets/{AgentIdentity-D4BY0hNL.js → AgentIdentity-MCshmbhZ.js} +1 -1
  146. package/ui-dist/assets/{Agents.production-gcp98JXS.js → Agents.production-M_NY58co.js} +2 -2
  147. package/ui-dist/assets/{CompanyActivity.production-CWlPErYS.js → CompanyActivity.production-DYQKd80o.js} +1 -1
  148. package/ui-dist/assets/{CompanyExport-JunkVVGm.js → CompanyExport-Ch4DvzDC.js} +1 -1
  149. package/ui-dist/assets/{CompanySkills.production-DvSrjYfs.js → CompanySkills.production-BGOAW-TP.js} +1 -1
  150. package/ui-dist/assets/{Costs.production-zx6HrqRG.js → Costs.production-AiD1rIrs.js} +1 -1
  151. package/ui-dist/assets/{EmptyState-DfjPe-d3.js → EmptyState-DPcc0zYh.js} +1 -1
  152. package/ui-dist/assets/{MarkdownBody-CsD5-bu_.js → MarkdownBody-D0eCfSWN.js} +1 -1
  153. package/ui-dist/assets/{MarkdownEditor-p2rnT0Be.js → MarkdownEditor-Pip4OXiJ.js} +49 -49
  154. package/ui-dist/assets/{OrgChart.production-C-wrmuDn.js → OrgChart.production-WmGsXZUQ.js} +1 -1
  155. package/ui-dist/assets/{PageSkeleton-CFPaR2xk.js → PageSkeleton-DHjTwRT3.js} +1 -1
  156. package/ui-dist/assets/{RoutineDetail.production-Skb6CK8y.js → RoutineDetail.production-B8ydFpMP.js} +1 -1
  157. package/ui-dist/assets/{RoutineRunVariablesDialog-BWeOhxiO.js → RoutineRunVariablesDialog-IRX4TLng.js} +1 -1
  158. package/ui-dist/assets/{Routines.production-TpFNwHyG.js → Routines.production-Bcb1R-Uu.js} +1 -1
  159. package/ui-dist/assets/{SidebarContext-bqQ25oRc.js → SidebarContext-D01pu4wh.js} +1 -1
  160. package/ui-dist/assets/{StatusIcon-BJoaLFpW.js → StatusIcon-BuUYMqqU.js} +1 -1
  161. package/ui-dist/assets/{agents-D79f8ubB.js → agents-BlSzFh-1.js} +1 -1
  162. package/ui-dist/assets/{badge-Dtq5g7E6.js → badge-Cf7ihb3q.js} +1 -1
  163. package/ui-dist/assets/{bot-CuAIZ3O7.js → bot-DZDpMzjD.js} +1 -1
  164. package/ui-dist/assets/{button-BvVFpN4P.js → button-CAPbz11u.js} +1 -1
  165. package/ui-dist/assets/{card-Dt_3k83X.js → card-dmVcp3AX.js} +1 -1
  166. package/ui-dist/assets/{check-IIwgETIo.js → check-DDiXDm2i.js} +1 -1
  167. package/ui-dist/assets/{checkbox-Dt_GoRUY.js → checkbox-CmMbs2PZ.js} +1 -1
  168. package/ui-dist/assets/{chevron-down-UBZnuvt1.js → chevron-down-F9aZv-V7.js} +1 -1
  169. package/ui-dist/assets/{chevron-right-B0AHub3v.js → chevron-right-B9JUOr38.js} +1 -1
  170. package/ui-dist/assets/{clipboard-Bj5QAqRq.js → clipboard-CYJ5Q78m.js} +1 -1
  171. package/ui-dist/assets/{company-members-DEqvhrMC.js → company-members-BcZm1g8Q.js} +1 -1
  172. package/ui-dist/assets/createLucideIcon-r3v6fbGz.js +92 -0
  173. package/ui-dist/assets/{definition-wrbKkF1t.js → definition-Irgr7mY_.js} +1 -1
  174. package/ui-dist/assets/{dist-FWFKwYyU.js → dist-5v80Jc6A.js} +1 -1
  175. package/ui-dist/assets/{dist-VxTJitj7.js → dist-D1zgkcBw.js} +1 -1
  176. package/ui-dist/assets/{environments-CkEnfa1n.js → environments-BVeNFanj.js} +1 -1
  177. package/ui-dist/assets/{external-link-B35J81lc.js → external-link-0lrOvZWO.js} +1 -1
  178. package/ui-dist/assets/{file-text-CD47Bznz.js → file-text-C9vgFckt.js} +1 -1
  179. package/ui-dist/assets/{health-CfAQPRgq.js → health-DeeeogeJ.js} +1 -1
  180. package/ui-dist/assets/{heartbeats-DLceYe5K.js → heartbeats-CK_aXmx5.js} +1 -1
  181. package/ui-dist/assets/{index-qzns_tVc.js → index-F2pxxyIV.js} +153 -153
  182. package/ui-dist/assets/{input-CFI8T_fr.js → input-DpsS9it-.js} +1 -1
  183. package/ui-dist/assets/{label-JgSsn_gH.js → label-C2ddSDJj.js} +1 -1
  184. package/ui-dist/assets/{loader-circle-AYbv_YhN.js → loader-circle-BD9wx-lw.js} +1 -1
  185. package/ui-dist/assets/{mention-chips-DPVE_n2N.js → mention-chips-DXumPrOR.js} +1 -1
  186. package/ui-dist/assets/{octagon-alert-2PgnRbAG.js → octagon-alert-rGMwyrWA.js} +1 -1
  187. package/ui-dist/assets/{rotate-ccw-D72kg6zn.js → rotate-ccw-CRAQ3Xng.js} +1 -1
  188. package/ui-dist/assets/{router-BrCMx2mP.js → router-DyZkoSkG.js} +2 -2
  189. package/ui-dist/assets/{save-fTBYxOC9.js → save-DUnPDT6R.js} +1 -1
  190. package/ui-dist/assets/{select-BidMsZcD.js → select-mS22eY6T.js} +1 -1
  191. package/ui-dist/assets/{sheet-BAx2-UjA.js → sheet-DeCxNmfl.js} +1 -1
  192. package/ui-dist/assets/{skeleton-CYELISHD.js → skeleton-CKir8TUW.js} +1 -1
  193. package/ui-dist/assets/{tabs-D5oWPScx.js → tabs-DWRZjksg.js} +1 -1
  194. package/ui-dist/assets/{triangle-alert-DFzcyeFH.js → triangle-alert-CgJcxSQX.js} +1 -1
  195. package/ui-dist/assets/{use-adapter-capabilities-aPQHbB6R.js → use-adapter-capabilities-BiWYK4zJ.js} +1 -1
  196. package/ui-dist/assets/{useHiddenSettings-jRtbaks6.js → useHiddenSettings-2JpxuJV7.js} +1 -1
  197. package/ui-dist/assets/{zap-B3DNfTNV.js → zap-P-cXfK28.js} +1 -1
  198. package/ui-dist/index.html +45 -45
  199. package/ui-dist/sw.js +1 -1
  200. package/node_modules/mdast-util-to-markdown/lib/util/emphasis-strong-marker.d.ts +0 -7
  201. package/node_modules/mdast-util-to-markdown/lib/util/emphasis-strong-marker.d.ts.map +0 -1
  202. package/ui-dist/assets/createLucideIcon-eTR0JqwS.js +0 -92
@@ -1,33 +1,487 @@
1
1
  /**
2
- * @import {Handle, Info, State} from 'mdast-util-to-markdown'
2
+ * @import {Attention, Handle, Info, State} from 'mdast-util-to-markdown'
3
3
  * @import {PhrasingParents} from '../types.js'
4
4
  */
5
5
 
6
+ import {asciiPunctuation} from 'micromark-util-character'
7
+ import {classifyCharacter} from 'micromark-util-classify-character'
8
+ import {firstCharacter, lastCharacter} from './character.js'
6
9
  import {encodeCharacterReference} from './encode-character-reference.js'
10
+ import {encodeInfo} from './encode-info.js'
11
+ import {htmlKind} from './html-kind.js'
7
12
 
8
13
  /**
9
- * Serialize the children of a parent that contains phrasing children.
14
+ * Markers for builtin attention (emphasis, strong) to whether they are stricter:
15
+ * whether they cannot open and close inside words.
16
+ *
17
+ * Builtin runs pair following CommonMark rules for emphasis and strong:
18
+ * they are split,
19
+ * using one or two markers at a time,
20
+ * with the rule of 3.
21
+ * Other markers pair like GFM strikethrough:
22
+ * whole runs pair with a run of the same size.
23
+ *
24
+ * @type {Map<string, boolean>}
25
+ */
26
+ const builtins = new Map([
27
+ ['*', false],
28
+ ['_', true]
29
+ ])
30
+
31
+ /**
32
+ * @typedef AttentionResult
33
+ * Attention, of which the sequence is chosen later.
34
+ * @property {Array<Item>} children
35
+ * Serialized children.
36
+ * @property {Array<string>} sequences
37
+ * Sequences that can be used, in order of preference.
38
+ */
39
+
40
+ /**
41
+ * @typedef Improvement
42
+ * Improvement of attention sequences.
43
+ * @property {Map<AttentionResult, string>} chosen
44
+ * Chosen sequences for each attention.
45
+ * @property {Array<Token>} tokens
46
+ * Tokens involved in the improvement.
47
+ * @property {Mistake | undefined} mistake
48
+ * Mistake that led to this improvement, if any.
49
+ */
50
+
51
+ /**
52
+ * @typedef {AttentionResult | string} Item
53
+ * Serialized phrasing.
54
+ */
55
+
56
+ /**
57
+ * @typedef Mistake
58
+ * Sequence that does not form its attention.
59
+ * @property {Array<AttentionResult>} attention
60
+ * Attention to try other sequences for.
61
+ * @property {number} index
62
+ * Index of the token.
63
+ */
64
+
65
+ /**
66
+ * @typedef Run
67
+ * Sequences next to each other with the same marker.
68
+ * @property {boolean} close
69
+ * Whether it can close.
70
+ * @property {number} end
71
+ * Index after the last marker not used (to open).
72
+ * @property {Array<Token>} markers
73
+ * Sequence of each marker.
74
+ * @property {boolean} open
75
+ * Whether it can open.
76
+ * @property {boolean} split
77
+ * Whether it can be split (built-in attention).
78
+ * @property {number} start
79
+ * Index of the first marker not used (to close).
80
+ * @property {Array<Token>} tokens
81
+ * Sequences.
82
+ */
83
+
84
+ /**
85
+ * @typedef Token
86
+ * Rendered phrasing.
87
+ * @property {AttentionResult | undefined} attention
88
+ * Attention, if this is one of its sequences.
89
+ * @property {string} value
90
+ * Value.
91
+ */
92
+
93
+ /**
94
+ * Get candidates for a mistake:
95
+ * attention to try other sequences for,
96
+ * later first.
97
+ *
98
+ * @param {Array<Token>} tokens
99
+ * Tokens.
100
+ * @param {Array<Token>} involved
101
+ * Sequences involved in the mistake.
102
+ * @param {Map<Token, Run>} runOf
103
+ * Run of each sequence.
104
+ * @returns {Array<AttentionResult>}
105
+ * Candidates.
106
+ */
107
+ function candidates(tokens, involved, runOf) {
108
+ /** @type {Set<AttentionResult | undefined>} */
109
+ const related = new Set()
110
+
111
+ // The attention involved, and attention in runs with its sequences.
112
+ for (const token of tokens) {
113
+ const siblings = runOf.get(token)
114
+ if (
115
+ siblings &&
116
+ token.attention &&
117
+ involved.some((d) => d.attention === token.attention)
118
+ ) {
119
+ for (const sibling of siblings.tokens) {
120
+ related.add(sibling.attention)
121
+ }
122
+ }
123
+ }
124
+
125
+ /** @type {Array<AttentionResult>} */
126
+ const ordered = []
127
+
128
+ for (const token of tokens) {
129
+ if (token.attention && related.delete(token.attention)) {
130
+ ordered.push(token.attention)
131
+ }
132
+ }
133
+
134
+ // Later first: attention that opens later is inner or next.
135
+ ordered.reverse()
136
+ return ordered
137
+ }
138
+
139
+ /**
140
+ * Check whether sequences form their attention, like `micromark`.
141
+ *
142
+ * Sequences of `*` and `_` pair like emphasis and strong in CommonMark,
143
+ * others like strikethrough in GFM.
10
144
  *
11
- * These children will be joined flush together.
145
+ * @param {Array<Token>} tokens
146
+ * Tokens.
147
+ * @param {string} before
148
+ * Characters before.
149
+ * @param {string} after
150
+ * Characters after.
151
+ * @returns {Mistake | undefined}
152
+ * First mistake, if any.
153
+ */
154
+ function check(tokens, before, after) {
155
+ /** @type {Array<Run>} */
156
+ const runs = []
157
+ /** @type {Map<Token, Array<Token>>} */
158
+ const wrong = new Map()
159
+ /** @type {Map<Token, Run>} */
160
+ const runOf = new Map()
161
+ let index = 0
162
+
163
+ while (index < tokens.length) {
164
+ if (!tokens[index].attention) {
165
+ index++
166
+ continue
167
+ }
168
+
169
+ const marker = tokens[index].value.charAt(0)
170
+ const strict = builtins.get(marker)
171
+ let end = index + 1
172
+
173
+ while (
174
+ end < tokens.length &&
175
+ tokens[end].attention &&
176
+ tokens[end].value.charAt(0) === marker
177
+ ) {
178
+ end++
179
+ }
180
+
181
+ const head = index ? tokens[index - 1].value : before
182
+ const previous = classifyCharacter(head.charCodeAt(head.length - 1))
183
+ const next = classifyCharacter(
184
+ (end < tokens.length ? tokens[end].value : after).charCodeAt(0)
185
+ )
186
+ const open = !next || (next === 2 && Boolean(previous))
187
+ const close = !previous || (previous === 2 && Boolean(next))
188
+ /** @type {Run} */
189
+ const run = {
190
+ tokens: tokens.slice(index, end),
191
+ markers: [],
192
+ start: 0,
193
+ end: 0,
194
+ // Underscores are strict, they cannot open or close inside words.
195
+ open: strict ? open && (Boolean(previous) || !close) : open,
196
+ close: strict ? close && (Boolean(next) || !open) : close,
197
+ // All builtins can split runs.
198
+ split: strict !== undefined
199
+ }
200
+
201
+ for (const token of run.tokens) {
202
+ // Every sequence is wrong until it pairs with its other sequence.
203
+ wrong.set(token, [...run.tokens])
204
+ runOf.set(token, run)
205
+ let size = token.value.length
206
+ while (size--) run.markers.push(token)
207
+ }
208
+
209
+ run.end = run.markers.length
210
+ runs.push(run)
211
+ index = end
212
+ }
213
+
214
+ pair(runs, wrong)
215
+
216
+ index = -1
217
+
218
+ while (++index < tokens.length) {
219
+ const involved = wrong.get(tokens[index])
220
+ if (involved) return {attention: candidates(tokens, involved, runOf), index}
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Serialize the children of a parent that contains phrasing children.
12
226
  *
13
227
  * @param {PhrasingParents} parent
14
- * Parent of flow nodes.
228
+ * Parent of phrasing nodes.
15
229
  * @param {State} state
16
230
  * Info passed around about the current state.
17
231
  * @param {Info} info
18
232
  * Info on where we are in the document we are generating.
19
233
  * @returns {string}
20
- * Serialized children, joined together.
234
+ * Serialized result.
21
235
  */
22
236
  export function containerPhrasing(parent, state, info) {
237
+ return serialize(phrasing(parent, state, info), info.before, info.after)
238
+ }
239
+
240
+ /**
241
+ * Encode the first or last character of tokens as a character reference,
242
+ * if it is text.
243
+ *
244
+ * @param {Array<Token>} tokens
245
+ * Tokens.
246
+ * @param {boolean} start
247
+ * Whether to encode the first or last character.
248
+ * @returns {undefined}
249
+ * Nothing.
250
+ */
251
+ function encode(tokens, start) {
252
+ const token = tokens[start ? 0 : tokens.length - 1]
253
+
254
+ if (!token || token.attention) return
255
+
256
+ const character = start
257
+ ? firstCharacter(token.value)
258
+ : lastCharacter(token.value)
259
+ const reference = encodeCharacterReference(
260
+ /** @type {number} */ (character.codePointAt(0))
261
+ )
262
+
263
+ token.value = start
264
+ ? reference + token.value.slice(character.length)
265
+ : token.value.slice(0, token.value.length - character.length) + reference
266
+ }
267
+
268
+ /**
269
+ * Try other sequences for the candidates of a mistake and use the first that
270
+ * moves the mistake further.
271
+ *
272
+ * @param {Array<Item>} items
273
+ * Items.
274
+ * @param {Map<AttentionResult, string>} chosen
275
+ * Sequences to use instead of preferred sequences.
276
+ * @param {Mistake} mistake
277
+ * Mistake.
278
+ * @param {string} before
279
+ * Characters before.
280
+ * @param {string} after
281
+ * Characters after.
282
+ * @returns {Improvement | undefined}
283
+ * Result if better.
284
+ */
285
+ function improve(items, chosen, mistake, before, after) {
286
+ for (const attention of mistake.attention) {
287
+ const current = chosen.get(attention) || attention.sequences[0]
288
+
289
+ for (const sequence of attention.sequences) {
290
+ if (sequence === current) continue
291
+ const trial = new Map(chosen)
292
+ trial.set(attention, sequence)
293
+ const tokens = render(items, trial, before, after)
294
+ const next = check(tokens, before, after)
295
+
296
+ if (!next || next.index > mistake.index) {
297
+ return {chosen: trial, mistake: next, tokens}
298
+ }
299
+ }
300
+ }
301
+ }
302
+
303
+ /**
304
+ * Pair runs like `micromark` and mark sequences that do form their attention
305
+ * as fine.
306
+ *
307
+ * Each pair uses markers from the end of an opener and the start of a closer.
308
+ * It forms the intended attention if those markers are exactly the whole
309
+ * opening and closing sequence of one attention.
310
+ * Otherwise attention is mixed up:
311
+ * either sequences of different attention pair,
312
+ * part of a sequence is used (such as `**` of strong as `*`),
313
+ * or several sequences are used together (such as `*` and `*` as `**`).
314
+ * Then the sequences involved are recorded with each other.
315
+ *
316
+ * @param {Array<Run>} runs
317
+ * Runs.
318
+ * @param {Map<Token, Array<Token>>} wrong
319
+ * Sequences that are wrong, with the sequences involved.
320
+ * @returns {undefined}
321
+ * Nothing, `wrong` is changed.
322
+ */
323
+ function pair(runs, wrong) {
324
+ let index = 0
325
+
326
+ while (index < runs.length) {
327
+ const closer = runs[index]
328
+ const marker = closer.tokens[0].value.charAt(0)
329
+ const closerSize = closer.end - closer.start
330
+ let open = closer.close && closerSize ? index : 0
331
+
332
+ while (open--) {
333
+ const opener = runs[open]
334
+ const openerSize = opener.end - opener.start
335
+
336
+ if (
337
+ opener.tokens[0].value.charAt(0) === marker &&
338
+ opener.open &&
339
+ openerSize &&
340
+ (closer.split
341
+ ? // The rule of 3, on the sizes that are left.
342
+ !((opener.close || closer.open) && closerSize % 3) ||
343
+ (openerSize + closerSize) % 3
344
+ : // Others pair whole runs of the same size.
345
+ openerSize === opener.markers.length && openerSize === closerSize)
346
+ ) {
347
+ const size = closer.split
348
+ ? openerSize > 1 && closerSize > 1
349
+ ? 2
350
+ : 1
351
+ : closerSize
352
+ const opening = opener.markers.slice(opener.end - size, opener.end)
353
+ const closing = closer.markers.slice(closer.start, closer.start + size)
354
+ const openToken = opening[0]
355
+ const closeToken = closing[0]
356
+
357
+ if (
358
+ // Whole sequences:
359
+ // the markers of a sequence are next to each other,
360
+ // so if the first and last marker are of one sequence of that size,
361
+ // all markers are exactly that sequence.
362
+ openToken === opening[size - 1] &&
363
+ openToken.value.length === size &&
364
+ closeToken === closing[size - 1] &&
365
+ closeToken.value.length === size &&
366
+ // Of the same attention, so its opening and closing sequence.
367
+ openToken.attention === closeToken.attention
368
+ ) {
369
+ wrong.delete(openToken)
370
+ wrong.delete(closeToken)
371
+ } else {
372
+ const involved = [...new Set([...opening, ...closing])]
373
+ // Add to what is involved already: a sequence can be in several pairs.
374
+ for (const token of involved) {
375
+ const list = wrong.get(token)
376
+ if (list) list.push(...involved)
377
+ }
378
+ }
379
+
380
+ opener.end -= size
381
+ closer.start += size
382
+ break
383
+ }
384
+ }
385
+
386
+ // Stay on this run if it can close more.
387
+ if (open === -1 || closer.start === closer.end) index++
388
+ }
389
+ }
390
+
391
+ /**
392
+ * Get the sequences that can be used for attention, in order of preference.
393
+ *
394
+ * @param {string} type
395
+ * Node type.
396
+ * @param {Array<string>} markers
397
+ * Markers.
398
+ * @param {Array<number>} sizes
399
+ * Sizes.
400
+ * @returns {Array<string>}
401
+ * Sequences.
402
+ */
403
+ function attentionSequences(type, markers, sizes) {
404
+ if (markers.length === 0) {
405
+ throw new Error(
406
+ 'Cannot serialize `' +
407
+ type +
408
+ '` as attention without markers, expected one or more markers'
409
+ )
410
+ }
411
+
412
+ if (sizes.length === 0) {
413
+ throw new Error(
414
+ 'Cannot serialize `' +
415
+ type +
416
+ '` as attention without sizes, expected one or more sizes'
417
+ )
418
+ }
419
+
420
+ for (const size of sizes) {
421
+ if (!Number.isSafeInteger(size) || size < 1) {
422
+ throw new Error(
423
+ 'Cannot serialize `' +
424
+ type +
425
+ '` as attention with `' +
426
+ size +
427
+ '` as size, expected positive integer'
428
+ )
429
+ }
430
+ }
431
+
432
+ /** @type {Array<string>} */
433
+ const sequences = []
434
+
435
+ for (const marker of markers) {
436
+ if (marker.length !== 1) {
437
+ throw new Error(
438
+ 'Cannot serialize `' +
439
+ type +
440
+ '` as attention with `' +
441
+ marker +
442
+ '` as marker, expected a single ascii character'
443
+ )
444
+ }
445
+
446
+ if (!asciiPunctuation(marker.charCodeAt(0))) {
447
+ throw new Error(
448
+ 'Cannot serialize `' +
449
+ type +
450
+ '` as attention with `' +
451
+ marker +
452
+ '` as marker, expected ascii punctuation'
453
+ )
454
+ }
455
+
456
+ for (const size of sizes) {
457
+ sequences.push(marker.repeat(size))
458
+ }
459
+ }
460
+
461
+ return sequences
462
+ }
463
+
464
+ /**
465
+ * Serialize the children of a parent that contains phrasing children,
466
+ * keeping attention separate,
467
+ * so that its markers can be chosen later.
468
+ *
469
+ * @param {PhrasingParents} parent
470
+ * Parent of phrasing nodes.
471
+ * @param {State} state
472
+ * Info passed around about the current state.
473
+ * @param {Info} info
474
+ * Info on where we are in the document we are generating.
475
+ * @returns {Array<Item>}
476
+ * Items.
477
+ */
478
+ function phrasing(parent, state, info) {
23
479
  const indexStack = state.indexStack
24
480
  const children = parent.children || []
25
- /** @type {Array<string>} */
481
+ /** @type {Array<Item>} */
26
482
  const results = []
27
483
  let index = -1
28
484
  let before = info.before
29
- /** @type {string | undefined} */
30
- let encodeAfter
31
485
 
32
486
  indexStack.push(-1)
33
487
  let tracker = state.createTracker(info)
@@ -43,83 +497,208 @@ export function containerPhrasing(parent, state, info) {
43
497
  /** @type {Handle} */
44
498
  // @ts-expect-error: hush, it’s actually a `zwitch`.
45
499
  let handle = state.handle.handlers[children[index + 1].type]
46
- /** @type {Handle} */
47
500
  // @ts-expect-error: hush, it’s actually a `zwitch`.
48
501
  if (handle && handle.peek) handle = handle.peek
49
502
  after = handle
50
- ? handle(children[index + 1], parent, state, {
51
- before: '',
52
- after: '',
53
- ...tracker.current()
54
- }).charAt(0)
503
+ ? firstCharacter(
504
+ handle(children[index + 1], parent, state, {
505
+ before: '',
506
+ after: '',
507
+ ...tracker.current()
508
+ })
509
+ )
55
510
  : ''
56
511
  } else {
57
512
  after = info.after
58
513
  }
59
514
 
60
515
  // In some cases, html (text) can be found in phrasing right after an eol.
61
- // When we’d serialize that, in most cases that would be seen as html
62
- // (flow).
63
- // As we can’t escape or so to prevent it from happening, we take a somewhat
64
- // reasonable approach: replace that eol with a space.
516
+ // When we’d serialize that, it could be seen as html (flow): all its kinds
517
+ // except 7 can interrupt a paragraph.
518
+ // As we can’t escape or so to prevent it from happening,
519
+ // we take a somewhat reasonable approach:
520
+ // replace that eol with a space.
65
521
  // See: <https://github.com/syntax-tree/mdast-util-to-markdown/issues/15>
522
+ const previous = results[results.length - 1]
523
+
66
524
  if (
67
- results.length > 0 &&
525
+ typeof previous === 'string' &&
68
526
  (before === '\r' || before === '\n') &&
69
- child.type === 'html'
527
+ child.type === 'html' &&
528
+ htmlKind(child.value) !== 7
70
529
  ) {
71
- results[results.length - 1] = results[results.length - 1].replace(
72
- /(\r?\n|\r)$/,
73
- ' '
74
- )
530
+ results[results.length - 1] = previous.replace(/(\r?\n|\r)$/, ' ')
75
531
  before = ' '
76
532
 
77
533
  // To do: does this work to reset tracker?
78
534
  tracker = state.createTracker(info)
79
- tracker.move(results.join(''))
535
+ tracker.move(serialize(results, info.before, info.after))
80
536
  }
81
537
 
82
- let value = state.handle(child, parent, state, {
83
- ...tracker.current(),
84
- after,
85
- before
86
- })
538
+ /** @type {(Handle & {attention?: Attention | undefined}) | undefined} */
539
+ // @ts-expect-error: hush, it’s actually a `zwitch`.
540
+ const handle = state.handle.handlers[child.type]
87
541
 
88
- // If we had to encode the first character after the previous node and it’s
89
- // still the same character,
90
- // encode it.
91
- if (encodeAfter && encodeAfter === value.slice(0, 1)) {
92
- value =
93
- encodeCharacterReference(encodeAfter.charCodeAt(0)) + value.slice(1)
542
+ if (handle && handle.attention) {
543
+ const {construct, markers, sizes} = handle.attention(child, state)
544
+ const sequences = attentionSequences(child.type, markers, sizes)
545
+ const sequence = sequences[0]
546
+ const exit = state.enter(construct)
547
+ tracker.move(sequence)
548
+ const inside = phrasing(/** @type {PhrasingParents} */ (child), state, {
549
+ ...tracker.current(),
550
+ before: sequence,
551
+ after: sequence
552
+ })
553
+ tracker.move(serialize(inside, sequence, sequence))
554
+ tracker.move(sequence)
555
+ exit()
556
+ results.push({children: inside, sequences})
557
+ before = sequence.charAt(sequence.length - 1)
558
+ } else {
559
+ const value = state.handle(child, parent, state, {
560
+ ...tracker.current(),
561
+ after,
562
+ before
563
+ })
564
+
565
+ if (!value) continue
566
+ tracker.move(value)
567
+ results.push(value)
568
+ before = lastCharacter(value)
94
569
  }
570
+ }
95
571
 
96
- const encodingInfo = state.attentionEncodeSurroundingInfo
97
- state.attentionEncodeSurroundingInfo = undefined
98
- encodeAfter = undefined
572
+ indexStack.pop()
99
573
 
100
- // If we have to encode the first character before the current node and
101
- // it’s still the same character,
102
- // encode it.
103
- if (encodingInfo) {
104
- if (
105
- results.length > 0 &&
106
- encodingInfo.before &&
107
- before === results[results.length - 1].slice(-1)
108
- ) {
109
- results[results.length - 1] =
110
- results[results.length - 1].slice(0, -1) +
111
- encodeCharacterReference(before.charCodeAt(0))
574
+ return results
575
+ }
576
+
577
+ /**
578
+ * Render items with sequences;
579
+ * encoding characters around attention where needed.
580
+ *
581
+ * @param {Array<Item>} items
582
+ * Serialized phrasing.
583
+ * @param {Map<AttentionResult, string>} chosen
584
+ * Sequences to use instead of preferred sequences.
585
+ * @param {string} before
586
+ * Characters before.
587
+ * @param {string} after
588
+ * Characters after.
589
+ * @returns {Array<Token>}
590
+ * Tokens.
591
+ */
592
+ function render(items, chosen, before, after) {
593
+ /** @type {Array<Token>} */
594
+ const tokens = []
595
+ /** @type {string | undefined} */
596
+ let encodeAfter
597
+ let previous = lastCharacter(before)
598
+ let index = -1
599
+
600
+ while (++index < items.length) {
601
+ const item = items[index]
602
+
603
+ if (typeof item === 'string') {
604
+ /** @type {Token} */
605
+ const token = {value: item, attention: undefined}
606
+
607
+ // If attention before had to encode the character after it, encode it.
608
+ if (encodeAfter && encodeAfter === firstCharacter(item)) {
609
+ encode([token], true)
112
610
  }
113
611
 
114
- if (encodingInfo.after) encodeAfter = after
612
+ encodeAfter = undefined
613
+ tokens.push(token)
614
+ if (token.value) previous = lastCharacter(token.value)
615
+ continue
115
616
  }
116
617
 
117
- tracker.move(value)
118
- results.push(value)
119
- before = value.slice(-1)
618
+ const sequence = chosen.get(item) || item.sequences[0]
619
+ const marker = sequence.charAt(0)
620
+ const next = items[index + 1]
621
+ const outsideBefore = previous
622
+ const outsideAfter = firstCharacter(
623
+ next === undefined
624
+ ? after
625
+ : typeof next === 'string'
626
+ ? next
627
+ : chosen.get(next) || next.sequences[0]
628
+ )
629
+ const inside = render(item.children, chosen, sequence, sequence)
630
+ const head = inside.length > 0 ? inside[0].value : ''
631
+ const open = encodeInfo(
632
+ outsideBefore.charCodeAt(outsideBefore.length - 1),
633
+ head.charCodeAt(0),
634
+ marker
635
+ )
636
+
637
+ if (open.inside) encode(inside, true)
638
+
639
+ const tail =
640
+ inside.length > 0 ? lastCharacter(inside[inside.length - 1].value) : ''
641
+ const close = encodeInfo(
642
+ outsideAfter.charCodeAt(0),
643
+ tail.charCodeAt(tail.length - 1),
644
+ marker
645
+ )
646
+
647
+ if (close.inside) encode(inside, false)
648
+
649
+ if (open.outside && outsideBefore !== '\n' && outsideBefore !== '\r') {
650
+ encode(tokens, false)
651
+ }
652
+
653
+ if (close.outside) encodeAfter = outsideAfter
654
+
655
+ tokens.push({value: sequence, attention: item}, ...inside, {
656
+ value: sequence,
657
+ attention: item
658
+ })
659
+ previous = sequence.charAt(sequence.length - 1)
120
660
  }
121
661
 
122
- indexStack.pop()
662
+ return tokens
663
+ }
664
+
665
+ /**
666
+ * Serialize phrasing with attention.
667
+ *
668
+ * Whether attention forms depends on everything around it.
669
+ * This checks that it does and tries other sequences if not.
670
+ *
671
+ * @param {Array<Item>} items
672
+ * Phrasing items.
673
+ * @param {string} before
674
+ * Characters before.
675
+ * @param {string} after
676
+ * Characters after.
677
+ * @returns {string}
678
+ * Serialized markdown.
679
+ */
680
+ function serialize(items, before, after) {
681
+ /** @type {Map<AttentionResult, string>} */
682
+ let chosen = new Map()
683
+ const initial = render(items, chosen, before, after)
684
+ let tokens = initial
685
+ let mistake = check(tokens, before, after)
686
+
687
+ while (mistake) {
688
+ const next = improve(items, chosen, mistake, before, after)
689
+
690
+ if (!next) {
691
+ tokens = initial
692
+ break
693
+ }
694
+
695
+ chosen = next.chosen
696
+ tokens = next.tokens
697
+ mistake = next.mistake
698
+ }
123
699
 
124
- return results.join('')
700
+ // Join the tokens.
701
+ let result = ''
702
+ for (const token of tokens) result += token.value
703
+ return result
125
704
  }