Repository navigation
fix: cover the last line in the size of an unclosed fence (DEV-3424) - #28
Open
galaxian85 wants to merge 1 commit into
Open
galaxian85 wants to merge 1 commit into
galaxian85 wants to merge 1 commit into
Conversation
A fence without a closing marker (closed by the end of the document or of its container) took its size from wherever the closing marker search stopped, so it ended short of its last line or past its newline. End it at the end of the last line in its map, without the newline, like a closed fence. position, content, map, meta and the rendered HTML are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage Report for CI Build 45764242818Coverage increased (+0.001%) to 99.337%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
This was referenced Nov 26, 2026
Open
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DEV-3424
問題
fence 沒有結尾的 marker 時(一直延伸到文件或容器結尾),
size = pos - originalPos裡的pos停在搜尋結尾 marker 的迴圈最後檢查的地方:可能在那一行的開頭,也可能在中間。所以size可能沒蓋到最後一行,也可能多蓋到換行。這在 #22 之前就有(DEV-3267 的「Pre-existing gaps」)。position、size、涵蓋的範圍)```\nx\ny```\nx\n```\nx\ny> ```\n> x\n> y```\n> x\n>```\n> x\n> y- ```\n x\n y```\n x\n```\n x\n y> ```\n> x\n\ny(blockquote 結束)```\n>```\n> x- ```\n x\ny(縮排變少)```\n x\n(多蓋到換行)```\n x```\nx\n``` y(最後一行不是合法的結尾 marker)```js(只有開頭那一行)``````js修法和慣例
只改
lib/rules_block/fence.mjs:沒有結尾 marker 時,size = state.eMarks[nextLine - 1] - originalPos。也就是結束在map最後一行的行尾,不含換行。有結尾 marker 的 fence 本來就結束在結尾那一行的行尾,規則相同。只有開頭那一行的 fence 結束在那一行的行尾,會包含 info string。結尾有空行時(
```\nx\ny\n\n,map是 [0, 4]),照 issue 的建議結束在最後一個空行的開頭(size8,和 14.2.0 一樣)。沒有改成「結束在最後一個非空行」,因為map和content都包含結尾的空行。結束在map最後一行的行尾,不管 fence 有沒有結尾 marker,position + size都和map一致。有結尾 marker 的 fence 走的是原本的路徑,位置不變。
position、content、map、meta.srcLineStarts和輸出的 HTML 都不變。hackmd-production 有沒有讀 fence 的
size?有兩個地方,都不用改 code。
universal/markdownService/helper.ts(extractExcerpt,第 17–18、56 行):每個 token 都會算end = position + size,fence在contentTokenNames裡;anchor 的起點在end或之後時,就跳過這個 fence。文字本身由sourceToCodeContentIndex(position、meta、content)取得。在 14.2.0,comment 錨在沒有結尾 marker 的 fence 最後一行時,fence 的 excerpt 是空的。用臨時 spec(已刪除)比較 npm 14.2.0 和這個 branch:```\nx\nyz,anchor 在yz:""→"yz"(blockquote、list 裡也一樣)- ```\n x\ny,anchor 在x後面的換行:"\n"→""。舊的size多蓋到那個換行。universal/markdownService/plugins/githubAlertsPositionPlugin.js:53-67:對alert_open和第一個inline之間的 token,用position + size改寫position。fence 只有在標題段落之前才會出現在這裡。沒有結尾 marker 的 fence 會把 blockquote 剩下的部分都吃掉,所以不會走到這個迴圈;有結尾 marker 的 fencesize不變。其他地方都沒有讀 fence 的
size:codeSourceMap.ts(universal 和 frontend)用的是position、markup、info、meta和content。data-position,但不輸出data-size;只有code_block會輸出data-size。data-size,fence 的區塊不會有這個屬性。測試
test/annotation.js新增 3 個測試,放在should annotate code blocks後面,避免和 fix: end paragraph_close after the last content character in containers #25–fix: table cell positions for rows without a leading or trailing pipe (DEV-3395) #27 衝突:```、```\n、```js、```js\n);~~~;結尾 marker 太短;結尾有空行;blockquote、list 裡被容器結束。position和size。map最後一行的行尾。npm test:1623 passing、1 pending(master 是 1620),lint 通過。size,每種設定 201 個,全部是沒有結尾 marker 的 fence,現在都結束在map最後一行的行尾。其他欄位都沒有變。develop,已包含 #6100、已是 14.2.0),把@hackmd/markdown-it換成指向這個 branch 的 symlink:node 8 個檔案、135 個測試,browser 15 個檔案、163 個測試,全過,和同一個 commit 上用 npm 14.2.0 的結果相同。發版
這是 14.2.1 批次(patch)的一部分。merge 後請先不要發版,等其他項目都 merge 後再一起發 14.2.1。CHANGELOG 新增了
[14.2.1] - Unreleased段落,會和 #25/#26/#27 衝突,後 merge 的 PR 要把### Fixed合併起來。🤖 Generated with Claude Code