From 02e2df4ff88078c96fa8022ee8d8c9a29ba42bea Mon Sep 17 00:00:00 2001 From: albert4719 Date: Sat, 19 Sep 2026 12:48:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E7=B4=A2=E9=A1=B5=EF=BC=9A=E6=9D=A5?= =?UTF-8?q?=E6=BA=90=E5=88=87=E5=88=86=E8=AE=A4=E6=8B=AC=E5=8F=B7=E5=92=8C?= =?UTF-8?q?=E5=BC=95=E5=8F=B7=EF=BC=8C=E6=B3=95=E6=9D=A1=E5=BC=95=E6=96=87?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E5=88=86=E5=8F=B7=E4=B8=8D=E5=86=8D=E8=A2=AB?= =?UTF-8?q?=E5=BD=93=E6=88=90=E5=88=86=E9=9A=94=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 来源栏按「;」切条,但法条原文里有「……代理或者追认;……」,条款注里有 「修改刑法第三百九十条;自 2024 年 3 月 1 日起施行」,按裸分号切会把一条来源 劈成好几条,「来源 · N 条」也跟着算错。改成按「」『』()的深度切分。 全书 540 行来源里 20 行的条数因此改正,最多的一处从 11 条并回 3 条; 540 行的括号全部配平,不存在反过来漏切的情况。 --- index.html | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 534d715..75e212f 100644 --- a/index.html +++ b/index.html @@ -573,10 +573,24 @@ function renderText(el, text, terms, withTerms = true, urlsLast = false){ if (withTerms) termify(el); } // 来源栏是「;」串起来的若干条文献,拆成带序号的列表,一条一行 -const SRC_SPLIT_RE = /;|\s+;\s+/; +// 括号和引号里的分号不算分隔符:法条原文里有「……代理或者追认;……」,条款注里有「第五项,修改刑法第三百九十条;自 2024 年 3 月 1 日起施行」 +const SRC_OPEN = '「『(', SRC_CLOSE = '」』)'; +function splitSrc(text){ + const parts = []; let buf = '', depth = 0; + for (let i = 0; i < text.length; i++){ + const c = text[i]; + if (SRC_OPEN.includes(c)) depth++; + if (SRC_CLOSE.includes(c)) depth = Math.max(0, depth - 1); + const semi = c === ';' || (c === ';' && /\s/.test(text[i-1] || '') && /\s/.test(text[i+1] || '')); + if (semi && depth === 0){ parts.push(buf); buf = ''; continue; } + buf += c; + } + parts.push(buf); + return parts.map(s => s.trim()).filter(Boolean); +} function renderSrc(el, text, terms){ el.textContent = ''; - const parts = text.split(SRC_SPLIT_RE).map(s => s.trim()).filter(Boolean); + const parts = splitSrc(text); if (parts.length < 2){ renderText(el, text, terms, true, true); return parts.length; } const ol = document.createElement('ol'); for (const p of parts){ const li = document.createElement('li'); renderText(li, p, terms, true, true); ol.appendChild(li); }