Elffuss BraidHub

kikocis/utopia public

The references section was never cut, because the heading was never symmetric (#164)

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Changeset118ff21ce523ee2488daad930672a646d7b7d1ac67580cfc3cba773ed8a4e088
AuthorWaylandYang <145302500+WaylandYang@users.noreply.github.com> · 2026-09-02 09:06 +08:00
CommitterGitHub <noreply@github.com> · 2026-09-02 09:06 +08:00
Parents285aeaf026e6

Browse the files at this changeset

1 file changed

modified scripts/bench/fetch-wiki-history.mjs +15 −2
@@ -197,8 +197,19 @@
197197 }
198198
199199 // 末尾的 References / External links 全是链接和模板残渣,抽取器会把它们当正文。切掉。
200+//
201+// **收尾侧写 `=+` 而不是 `==+`,是有意宽一格的。** 这里曾经两边都是 `==+`,
202+// 而下面 h 标签的转换开标签按层级铺 `=`、闭标签硬编码了一个,于是二级标题
203+// 落成 `== References =`,这条正则一次都没匹配上——**每一篇快照的整个参考
204+// 文献区都进了抽取**。实测 414 块里 223 块(54%)是引文残渣,产出的是
205+// `Wired --employee--> Steven Levy` 这种把记者署名当雇佣关系的事实,
206+// 还占着 supersedes 机制。
207+//
208+// 闭标签那侧已经修好,但这条仍然放宽:标题两侧对不对称是渲染的事,而这里
209+// 要判的是「从哪儿开始不要了」。宽一格换来同类错配再也打不穿它,代价是可能
210+// 多切一个 `= Foo =` 形状的一级标题——那种标题在条目正文里不出现。
200211 const CUT =
201- /\n==+ ?(References|External links|See also|Further reading|Notes|Bibliography|Sources|Citations) ?==+/i;
212+ /\n==+ ?(References|External links|See also|Further reading|Notes|Bibliography|Sources|Citations) ?=+/i;
202213
203214 /// 取某一版的正文。历史版本没有 `prop=extracts`(那个只认当前版),
204215 /// 所以走 `action=parse&oldid=` 拿渲染后的 HTML,再剥成纯文本。
@@ -217,7 +228,9 @@
217228 .replace(/<sup class="reference"[\s\S]*?<\/sup>/gi, "") // 脚注角标
218229 .replace(/<span class="mw-editsection"[\s\S]*?<\/span>/gi, "")
219230 .replace(/<h([1-6])[^>]*>/gi, (_, n) => "\n\n" + "=".repeat(+n) + " ")
220- .replace(/<\/h[1-6]>/gi, " " + "=" + "\n")
231+ // 闭标签也按层级铺,跟上一行对称。硬编码一个 `=` 会让二级标题落成
232+ // `== References =`,而 CUT 那边在等 `==`,于是尾节永远切不掉。
233+ .replace(/<\/h([1-6])>/gi, (_, n) => " " + "=".repeat(+n) + "\n")
221234 .replace(/<li[^>]*>/gi, "\n- ")
222235 .replace(/<\/(p|div|li|tr)>/gi, "\n")
223236 .replace(/<br\s*\/?>/gi, "\n")