chaffjs 0.43.0 → 0.45.0

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 (348) hide show
  1. package/dist/bound-word-particles.d.ts +9 -0
  2. package/dist/bound-word-particles.d.ts.map +1 -0
  3. package/dist/bound-word-particles.js +16 -0
  4. package/dist/bound-word-particles.js.map +1 -0
  5. package/dist/derived/stays.d.ts +0 -1
  6. package/dist/derived/stays.d.ts.map +1 -1
  7. package/dist/derived/stays.js +3 -1
  8. package/dist/derived/stays.js.map +1 -1
  9. package/dist/detectors/absolute-exception.d.ts.map +1 -1
  10. package/dist/detectors/absolute-exception.js +10 -4
  11. package/dist/detectors/absolute-exception.js.map +1 -1
  12. package/dist/detectors/abstract-length.d.ts +5 -1
  13. package/dist/detectors/abstract-length.d.ts.map +1 -1
  14. package/dist/detectors/abstract-length.js +13 -5
  15. package/dist/detectors/abstract-length.js.map +1 -1
  16. package/dist/detectors/adversative-ga.d.ts +1 -1
  17. package/dist/detectors/adversative-ga.d.ts.map +1 -1
  18. package/dist/detectors/adversative-ga.js +19 -2
  19. package/dist/detectors/adversative-ga.js.map +1 -1
  20. package/dist/detectors/agreement-slip.d.ts +2 -0
  21. package/dist/detectors/agreement-slip.d.ts.map +1 -1
  22. package/dist/detectors/agreement-slip.js +22 -8
  23. package/dist/detectors/agreement-slip.js.map +1 -1
  24. package/dist/detectors/bold-label.d.ts +5 -1
  25. package/dist/detectors/bold-label.d.ts.map +1 -1
  26. package/dist/detectors/bold-label.js +74 -14
  27. package/dist/detectors/bold-label.js.map +1 -1
  28. package/dist/detectors/bold-quoted.d.ts +4 -0
  29. package/dist/detectors/bold-quoted.d.ts.map +1 -0
  30. package/dist/detectors/bold-quoted.js +17 -0
  31. package/dist/detectors/bold-quoted.js.map +1 -0
  32. package/dist/detectors/caps-caption.d.ts +5 -0
  33. package/dist/detectors/caps-caption.d.ts.map +1 -1
  34. package/dist/detectors/caps-caption.js +7 -0
  35. package/dist/detectors/caps-caption.js.map +1 -1
  36. package/dist/detectors/char-shape.d.ts +0 -6
  37. package/dist/detectors/char-shape.d.ts.map +1 -1
  38. package/dist/detectors/char-shape.js +4 -21
  39. package/dist/detectors/char-shape.js.map +1 -1
  40. package/dist/detectors/clause-shape.d.ts +2 -0
  41. package/dist/detectors/clause-shape.d.ts.map +1 -1
  42. package/dist/detectors/clause-shape.js +11 -2
  43. package/dist/detectors/clause-shape.js.map +1 -1
  44. package/dist/detectors/cleft-focus.d.ts +4 -0
  45. package/dist/detectors/cleft-focus.d.ts.map +1 -0
  46. package/dist/detectors/cleft-focus.js +31 -0
  47. package/dist/detectors/cleft-focus.js.map +1 -0
  48. package/dist/detectors/count-per-section.d.ts.map +1 -1
  49. package/dist/detectors/count-per-section.js +7 -4
  50. package/dist/detectors/count-per-section.js.map +1 -1
  51. package/dist/detectors/defined-term-form.d.ts.map +1 -1
  52. package/dist/detectors/defined-term-form.js +2 -1
  53. package/dist/detectors/defined-term-form.js.map +1 -1
  54. package/dist/detectors/definition-use.d.ts.map +1 -1
  55. package/dist/detectors/definition-use.js +13 -3
  56. package/dist/detectors/definition-use.js.map +1 -1
  57. package/dist/detectors/emoticon.d.ts +6 -0
  58. package/dist/detectors/emoticon.d.ts.map +1 -0
  59. package/dist/detectors/emoticon.js +19 -0
  60. package/dist/detectors/emoticon.js.map +1 -0
  61. package/dist/detectors/empty-section.d.ts +1 -1
  62. package/dist/detectors/empty-section.d.ts.map +1 -1
  63. package/dist/detectors/empty-section.js +3 -2
  64. package/dist/detectors/empty-section.js.map +1 -1
  65. package/dist/detectors/en-shape.d.ts +6 -1
  66. package/dist/detectors/en-shape.d.ts.map +1 -1
  67. package/dist/detectors/en-shape.js +9 -1
  68. package/dist/detectors/en-shape.js.map +1 -1
  69. package/dist/detectors/fullwidth-alnum.d.ts +2 -2
  70. package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
  71. package/dist/detectors/fullwidth-alnum.js +19 -3
  72. package/dist/detectors/fullwidth-alnum.js.map +1 -1
  73. package/dist/detectors/heading-echo.d.ts.map +1 -1
  74. package/dist/detectors/heading-echo.js +20 -7
  75. package/dist/detectors/heading-echo.js.map +1 -1
  76. package/dist/detectors/heading-number.d.ts +7 -0
  77. package/dist/detectors/heading-number.d.ts.map +1 -0
  78. package/dist/detectors/heading-number.js +21 -0
  79. package/dist/detectors/heading-number.js.map +1 -0
  80. package/dist/detectors/katakana-density.d.ts +6 -1
  81. package/dist/detectors/katakana-density.d.ts.map +1 -1
  82. package/dist/detectors/katakana-density.js +14 -1
  83. package/dist/detectors/katakana-density.js.map +1 -1
  84. package/dist/detectors/lexicon.d.ts.map +1 -1
  85. package/dist/detectors/lexicon.js +2 -1
  86. package/dist/detectors/lexicon.js.map +1 -1
  87. package/dist/detectors/lookalike-character.d.ts +2 -1
  88. package/dist/detectors/lookalike-character.d.ts.map +1 -1
  89. package/dist/detectors/lookalike-character.js +14 -1
  90. package/dist/detectors/lookalike-character.js.map +1 -1
  91. package/dist/detectors/mark-shape.d.ts +8 -3
  92. package/dist/detectors/mark-shape.d.ts.map +1 -1
  93. package/dist/detectors/mark-shape.js +55 -16
  94. package/dist/detectors/mark-shape.js.map +1 -1
  95. package/dist/detectors/mentioned-phrase.d.ts +3 -1
  96. package/dist/detectors/mentioned-phrase.d.ts.map +1 -1
  97. package/dist/detectors/mentioned-phrase.js +9 -0
  98. package/dist/detectors/mentioned-phrase.js.map +1 -1
  99. package/dist/detectors/middle-dot.d.ts +7 -0
  100. package/dist/detectors/middle-dot.d.ts.map +1 -1
  101. package/dist/detectors/middle-dot.js +19 -0
  102. package/dist/detectors/middle-dot.js.map +1 -1
  103. package/dist/detectors/named-by-context.d.ts +13 -0
  104. package/dist/detectors/named-by-context.d.ts.map +1 -0
  105. package/dist/detectors/named-by-context.js +10 -0
  106. package/dist/detectors/named-by-context.js.map +1 -0
  107. package/dist/detectors/number-style.d.ts.map +1 -1
  108. package/dist/detectors/number-style.js +13 -1
  109. package/dist/detectors/number-style.js.map +1 -1
  110. package/dist/detectors/obligation-without-deadline.d.ts +10 -2
  111. package/dist/detectors/obligation-without-deadline.d.ts.map +1 -1
  112. package/dist/detectors/obligation-without-deadline.js +47 -2
  113. package/dist/detectors/obligation-without-deadline.js.map +1 -1
  114. package/dist/detectors/open-end-names.d.ts +2 -0
  115. package/dist/detectors/open-end-names.d.ts.map +1 -1
  116. package/dist/detectors/open-end-names.js +8 -1
  117. package/dist/detectors/open-end-names.js.map +1 -1
  118. package/dist/detectors/orthographic-variant.d.ts.map +1 -1
  119. package/dist/detectors/orthographic-variant.js +5 -3
  120. package/dist/detectors/orthographic-variant.js.map +1 -1
  121. package/dist/detectors/paragraph-pointer.d.ts +4 -0
  122. package/dist/detectors/paragraph-pointer.d.ts.map +1 -0
  123. package/dist/detectors/paragraph-pointer.js +22 -0
  124. package/dist/detectors/paragraph-pointer.js.map +1 -0
  125. package/dist/detectors/phrase-match.d.ts +4 -1
  126. package/dist/detectors/phrase-match.d.ts.map +1 -1
  127. package/dist/detectors/phrase-match.js +12 -5
  128. package/dist/detectors/phrase-match.js.map +1 -1
  129. package/dist/detectors/placeholder-context.d.ts +16 -0
  130. package/dist/detectors/placeholder-context.d.ts.map +1 -0
  131. package/dist/detectors/placeholder-context.js +57 -0
  132. package/dist/detectors/placeholder-context.js.map +1 -0
  133. package/dist/detectors/placeholder-text.d.ts +2 -0
  134. package/dist/detectors/placeholder-text.d.ts.map +1 -1
  135. package/dist/detectors/placeholder-text.js +1 -1
  136. package/dist/detectors/placeholder-text.js.map +1 -1
  137. package/dist/detectors/redundant-pair.d.ts +5 -0
  138. package/dist/detectors/redundant-pair.d.ts.map +1 -0
  139. package/dist/detectors/redundant-pair.js +18 -0
  140. package/dist/detectors/redundant-pair.js.map +1 -0
  141. package/dist/detectors/registry/middle-dot.js +1 -1
  142. package/dist/detectors/registry/redundant-pair.d.ts +3 -0
  143. package/dist/detectors/registry/redundant-pair.d.ts.map +1 -0
  144. package/dist/detectors/registry/redundant-pair.js +3 -0
  145. package/dist/detectors/registry/redundant-pair.js.map +1 -0
  146. package/dist/detectors/request-owner.d.ts +1 -0
  147. package/dist/detectors/request-owner.d.ts.map +1 -1
  148. package/dist/detectors/request-owner.js +6 -3
  149. package/dist/detectors/request-owner.js.map +1 -1
  150. package/dist/detectors/sentence-counts.d.ts +2 -0
  151. package/dist/detectors/sentence-counts.d.ts.map +1 -1
  152. package/dist/detectors/sentence-counts.js +13 -4
  153. package/dist/detectors/sentence-counts.js.map +1 -1
  154. package/dist/detectors/signals.d.ts.map +1 -1
  155. package/dist/detectors/signals.js +10 -1
  156. package/dist/detectors/signals.js.map +1 -1
  157. package/dist/detectors/structure-tree.d.ts.map +1 -1
  158. package/dist/detectors/structure-tree.js +1 -0
  159. package/dist/detectors/structure-tree.js.map +1 -1
  160. package/dist/detectors/structure.d.ts.map +1 -1
  161. package/dist/detectors/structure.js +6 -5
  162. package/dist/detectors/structure.js.map +1 -1
  163. package/dist/detectors/superlative-context.d.ts +7 -0
  164. package/dist/detectors/superlative-context.d.ts.map +1 -1
  165. package/dist/detectors/superlative-context.js +9 -0
  166. package/dist/detectors/superlative-context.js.map +1 -1
  167. package/dist/detectors/template-sections.d.ts +1 -0
  168. package/dist/detectors/template-sections.d.ts.map +1 -1
  169. package/dist/detectors/template-sections.js +1 -1
  170. package/dist/detectors/template-sections.js.map +1 -1
  171. package/dist/detectors/token-shape.d.ts.map +1 -1
  172. package/dist/detectors/token-shape.js +7 -5
  173. package/dist/detectors/token-shape.js.map +1 -1
  174. package/dist/detectors/unbalanced-bracket.d.ts.map +1 -1
  175. package/dist/detectors/unbalanced-bracket.js +2 -1
  176. package/dist/detectors/unbalanced-bracket.js.map +1 -1
  177. package/dist/detectors/unfilled-placeholder.d.ts.map +1 -1
  178. package/dist/detectors/unfilled-placeholder.js +18 -1
  179. package/dist/detectors/unfilled-placeholder.js.map +1 -1
  180. package/dist/detectors/verse-block.d.ts +4 -0
  181. package/dist/detectors/verse-block.d.ts.map +1 -0
  182. package/dist/detectors/verse-block.js +40 -0
  183. package/dist/detectors/verse-block.js.map +1 -0
  184. package/dist/document.d.ts.map +1 -1
  185. package/dist/document.js +1 -0
  186. package/dist/document.js.map +1 -1
  187. package/dist/email-parts.d.ts +2 -0
  188. package/dist/email-parts.d.ts.map +1 -1
  189. package/dist/email-parts.js +10 -7
  190. package/dist/email-parts.js.map +1 -1
  191. package/dist/eval.d.ts.map +1 -1
  192. package/dist/eval.js +3 -0
  193. package/dist/eval.js.map +1 -1
  194. package/dist/paragraph-length.d.ts +4 -0
  195. package/dist/paragraph-length.d.ts.map +1 -1
  196. package/dist/paragraph-length.js +6 -0
  197. package/dist/paragraph-length.js.map +1 -1
  198. package/dist/plugin.d.ts +4 -0
  199. package/dist/plugin.d.ts.map +1 -1
  200. package/dist/reasons.d.ts +2 -0
  201. package/dist/reasons.d.ts.map +1 -1
  202. package/dist/reasons.js +2 -0
  203. package/dist/reasons.js.map +1 -1
  204. package/dist/rule-of-three.d.ts +13 -1
  205. package/dist/rule-of-three.d.ts.map +1 -1
  206. package/dist/rule-of-three.js +32 -3
  207. package/dist/rule-of-three.js.map +1 -1
  208. package/dist/run.d.ts.map +1 -1
  209. package/dist/run.js +4 -1
  210. package/dist/run.js.map +1 -1
  211. package/dist/structure/build.d.ts.map +1 -1
  212. package/dist/structure/build.js +2 -1
  213. package/dist/structure/build.js.map +1 -1
  214. package/dist/structure/cited-elsewhere.d.ts +5 -2
  215. package/dist/structure/cited-elsewhere.d.ts.map +1 -1
  216. package/dist/structure/cited-elsewhere.js +16 -6
  217. package/dist/structure/cited-elsewhere.js.map +1 -1
  218. package/dist/structure/definition-use.d.ts +2 -1
  219. package/dist/structure/definition-use.d.ts.map +1 -1
  220. package/dist/structure/definition-use.js +10 -2
  221. package/dist/structure/definition-use.js.map +1 -1
  222. package/dist/structure/issues.js +1 -1
  223. package/dist/structure/issues.js.map +1 -1
  224. package/dist/structure/negated-act.d.ts +1 -0
  225. package/dist/structure/negated-act.d.ts.map +1 -1
  226. package/dist/structure/negated-act.js +1 -1
  227. package/dist/structure/negated-act.js.map +1 -1
  228. package/dist/structure/own-name.d.ts +4 -0
  229. package/dist/structure/own-name.d.ts.map +1 -0
  230. package/dist/structure/own-name.js +20 -0
  231. package/dist/structure/own-name.js.map +1 -0
  232. package/dist/structure/percent-sum-prose.d.ts.map +1 -1
  233. package/dist/structure/percent-sum-prose.js +9 -1
  234. package/dist/structure/percent-sum-prose.js.map +1 -1
  235. package/dist/structure/percent-sum.d.ts +2 -0
  236. package/dist/structure/percent-sum.d.ts.map +1 -1
  237. package/dist/structure/percent-sum.js.map +1 -1
  238. package/dist/structure/reference-text.d.ts.map +1 -1
  239. package/dist/structure/reference-text.js +3 -1
  240. package/dist/structure/reference-text.js.map +1 -1
  241. package/dist/te-form-helper.d.ts +22 -0
  242. package/dist/te-form-helper.d.ts.map +1 -0
  243. package/dist/te-form-helper.js +35 -0
  244. package/dist/te-form-helper.js.map +1 -0
  245. package/dist/word-use.d.ts +7 -0
  246. package/dist/word-use.d.ts.map +1 -1
  247. package/dist/word-use.js +11 -0
  248. package/dist/word-use.js.map +1 -1
  249. package/package.json +3 -3
  250. package/rules/absolute-exception.yaml +3 -3
  251. package/rules/abstract-length.yaml +2 -2
  252. package/rules/adversative-ga-repeat.yaml +2 -2
  253. package/rules/all-caps-shouting.yaml +2 -2
  254. package/rules/attachment-not-attached.yaml +11 -6
  255. package/rules/bold-label-list.yaml +29 -6
  256. package/rules/bracket-width-consistency.yaml +2 -2
  257. package/rules/demonstrative-opener-run.yaml +2 -2
  258. package/rules/duration-mismatch.yaml +2 -2
  259. package/rules/emoji-density.yaml +2 -2
  260. package/rules/empty-section.yaml +2 -2
  261. package/rules/fullwidth-alnum-consistency.yaml +2 -2
  262. package/rules/katakana-density.yaml +3 -3
  263. package/rules/lookalike-character.yaml +8 -5
  264. package/rules/max-kanji-continuous.yaml +4 -0
  265. package/rules/no-doubled-joshi.yaml +2 -2
  266. package/rules/number-style-consistency.yaml +2 -2
  267. package/rules/obligation-without-deadline.yaml +2 -2
  268. package/rules/padded-intro.yaml +1 -1
  269. package/rules/paragraph-length-variance.yaml +27 -3
  270. package/rules/redundant-expression.yaml +1 -1
  271. package/rules/repeated-sentence-ending.yaml +2 -2
  272. package/rules/request-without-deadline.yaml +2 -2
  273. package/rules/requirement-smell.yaml +2 -2
  274. package/rules/rule-of-three.yaml +2 -2
  275. package/rules/sentence-spacing-consistency.yaml +2 -2
  276. package/rules/teki-overuse.yaml +2 -0
  277. package/rules/unfilled-placeholder.yaml +2 -2
  278. package/rules/use-before-definition.yaml +2 -2
  279. package/src/bound-word-particles.ts +23 -0
  280. package/src/derived/stays.ts +4 -1
  281. package/src/detectors/absolute-exception.ts +11 -5
  282. package/src/detectors/abstract-length.ts +16 -6
  283. package/src/detectors/adversative-ga.ts +24 -2
  284. package/src/detectors/agreement-slip.ts +35 -10
  285. package/src/detectors/bold-label.ts +82 -14
  286. package/src/detectors/bold-quoted.ts +21 -0
  287. package/src/detectors/caps-caption.ts +10 -0
  288. package/src/detectors/char-shape.ts +8 -22
  289. package/src/detectors/clause-shape.ts +14 -3
  290. package/src/detectors/cleft-focus.ts +40 -0
  291. package/src/detectors/count-per-section.ts +9 -4
  292. package/src/detectors/defined-term-form.ts +2 -1
  293. package/src/detectors/definition-use.ts +23 -4
  294. package/src/detectors/emoticon.ts +21 -0
  295. package/src/detectors/empty-section.ts +3 -2
  296. package/src/detectors/en-shape.ts +10 -1
  297. package/src/detectors/fullwidth-alnum.ts +24 -3
  298. package/src/detectors/heading-echo.ts +21 -8
  299. package/src/detectors/heading-number.ts +20 -0
  300. package/src/detectors/katakana-density.ts +17 -2
  301. package/src/detectors/lexicon.ts +2 -1
  302. package/src/detectors/lookalike-character.ts +19 -2
  303. package/src/detectors/mark-shape.ts +61 -13
  304. package/src/detectors/mentioned-phrase.ts +13 -1
  305. package/src/detectors/middle-dot.ts +22 -0
  306. package/src/detectors/named-by-context.ts +15 -0
  307. package/src/detectors/number-style.ts +14 -1
  308. package/src/detectors/obligation-without-deadline.ts +69 -5
  309. package/src/detectors/open-end-names.ts +21 -2
  310. package/src/detectors/orthographic-variant.ts +20 -15
  311. package/src/detectors/paragraph-pointer.ts +28 -0
  312. package/src/detectors/phrase-match.ts +13 -5
  313. package/src/detectors/placeholder-context.ts +72 -0
  314. package/src/detectors/placeholder-text.ts +1 -1
  315. package/src/detectors/redundant-pair.ts +25 -0
  316. package/src/detectors/registry/middle-dot.ts +1 -1
  317. package/src/detectors/registry/redundant-pair.ts +4 -0
  318. package/src/detectors/request-owner.ts +6 -3
  319. package/src/detectors/sentence-counts.ts +16 -4
  320. package/src/detectors/signals.ts +11 -1
  321. package/src/detectors/structure-tree.ts +1 -0
  322. package/src/detectors/structure.ts +6 -5
  323. package/src/detectors/superlative-context.ts +12 -0
  324. package/src/detectors/template-sections.ts +1 -1
  325. package/src/detectors/token-shape.ts +10 -7
  326. package/src/detectors/unbalanced-bracket.ts +2 -1
  327. package/src/detectors/unfilled-placeholder.ts +22 -1
  328. package/src/detectors/verse-block.ts +48 -0
  329. package/src/document.ts +1 -0
  330. package/src/email-parts.ts +16 -7
  331. package/src/eval.ts +2 -0
  332. package/src/paragraph-length.ts +10 -0
  333. package/src/plugin.ts +4 -0
  334. package/src/reasons.ts +4 -0
  335. package/src/rule-of-three.ts +47 -4
  336. package/src/run.ts +3 -1
  337. package/src/structure/build.ts +2 -1
  338. package/src/structure/cited-elsewhere.ts +18 -6
  339. package/src/structure/definition-use.ts +10 -1
  340. package/src/structure/issues.ts +1 -1
  341. package/src/structure/negated-act.ts +1 -1
  342. package/src/structure/own-name.ts +28 -0
  343. package/src/structure/percent-sum-prose.ts +12 -1
  344. package/src/structure/percent-sum.ts +2 -0
  345. package/src/structure/reference-text.ts +5 -1
  346. package/src/te-form-helper.ts +52 -0
  347. package/src/word-use.ts +13 -0
  348. package/src/honorific-group.ts +0 -22
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A round bracket written as the mouth of an emoticon (":-)", ";)", ":(" ). It opens and closes nothing.
3
+ * text is the section, offset the bracket's position.
4
+ */
5
+
6
+ /**
7
+ * The eyes and an optional nose right before the mouth, at the start of a word or after an opening quote: ":", ";" or "=",
8
+ * then "-" or "'". Not after an opening bracket: "(:)" names the colon.
9
+ */
10
+ const FACE_BEFORE = /(?:^|[\s"'“‘])[:;=][-']?$/u;
11
+
12
+ /** After the mouth: the end, a space, a closing quote or punctuation. A letter or digit would make it part of a word. */
13
+ const FACE_AFTER = /^(?:$|[\s"'”’),.;:!?])/u;
14
+
15
+ const LOOK_AROUND = 4;
16
+
17
+ export const isEmoticonMouth = (text: string, offset: number): boolean => {
18
+ const mark = text[offset];
19
+ if (mark !== "(" && mark !== ")") return false;
20
+ return FACE_BEFORE.test(text.slice(Math.max(0, offset - LOOK_AROUND), offset)) && FACE_AFTER.test(text.slice(offset + 1, offset + 2));
21
+ };
@@ -1,5 +1,6 @@
1
1
  import type { Detector, Finding, MarkupHeading } from "../plugin.ts";
2
2
  import { findingAt, writtenHeadings } from "./markup-finding.ts";
3
+ import { opensSubsection } from "./heading-number.ts";
3
4
 
4
5
  /** HTML のコメント(「<!-- 後で書く -->」)。読み手には見えない。一つずつ外す(間の本文ごと一つのコメントと読まない)。 */
5
6
  const HTML_COMMENT = /<!--[\s\S]*?-->/gu;
@@ -8,12 +9,12 @@ const showsNothing = (written: string): boolean => written.replace(HTML_COMMENT,
8
9
 
9
10
  /**
10
11
  * 中身の無い節。見出しのすぐ後ろに、同じ深さか浅い見出しが来るもの(remark-lint の no-empty-sections)。
11
- * 深い見出しが続くのは、節を小さな節に分けただけなので中身がある。文書の最後の見出しは、後ろに何も無ければ空。
12
+ * 深い見出しが続くのは、節を小さな節に分けただけなので中身がある。同じ深さでも、番号が節の下の番号(3. の後の 3.1、4. の後の (1))なら同じ。文書の最後の見出しは、後ろに何も無ければ空。
12
13
  */
13
14
  export const emptySections = (source: string, headings: readonly MarkupHeading[]): MarkupHeading[] =>
14
15
  headings.filter((heading, index) => {
15
16
  const next = headings[index + 1];
16
- if (next !== undefined && next.depth > heading.depth) return false;
17
+ if (next !== undefined && (next.depth > heading.depth || (next.depth === heading.depth && opensSubsection(heading.text, next.text)))) return false;
17
18
  return showsNothing(source.slice(heading.end, next?.start ?? source.length));
18
19
  });
19
20
 
@@ -53,6 +53,15 @@ export const adverbDensity: Detector = (doc, options): Finding[] => {
53
53
 
54
54
  const BE = new Set(["be", "is", "are", "was", "were"]);
55
55
 
56
+ /**
57
+ * The words before ", but": "It's not fashionable these days, but my view is that …" is a concessive aside, and its
58
+ * that-clause belongs to the clause after but.
59
+ */
60
+ export const beforeConcession = (tokens: readonly Token[]): readonly Token[] => {
61
+ const at = tokens.findIndex((token, index) => token.surface === "," && tokens[index + 1]?.surface.toLowerCase() === "but");
62
+ return at === -1 ? tokens : tokens.slice(0, at);
63
+ };
64
+
56
65
  /**
57
66
  * There is / It is ... that は、主語を後ろへ押しやって誰が何をするのかを消す。
58
67
  * 「There is a need to review」は、誰が必要としているのかを言っていない。
@@ -65,7 +74,7 @@ const expletiveAt = (tokens: readonly Token[]): Token | undefined => {
65
74
  const next = tokens.find((token) => token.span.start >= head.span.end && token.pos !== "PUNCT");
66
75
  if (next === undefined || !BE.has(next.lemma ?? next.surface.toLowerCase())) return undefined;
67
76
  // "it is" は "it is raining" のような正当な用法があるので、that 節を伴うときだけ数える。
68
- if (lead === "it" && !tokens.some((token) => token.surface.toLowerCase() === "that")) return undefined;
77
+ if (lead === "it" && !beforeConcession(tokens).some((token) => token.surface.toLowerCase() === "that")) return undefined;
69
78
  return head;
70
79
  };
71
80
 
@@ -89,15 +89,36 @@ export type AlnumRun = {
89
89
  readonly glued: boolean;
90
90
  };
91
91
 
92
+ type Piece = { readonly 0: string; readonly index: number };
93
+
94
+ /** 一つの幅で書いた部分。 */
95
+ const SAME_WIDTH = /[A-Za-z0-9]+|[A-Za-z0-9]+/gu;
96
+ const ONE_LETTER = /^[A-Za-zA-Za-z]$/u;
97
+ const DIGITS = /^[0-90-9]+$/u;
98
+
99
+ /** 英字一字と数字の、幅の違う組(Q5、H30、600w)か。 */
100
+ const isLetterAndNumber = (parts: readonly Piece[]): boolean =>
101
+ parts.length === 2 && parts.some((part) => ONE_LETTER.test(part[0])) && parts.some((part) => DIGITS.test(part[0]));
102
+
103
+ /**
104
+ * 並びを、一つの幅で書いた部分に分ける。英字一字と数字を違う幅で書いた並び(Q5、H30)は、英字と数字に分けてそれぞれの組で数える。
105
+ * 「一字の英字は全角、2桁以上は半角」の H30 は、H も 30 もその組の中でそろう。ほかの混ざった並び(IoT)は数えない。
106
+ */
107
+ const widthPieces = (match: RegExpExecArray): Piece[] => {
108
+ if (FULLWIDTH.test(match[0]) || HALFWIDTH.test(match[0])) return [match];
109
+ const parts = [...match[0].matchAll(SAME_WIDTH)].map((part) => ({ 0: part[0], index: match.index + part.index }));
110
+ return isLetterAndNumber(parts) ? parts : [];
111
+ };
112
+
92
113
  /**
93
- * 文の中の英字・数字の並び。全角と半角が混ざった並び、鉤括弧で引いたものの中、項目と注の番号、箇条書きの頭の番号、版の番号の続き(TLS1.2 の 2)は数えない。
94
- * offset は文書の中の位置。
114
+ * 文の中の英字・数字の並び。鉤括弧で引いたものの中、項目と注の番号、箇条書きの頭の番号、版の番号の続き(TLS1.2 の 2)は数えない。
115
+ * 英字一字と数字を違う幅で書いた並びは分ける。offset は文書の中の位置。
95
116
  */
96
117
  export const alnumRunsIn = (sentence: Sentence, source: string): AlnumRun[] => {
97
118
  const quoted: readonly Span[] = quotedSpans(sentence.text, QUOTATION_MARKS);
98
119
  const glued = gluedNumberSpans(sentence.text);
99
120
  return [...sentence.text.matchAll(ALNUM_RUN)]
100
- .filter((match) => FULLWIDTH.test(match[0]) || HALFWIDTH.test(match[0]))
121
+ .flatMap(widthPieces)
101
122
  .filter((match) => !isWithinAny(quoted, { start: match.index, end: match.index + match[0].length }))
102
123
  .filter((match) => !isLabel(sentence.text, match.index, match.index + match[0].length))
103
124
  .filter((match) => !isListItemNumber(source, sentence.span.start + match.index))
@@ -1,4 +1,5 @@
1
1
  import { lengthOf, proseText } from "../measure.ts";
2
+ import { cleftFocus } from "./cleft-focus.ts";
2
3
  import { newContentMorphemes } from "./content-morphemes.ts";
3
4
  import { echoedHeadingUnits, trigrams } from "./heading-overlap.ts";
4
5
  import { fieldValueStart } from "./field-label.ts";
@@ -9,7 +10,7 @@ import { handsOver } from "./lead-in.ts";
9
10
  import { holdsLink, namesLocation } from "./location-pointer.ts";
10
11
  import { withoutQuotedVariants } from "./quoted-variant.ts";
11
12
  import { namesHeadingSubject } from "./subject-name-line.ts";
12
- import type { Detector, Finding, LengthUnit, ProseDocument, Section, Sentence } from "../plugin.ts";
13
+ import type { Detector, Finding, LengthUnit, ProseDocument, Section, Sentence, Token } from "../plugin.ts";
13
14
 
14
15
  /** 見出しが短すぎると、偶然の一致で 100% になる。これ未満の見出しは見ない。 */
15
16
  const MIN_GRAMS = 4;
@@ -46,11 +47,23 @@ const NEW_CONTENT_MORPHEMES = 1;
46
47
  /** 重なりを測る見出し。頭の番号の札(例 3:、Step 3:、1.)は本文で繰り返されないので、数えると短い見出しほど重なりが下がる。 */
47
48
  const measuredHeading = (section: Section): string => section.unlabeledHeading ?? section.heading;
48
49
 
49
- const addsLittle = (section: Section, unit: LengthUnit): boolean => {
50
+ /**
51
+ * 内容を測る文の語。分裂文(いちばん大きく変わったのは、季節の移り変わりに気づくようになったことだ。)は焦点の語だけ:
52
+ * 主題の節は焦点を差し出すだけで、焦点が見出しを言い直していれば、文は見出しを繰り返している。
53
+ */
54
+ const statedTokens = (doc: ProseDocument, sentence: Sentence): readonly Token[] | undefined => {
55
+ const focus = cleftFocus(sentence.text, doc.lexicons["cleft-frame"] ?? []);
56
+ if (sentence.tokens === undefined || focus === undefined) return sentence.tokens;
57
+ const [start, end] = [sentence.span.start + focus.start, sentence.span.start + focus.end];
58
+ return sentence.tokens.filter((token) => token.span.start >= start && token.span.end <= end);
59
+ };
60
+
61
+ const addsLittle = (doc: ProseDocument, section: Section, unit: LengthUnit): boolean => {
50
62
  const first = section.firstSentence;
51
63
  if (first === undefined) return false;
52
- if (unit === "char" && first.tokens !== undefined && section.headingTokens !== undefined)
53
- return newContentMorphemes(titleTokens(section.heading, measuredHeading(section), section.headingTokens), first.tokens) <= NEW_CONTENT_MORPHEMES;
64
+ const stated = statedTokens(doc, first);
65
+ if (unit === "char" && stated !== undefined && section.headingTokens !== undefined)
66
+ return newContentMorphemes(titleTokens(section.heading, measuredHeading(section), section.headingTokens), stated) <= NEW_CONTENT_MORPHEMES;
54
67
  return lengthOf(first, unit) - echoedHeadingUnits(measuredHeading(section), proseText(first), unit) <= NEW_MATERIAL[unit];
55
68
  };
56
69
 
@@ -74,10 +87,10 @@ const pointsElsewhere = (doc: ProseDocument, section: Section): boolean => {
74
87
  * 予告や指示の語(covers, below, 説明, 以下)だけを述語にする文は、見出しを言い直しているだけで繰り返し。
75
88
  */
76
89
  const statesClaim = (doc: ProseDocument, section: Section): boolean => {
77
- const first = section.firstSentence;
78
- if (first?.tokens === undefined || section.headingTokens === undefined) return false;
90
+ const stated = section.firstSentence === undefined ? undefined : statedTokens(doc, section.firstSentence);
91
+ if (stated === undefined || section.headingTokens === undefined) return false;
79
92
  const heading = titleTokens(section.heading, measuredHeading(section), section.headingTokens);
80
- return makesClaim(heading, first.tokens, announcerWords(doc.lexicons["heading-announcer"] ?? []));
93
+ return makesClaim(heading, stated, announcerWords(doc.lexicons["heading-announcer"] ?? []));
81
94
  };
82
95
 
83
96
  /** A figure, with its thousands separators (1,320,000), compared without them. */
@@ -138,7 +151,7 @@ const echoedText = (section: Section): string =>
138
151
  export const headingEcho: Detector = (doc, options): Finding[] => {
139
152
  const leadIns = (doc.lexicons["lead-in"] ?? []).map((entry) => entry.pattern);
140
153
  return doc.sections
141
- .filter((section) => section.heading.length > 0 && section.firstSentence !== undefined && addsLittle(section, doc.lengthUnit))
154
+ .filter((section) => section.heading.length > 0 && section.firstSentence !== undefined && addsLittle(doc, section, doc.lengthUnit))
142
155
  .filter(
143
156
  (section) =>
144
157
  !leadsIn(doc, section, leadIns) &&
@@ -0,0 +1,20 @@
1
+ /** A heading's number at its head: 3, 4.2, 4.2.1 (a full stop after it, as in "3.", is not part of it). */
2
+ const DOTTED_NUMBER = /^(\d{1,3}(?:\.\d{1,3})*)\.?(?!\d)/u;
3
+ /** The first item of a bracketed series under a numbered heading: (1), (1). */
4
+ const FIRST_BRACKETED = /^\(1\)/u;
5
+
6
+ const numberOf = (heading: string): string | undefined => DOTTED_NUMBER.exec(heading.normalize("NFKC").trim())?.[1];
7
+
8
+ /**
9
+ * Whether `child`, the next heading at the same depth, opens a subsection of `parent` by its number: 3. then 3.1, 4.2 then
10
+ * 4.2.1, or a numbered heading then its first bracketed item ((1)). Some documents number their subsections at the
11
+ * heading level of the section itself, so the depth alone does not show the split.
12
+ */
13
+ export const opensSubsection = (parent: string, child: string): boolean => {
14
+ const parentNumber = numberOf(parent);
15
+ if (parentNumber === undefined) return false;
16
+ const normalizedChild = child.normalize("NFKC").trim();
17
+ if (FIRST_BRACKETED.test(normalizedChild)) return true;
18
+ const childNumber = numberOf(normalizedChild);
19
+ return childNumber !== undefined && childNumber.startsWith(`${parentNumber}.`) && !childNumber.slice(parentNumber.length + 1).includes(".");
20
+ };
@@ -33,8 +33,23 @@ export const mostFrequent = (words: readonly string[], count: number): string[]
33
33
  .map(([word]) => word);
34
34
  };
35
35
 
36
- const wordsOfDocument = (doc: ProseDocument): KatakanaWord[] =>
37
- doc.sentences.flatMap((sentence) => katakanaWordsIn(sentence.text, doc.names ?? []).map((word) => ({ sentence, word })));
36
+ /**
37
+ * The katakana words of the document's title: what the document is about (e-Govアカウントの登録方法). A manual on accounts
38
+ * cannot say アカウント another way, so the subject is not a loanword to trim.
39
+ */
40
+ export const subjectWords = (doc: ProseDocument): ReadonlySet<string> => {
41
+ const title = doc.markup?.headings.find((heading) => heading.depth === 1)?.text ?? "";
42
+ return new Set(katakanaWordsIn(title, doc.names ?? []));
43
+ };
44
+
45
+ const wordsOfDocument = (doc: ProseDocument): KatakanaWord[] => {
46
+ const subject = subjectWords(doc);
47
+ return doc.sentences.flatMap((sentence) =>
48
+ katakanaWordsIn(sentence.text, doc.names ?? [])
49
+ .filter((word) => !subject.has(word))
50
+ .map((word) => ({ sentence, word })),
51
+ );
52
+ };
38
53
 
39
54
  /**
40
55
  * Katakana loanwords per 1000 characters, over the whole document. Reported once, at the first sentence holding one, with the
@@ -11,7 +11,7 @@ import { restricted, type Restrictors } from "./superlative-clause.ts";
11
11
  import { stackedHedges, type StackedHedge } from "./stacked-hedge.ts";
12
12
  import { comparisonMarkersOf, counterpartBefore, onlyQuoted, quotedRange, type ComparisonMarkers } from "./superlative-comparison.ts";
13
13
  import { inPhrase, ownedBefore } from "./superlative-phrase.ts";
14
- import { asked, contextOf, pointsAtReferent, ranksParts, sought, viewpointBefore, type Context } from "./superlative-context.ts";
14
+ import { asked, contextOf, picksFromNamedSet, pointsAtReferent, ranksParts, sought, viewpointBefore, type Context } from "./superlative-context.ts";
15
15
 
16
16
  const PER = 1000;
17
17
 
@@ -156,6 +156,7 @@ const qualifiedAt = (tokens: readonly Token[], range: TokenRange, qualifiers: Qu
156
156
  viewpointBefore(tokens, range, qualifiers.context.viewpoints) ||
157
157
  pointsAtReferent(tokens, range, qualifiers.context.referents) ||
158
158
  ranksParts(tokens, range, qualifiers.context.parts) ||
159
+ picksFromNamedSet(tokens, range, qualifiers.context.proForms) ||
159
160
  restricted(tokens, range, qualifiers.restrictors) ||
160
161
  namesQuantity(tokens, range, qualifiers.quantityNouns) ||
161
162
  makesWord(tokens, range, qualifiers.suffixes) ||
@@ -7,8 +7,9 @@ import { codePointName } from "./invisible-character.ts";
7
7
  * compatibility: a CJK compatibility ideograph (or one of its supplement) that Unicode maps to a unified one (樂 U+F914 for 樂).
8
8
  * decomposed: a letter and a separate combining mark (か + U+3099 for が, e + U+0301 for é), from file names or text
9
9
  * copied on macOS. spacing-mark: kana followed by the spacing ゛ or ゜, typed in place of the combined letter.
10
+ * dash: a dash or minus between katakana (ニュ-ス, U+FF0D), typed in place of the long-vowel mark ー.
10
11
  */
11
- export type LookalikeKind = "radical" | "compatibility" | "decomposed" | "spacing-mark";
12
+ export type LookalikeKind = "radical" | "compatibility" | "decomposed" | "spacing-mark" | "dash";
12
13
 
13
14
  export type Lookalike = { readonly span: Span; readonly kind: LookalikeKind; readonly written: string; readonly usual: string };
14
15
 
@@ -48,8 +49,24 @@ const spacingMarkLookalikes = (source: string): Lookalike[] =>
48
49
  return [{ span: { start: match.index, end: match.index + match[0].length }, kind: "spacing-mark", written: match[0], usual }];
49
50
  });
50
51
 
52
+ const LONG_VOWEL = "ー";
53
+ /**
54
+ * A dash, a minus or a box line after a katakana letter that can be lengthened and before another katakana letter. The
55
+ * half-width - is left out: between katakana it joins the parts of a template or a range (<アルゴリズム>-<ハッシュ>, ァ-ヶ).
56
+ */
57
+ const DASH_FOR_LONG_VOWEL = /(?<=[ァ-ヂツ-ヲヴ-ヺ])[\u2010-\u2015\u2212\uFF0D\u2500\u2501](?=[ァ-ヺ])/gu;
58
+
59
+ /** A dash typed in place of the long-vowel mark between katakana (ニュ-ス → ニュース). */
60
+ const dashLookalikes = (source: string): Lookalike[] =>
61
+ [...source.matchAll(DASH_FOR_LONG_VOWEL)].map((match) => ({
62
+ span: { start: match.index, end: match.index + match[0].length },
63
+ kind: "dash",
64
+ written: match[0],
65
+ usual: LONG_VOWEL,
66
+ }));
67
+
51
68
  export const lookalikesIn = (source: string): Lookalike[] =>
52
- [...singleLookalikes(source), ...decomposedLookalikes(source), ...spacingMarkLookalikes(source)].toSorted(
69
+ [...singleLookalikes(source), ...decomposedLookalikes(source), ...spacingMarkLookalikes(source), ...dashLookalikes(source)].toSorted(
53
70
  (left, right) => left.span.start - right.span.start,
54
71
  );
55
72
 
@@ -6,11 +6,12 @@ import { externalLinkTitleSpans } from "../link-title.ts";
6
6
  import { formulaBracketSpans } from "../formula-brackets.ts";
7
7
  import { ownTitleQuoteSpans } from "../own-title-quote.ts";
8
8
  import { isWithinAny, quotedSpans } from "../quoted-span.ts";
9
- import { bracketPlaceholderSpans, capitalLineSpans, captionsOf, isCaptionAt, isWithinSorted } from "./caps-caption.ts";
9
+ import { bracketPlaceholderSpans, capitalLineSpans, captionsOf, isCaptionAt, isWholeQuotation, isWithinSorted } from "./caps-caption.ts";
10
10
  import { lineStarts } from "../position.ts";
11
11
  import { isTypewritten } from "./typewritten.ts";
12
12
  import { divisionLabelPattern, isDivisionSeparator } from "./division-label-separator.ts";
13
13
  import { isInCopiedText } from "./hyphen-copied-text.ts";
14
+ import { verseBlockSpans } from "./verse-block.ts";
14
15
 
15
16
  /** The letters a mark must touch to count as part of the document's text, by language. */
16
17
  const SCRIPT: Readonly<Record<string, RegExp>> = {
@@ -180,6 +181,22 @@ export const noteMarkerOffsets = (source: string): ReadonlySet<number> =>
180
181
 
181
182
  const NOTE_KIND = "\u0000note";
182
183
 
184
+ /**
185
+ * A note's number cited in the prose (注(24)で示した): an author writes it as the notes' labels are, or as the prose's
186
+ * brackets are, and either is the document's own notation for it.
187
+ */
188
+ const NOTE_ADDRESS = /(?<=[注註])(?:\([0-90-9]{1,3}\)|([0-90-9]{1,3}))/gu;
189
+
190
+ /** The offsets in `source` of the brackets of every note's cited number. */
191
+ export const noteAddressOffsets = (source: string): ReadonlySet<number> =>
192
+ new Set([...source.matchAll(NOTE_ADDRESS)].flatMap((match) => [match.index, match.index + match[0].length - 1]));
193
+
194
+ const NOTE_ADDRESS_KIND = "\u0000noteaddress";
195
+
196
+ /** A note's cited number is a kind of its own, compared only with the other cited note numbers. */
197
+ const withNoteAddressKind = (mark: Mark, addresses: ReadonlySet<number>): Mark =>
198
+ addresses.has(mark.offset) ? { ...mark, form: { ...mark.form, kind: `${mark.form.kind}${NOTE_ADDRESS_KIND}` } } : mark;
199
+
183
200
  /** A note marker's bracket is a kind of its own, compared only with the other note markers' brackets. */
184
201
  const withNoteKind = (mark: Mark, notes: ReadonlySet<number>): Mark =>
185
202
  notes.has(mark.offset) && !mark.form.kind.endsWith(ENUMERATOR_KIND) ? { ...mark, form: { ...mark.form, kind: `${mark.form.kind}${NOTE_KIND}` } } : mark;
@@ -199,8 +216,11 @@ export const markConsistency: Detector = (doc, options): Finding[] => {
199
216
  const enumerators = enumeratorBracketOffsets(doc.source);
200
217
  const doubled = doubledParenOffsets(doc.source);
201
218
  const notes = noteMarkerOffsets(doc.source);
219
+ const noteAddresses = noteAddressOffsets(doc.source);
202
220
  const marks = ownSentences(doc).flatMap((sentence) =>
203
- marksIn(doc.source, sentence, forms, script).map((mark) => withNoteKind(withDoubledKind(withEnumeratorKind(mark, enumerators), doubled), notes)),
221
+ marksIn(doc.source, sentence, forms, script).map((mark) =>
222
+ withNoteAddressKind(withNoteKind(withDoubledKind(withEnumeratorKind(mark, enumerators), doubled), notes), noteAddresses),
223
+ ),
204
224
  );
205
225
  const kinds = [...new Set(marks.map((mark) => mark.form.kind))];
206
226
  return kinds.flatMap((kind) =>
@@ -219,18 +239,25 @@ export const markConsistency: Detector = (doc, options): Finding[] => {
219
239
  const SENTENCE_END = /(?<![\p{L}\d.])\p{Ll}{2,}[.!?]["'”’)\]]?$/u;
220
240
  /** The next sentence starts with a capital, past an opening quote: not a citation ("[ISO99]") or an aside in brackets. */
221
241
  const SENTENCE_START = /^["'“‘]?\p{Lu}/u;
242
+ /** "Affiliation: …", "Note: …": a field's label opens what follows, as in an author block joined into one line. */
243
+ const FIELD_LABEL = /^\p{Lu}\p{Ll}+:\s/u;
222
244
  const ONE_SPACE = " ";
223
245
  const TWO_SPACES = " ";
224
246
 
225
- /** The space between two sentences on one line, when the first ends with a period, question or exclamation mark. spaced is two spaces. */
226
- export const sentenceGaps = (doc: ProseDocument): Sided[] =>
227
- ownSentences(doc).flatMap((sentence, at, sentences) => {
247
+ /**
248
+ * The space between two sentences on one line, when the first ends with a period, question or exclamation mark. spaced is
249
+ * two spaces. A pause inside a verse line ("I'm nobody! Who are you?") is the stanza's layout, not the prose's spacing.
250
+ */
251
+ export const sentenceGaps = (doc: ProseDocument): Sided[] => {
252
+ const stanzas = verseBlockSpans(doc.source);
253
+ return ownSentences(doc).flatMap((sentence, at, sentences) => {
228
254
  const next = sentences[at + 1];
229
- if (next === undefined || !SENTENCE_END.test(sentence.text) || !SENTENCE_START.test(next.text)) return [];
255
+ if (next === undefined || !SENTENCE_END.test(sentence.text) || !SENTENCE_START.test(next.text) || FIELD_LABEL.test(next.text)) return [];
230
256
  const gap = doc.source.slice(sentence.span.end, next.span.start);
231
- if (gap !== ONE_SPACE && gap !== TWO_SPACES) return [];
257
+ if ((gap !== ONE_SPACE && gap !== TWO_SPACES) || isWithinSorted(stanzas, { start: sentence.span.end, end: next.span.start })) return [];
232
258
  return [{ sentence: next, spaced: gap === TWO_SPACES, offset: sentence.span.end }];
233
259
  });
260
+ };
234
261
 
235
262
  /** One space between sentences and two, mixed in one document: the less common is reported. */
236
263
  export const sentenceSpacing: Detector = (doc, options): Finding[] =>
@@ -260,6 +287,20 @@ const reportFrom = (hits: readonly Hit[], limit: number): Finding[] => (hits.len
260
287
  /** A spaced hyphen or a double hyphen between words, standing for a dash ("late - very late", "late--very late"). */
261
288
  const HYPHEN_DASH = /(?<=[\p{L},;)]) -{1,2} (?=[\p{L}(])|(?<=\p{L})--(?=\p{L})/gu;
262
289
 
290
+ /** A spaced hyphen whose side is masked out of the sentence's text: a code span may stand there ("`float` - everything"). */
291
+ const MASKED_SIDE_HYPHEN = /(?<=\s) -{1,2} (?=[\p{L}(])|(?<=[\p{L},;)]) -{1,2} (?=\s)/gu;
292
+ const CODE_MARK = "`";
293
+
294
+ /**
295
+ * A spaced hyphen between a code span and a word, either way round ("`float` - everything", "two properties - `x`"). Code
296
+ * is masked out of the text, so the code side reads as spaces; the source shows the code mark right beside the hyphen.
297
+ * Code on both sides ("`query` - `form`") is a mapping, not a dash.
298
+ */
299
+ const besideCode = (source: string, hit: Hit): boolean => {
300
+ const end = hit.offset + hit.matched.length + 2;
301
+ return (source[hit.offset - 1] === CODE_MARK) !== (source[end] === CODE_MARK);
302
+ };
303
+
263
304
  /** A dash set as a character (an em dash, an en dash). */
264
305
  const TRUE_DASH = /[—–]/u;
265
306
  const DOUBLE_HYPHEN = "--";
@@ -276,10 +317,11 @@ export const hyphenDash: Detector = (doc, options): Finding[] => {
276
317
  const sentences = ownSentences(doc);
277
318
  const setsDashes = sentences.some((sentence) => TRUE_DASH.test(sentence.text));
278
319
  const divisionLabel = divisionLabelPattern((doc.lexicons["numbered-division"] ?? []).map((entry) => entry.pattern));
320
+ const codeHits = hitsOf(sentences, MASKED_SIDE_HYPHEN).filter((hit) => besideCode(doc.source, hit));
279
321
  return reportFrom(
280
- hitsOf(sentences, HYPHEN_DASH).filter(
281
- (hit) => !isTypedDash(hit, setsDashes) && !isDivisionSeparator(doc.source, hit.offset, divisionLabel) && !isInCopiedText(doc.source, hit.offset),
282
- ),
322
+ [...hitsOf(sentences, HYPHEN_DASH), ...codeHits]
323
+ .toSorted((left, right) => left.offset - right.offset)
324
+ .filter((hit) => !isTypedDash(hit, setsDashes) && !isDivisionSeparator(doc.source, hit.offset, divisionLabel) && !isInCopiedText(doc.source, hit.offset)),
283
325
  options.limit,
284
326
  );
285
327
  };
@@ -332,8 +374,8 @@ export const isShouting = (run: string, known: ReadonlySet<string>, conventional
332
374
 
333
375
  /**
334
376
  * Runs of three or more all-capital words that are ordinary words, not acronyms ("DO NOT DELETE THIS"), and not a
335
- * caption, a mention of one, a paragraph of capital lines that ends no sentence (a letterhead, a heading), a roster name, or a
336
- * placeholder in square brackets.
377
+ * caption, a mention of one, a paragraph of capital lines that ends no sentence (a letterhead, a heading), a roster name, a
378
+ * placeholder in square brackets, or a whole quotation.
337
379
  */
338
380
  export const capsShouting: Detector = (doc, options): Finding[] => {
339
381
  const known = lowerCaseWords(doc.prose ?? doc.source);
@@ -343,7 +385,13 @@ export const capsShouting: Detector = (doc, options): Finding[] => {
343
385
  const placeholders = bracketPlaceholderSpans(doc.source);
344
386
  const isCaptionOrLetterhead = (hit: Hit): boolean => {
345
387
  const span = { start: hit.offset, end: hit.offset + hit.matched.length };
346
- return captions.has(hit.matched) || isCaptionAt(doc.source, span.start, span.end) || isWithinSorted(capitalLines, span) || isWithinAny(placeholders, span);
388
+ return (
389
+ captions.has(hit.matched) ||
390
+ isCaptionAt(doc.source, span.start, span.end) ||
391
+ isWithinSorted(capitalLines, span) ||
392
+ isWithinAny(placeholders, span) ||
393
+ isWholeQuotation(doc.source, span.start, span.end)
394
+ );
347
395
  };
348
396
  const hits = hitsOf(ownSentences(doc), CAPS_RUN).filter((hit) => isShouting(hit.matched, known, conventional) && !isCaptionOrLetterhead(hit));
349
397
  return reportFrom(hits, options.limit);
@@ -1,7 +1,7 @@
1
1
  // A phrase that is mentioned rather than used: named as a term (when saying "raise the bar", the phrase "low-hanging
2
2
  // fruit", 「徹底解説」という言い方). The writer is talking about the words, not leaning on them. The cue words come from the
3
3
  // language's mention-cue word list: group before stands right before the phrase, group after right after it. Pure.
4
- import type { LexiconEntry, Sentence, Token } from "../plugin.ts";
4
+ import type { LexiconEntry, Sentence, Span, Token } from "../plugin.ts";
5
5
  import { entryEndsAt, entryRanges, type TokenRange } from "./lexicon-match.ts";
6
6
 
7
7
  const BEFORE = "before";
@@ -36,3 +36,15 @@ export const onlyMentioned = (sentence: Sentence, entry: LexiconEntry, cues: Men
36
36
  const ranges = entryRanges(sentence, entry);
37
37
  return tokens !== undefined && ranges.length > 0 && ranges.every((range) => isMention(tokens, range, cues));
38
38
  };
39
+
40
+ /** Whether every use of the entry in the sentence lies in a linked page's title: the other page's words, which the writer cites. */
41
+ export const onlyInTitles = (sentence: Sentence, entry: LexiconEntry, titles: readonly Span[]): boolean => {
42
+ const tokens = sentence.tokens ?? [];
43
+ const ranges = entryRanges(sentence, entry);
44
+ const inTitle = (start: number, end: number): boolean => titles.some((title) => start >= title.start && end <= title.end);
45
+ return (
46
+ titles.length > 0 &&
47
+ ranges.length > 0 &&
48
+ ranges.every((range) => inTitle(tokens[range.start]?.span.start ?? -1, tokens[range.end - 1]?.span.end ?? Number.POSITIVE_INFINITY))
49
+ );
50
+ };
@@ -1,3 +1,5 @@
1
+ import type { Detector, Finding } from "../plugin.ts";
2
+
1
3
  const MIDDLE_DOT = /・/gu;
2
4
 
3
5
  /** 文頭か行頭(前に空白だけ)の「・」。前に並べる項目が無いので、箇条書きの印。 */
@@ -13,3 +15,23 @@ const withoutWordDots = (text: string, words: readonly string[]): string =>
13
15
  */
14
16
  export const parallelDotCount = (text: string, words: readonly string[] = []): number =>
15
17
  [...withoutWordDots(text, words).replace(BULLET_DOT, "$1").matchAll(MIDDLE_DOT)].length;
18
+
19
+ /**
20
+ * 中黒で並べると、どこまでが 1 つの項目か分からなくなる。
21
+ * 「企画・開発・運用・保守体制」は、保守体制が 1 つなのか保守と体制なのか読めない。
22
+ * 語彙表(nakaguro-word)の、中黒を含めて 1 語の語(キャッシュ・フロー)の中黒は並べていないので数えない。
23
+ */
24
+ export const middleDot: Detector = (doc, options): Finding[] => {
25
+ const words = (options.lexicon ?? []).map((entry) => entry.pattern).toSorted((left, right) => right.length - left.length);
26
+ return doc.sentences
27
+ .map((sentence) => ({ sentence, count: parallelDotCount(sentence.text, words) }))
28
+ .filter(({ count }) => count > options.limit)
29
+ .map(({ sentence, count }) => ({
30
+ rule: "no-nakaguro-parallel",
31
+ severity: "info",
32
+ line: 0,
33
+ column: 0,
34
+ quote: sentence.text.trim(),
35
+ values: { count, limit: options.limit, offset: sentence.span.start },
36
+ }));
37
+ };
@@ -0,0 +1,15 @@
1
+ /** 連なりの前後の字と、名前を示す句の語彙。 */
2
+ type Surroundings = { readonly before: string; readonly next: string };
3
+ type ContextWords = { readonly designations: readonly string[]; readonly noticeEndings: readonly string[] };
4
+
5
+ /** 連なりの後ろ(next)が、制度が区分に入れることを言う句で始まるか(認定希少種保全動植物園等として認定)。 */
6
+ const isDesignated = (run: Surroundings, words: ContextWords): boolean => words.designations.some((phrase) => run.next.startsWith(phrase));
7
+
8
+ /** 行がお知らせの題で、連なりがその「の」の前か([e-Gov]〜設定解除完了のお知らせ)。題は句点で閉じない一行。 */
9
+ const isNoticeTitle = (run: Surroundings, words: ContextWords): boolean => {
10
+ const next = run.next.trim();
11
+ return !run.before.includes("\n") && words.noticeEndings.some((ending) => next === `の${ending}`);
12
+ };
13
+
14
+ /** 前後の字が、漢字の連なりを名前と示しているか: 制度が決めた区分の名前か、送り手が付けたお知らせの題の名前。 */
15
+ export const isNamedByContext = (run: Surroundings, words: ContextWords): boolean => isDesignated(run, words) || isNoticeTitle(run, words);
@@ -63,12 +63,25 @@ const isBeforeLongerWord = (numeral: string, written: string, offset: number, to
63
63
  return word !== undefined && word.surface.length > counter.length;
64
64
  };
65
65
 
66
+ /** The ordinal suffix (三枚目): a word the tokenizer joins to a count that is still a number of things. */
67
+ const ORDINAL_SUFFIX = "目";
68
+
69
+ /**
70
+ * A kanji numeral and counter that open a longer word (二枚貝, 二枚舌, 三人称): the tokenizer reads the whole as one noun, a name
71
+ * for a thing rather than a count of it, and digits could not be written there.
72
+ */
73
+ const isInsideWord = (written: string, offset: number, tokens: readonly Token[]): boolean => {
74
+ const word = tokens.find((token) => token.span.start === offset);
75
+ if (word === undefined || word.surface.length <= written.length || !word.surface.startsWith(written)) return false;
76
+ return word.surface.slice(written.length) !== ORDINAL_SUFFIX;
77
+ };
78
+
66
79
  const countMarks = (text: string, base: number, words: NumberWords, tokens: readonly Token[]): NumberMark[] => {
67
80
  const pattern = countPattern(words);
68
81
  if (pattern === undefined) return [];
69
82
  return [...text.matchAll(pattern)].flatMap((match): NumberMark[] => {
70
83
  const [written, digits, kanji] = match;
71
- if (kanji !== undefined && isIdiomNumeral(kanji)) return [];
84
+ if (kanji !== undefined && (isIdiomNumeral(kanji) || isInsideWord(written, base + match.index, tokens))) return [];
72
85
  if (isBeforeLongerWord(digits ?? kanji ?? "", written, base + match.index, tokens)) return [];
73
86
  return [{ kind: "count", style: digits === undefined ? "kanji" : "digits", written, offset: base + match.index }];
74
87
  });