From 65a9df561ed7d20401571d026f18ed7d3e18ac1c Mon Sep 17 00:00:00 2001 From: commilitia Date: Fri, 12 Jun 2026 17:23:11 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=B8=89=E5=88=86=E9=A1=9E=E5=84=AA?= =?UTF-8?q?=E5=85=88=E5=BA=8F=E5=A5=91=E7=B4=84=E2=80=94=E2=80=94pill=20?= =?UTF-8?q?=E8=A1=8C=E7=82=BA=E8=A6=86=E8=93=8B=20isolate=EF=BC=88?= =?UTF-8?q?=E5=85=A9=E7=AB=AF=E8=A3=9C=E9=9A=99=E5=90=8C=E5=8F=A3=E5=BE=91?= =?UTF-8?q?=E3=80=81=E9=9B=99=E5=91=BD=E4=B8=AD=20pill=20=E5=8B=9D?= =?UTF-8?q?=E5=87=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 實證後鎖定契約:pill 與 isolate 之邊界口徑完全相同(同一段 processPills 邊界處理, 兩端補隙/斷 run/斷相鄰/不可切分),差異僅在內部(pill 不可見、isolate 照常); 同一元素同時命中兩選擇器時 pill 語義勝出(collectRuns/jiyaAdjacency 均 pill 先判)。 新增契約測試(113 全綠);README 三分類要點+types.ts 選項註記補優先序說明。 --- README.md | 2 ++ dist/types.d.ts | 3 ++- src/types.ts | 3 ++- test/juzhen.test.mjs | 11 +++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 687f14e..5c967f6 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,8 @@ createJuzhen({ - **判定以元素為準、非標籤名**:KaTeX 全樹皆 ``,但 `.katex` 命中 `pillSelector` 即為整體邊界——舊版按標籤名判透明曾整棵下潛、把公式內側末字連同殼層克隆切出(肢解)。 +- **pill 行為覆蓋 isolate**:兩者邊界口徑完全相同(兩端補隙、斷 run/斷相鄰、不可切分, + 同一段邊界處理代碼),差異僅在內部;同一元素同時命中兩選擇器時 **pill 勝出**(內部不可見)。 - **禁則之整體綁定**:pill 緊鄰禁則標點時(`…$公式$,`),整個 pill 作為原子鄰字單位 綁入 `jz-jinze`(公式本不可斷,無額外代價);隔離元素同樣整綁(切分背景盒有可見接縫)。 - **`scope.avoid`/`skipAttribute`/`data-jz-skip` 以自身判定**:命中元素自身即邊界、 diff --git a/dist/types.d.ts b/dist/types.d.ts index 413fb02..9a98389 100644 --- a/dist/types.d.ts +++ b/dist/types.d.ts @@ -78,7 +78,8 @@ export interface JuzhenOptions { styleInlines?: string[]; blockTags?: string[]; skipTags?: string[]; - /** 整體(pill)元素選擇器(預設 "code, kbd")。 */ + /** 整體(pill)元素選擇器(預設 "code, kbd")。pill 之邊界口徑與 isolate 完全 + * 相同(行為覆蓋),差異僅在內部不可見;同元素雙選擇器命中時 pill 勝出。 */ pillSelector?: string; /** 內外隔離元素選擇器(預設 "mark")。傳 "" 停用(mark 回歸透明)。 */ isolateSelector?: string; diff --git a/src/types.ts b/src/types.ts index c1310ca..afb4ffd 100644 --- a/src/types.ts +++ b/src/types.ts @@ -107,7 +107,8 @@ export interface JuzhenOptions styleInlines?: string[]; blockTags?: string[]; skipTags?: string[]; - /** 整體(pill)元素選擇器(預設 "code, kbd")。 */ + /** 整體(pill)元素選擇器(預設 "code, kbd")。pill 之邊界口徑與 isolate 完全 + * 相同(行為覆蓋),差異僅在內部不可見;同元素雙選擇器命中時 pill 勝出。 */ pillSelector?: string; /** 內外隔離元素選擇器(預設 "mark")。傳 "" 停用(mark 回歸透明)。 */ isolateSelector?: string; diff --git a/test/juzhen.test.mjs b/test/juzhen.test.mjs index 12f622b..2208de4 100644 --- a/test/juzhen.test.mjs +++ b/test/juzhen.test.mjs @@ -1093,6 +1093,17 @@ test("isolate revert:mark 整綁+邊界間隙還原——DOM 回原樣", () assert.equal(document.querySelector("p").innerHTML, before, "render→revert 還原一致(I6)"); }); +test("三分類優先序:pill 行為覆蓋 isolate——兩端補隙同口徑,雙選擇器同命中時 pill 勝出", () => +{ + // pill 之邊界口徑=isolate(兩端補隙),差異僅在內部;同一元素同時命中 + // pillSelector 與 isolateSelector 時,pill 語義(內部不可見)勝出。 + const { document } = setupDom('

前文內,文後文

'); + createJuzhen({ pillSelector: ".x", isolateSelector: "mark", jinze: false }) + .render(document.body); + assert.equal(countTag(document.body, "jz-hws"), 2, "兩端各一間隙(同 isolate 口徑)"); + assert.equal(countTag(document.body, "mark jz-char"), 0, "內部不可見(pill 勝出,標點不 charify)"); +}); + // ----- v1 相容層移除 ----- test("v1 相容層已移除:createCjkAutospace 不再導出(消費端已全數遷移 v2 API)", async () =>