Repository navigation
fix: end paragraph_close after the last content character in containers - #25
Open
galaxian85 wants to merge 1 commit into
Open
galaxian85 wants to merge 1 commit into
galaxian85 wants to merge 1 commit into
Conversation
…rs (DEV-3359) paragraph_close.position was start + content.length, which misses the container markers (`> `) dropped before later lines of a multi-line paragraph. Add the line offset of the line holding the last content character: contentLine (where the trimmed content starts, offsets rebased by trimmedContentStart) plus the newlines in the trimmed content, so trailing whitespace trimmed away, even whole lines, is not counted. The inline token size stays content.length (hackmd-production computes GitHub alert titles in content coordinates from it); document that in Token#size and the paragraph and lheading rules. Rendered HTML is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage Report for CI Build 44262088967Warning No base build found for commit Coverage: 99.326%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats💛 - Coveralls |
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.
摘要
修正 Linear DEV-3359:在 blockquote 等容器裡,多行段落的
paragraph_close.position偏短。第二行開始,每一行都少算被拿掉的>前綴長度。這個問題在 #22 之前就存在。這是 14.2.1 批次的一部分,merge 後先不要發版。 等 14.2.1 的其他項目都 merge 後再一起發版。
> a\n> b *c* d\n> e> > a\n> > b\n> > c> a\nb lazy\n> c- > a\n > b> [!NOTE]\n> b *c* d\n> e輸出的 HTML 不變。inline 子 token 的位置本來就正確,這次不動。
修法
lib/rules_block/paragraph.mjs:contentLine是trimmedContentStart找到的 content 起始行;lineOffsets已經從這一行重新起算。content裡的換行數,就是最後一個字元所在的行,再加上那一行的 offset。trim()拿掉的空白不會算進去,包括整行的 U+00A0。tab 補的 padding 已經在lineOffsets裡扣掉。start,和以前一樣。和 Linear 的建議做法一樣,只是改成從 trim 後的
content往下數行數,不必另外回頭算 trim 前的字串。沒有改的部分
size維持content.length(2026-11-18 決定)。hackmd-production 的githubAlertsPositionPlugin.js在 content 座標裡用oldPos + oldSize - newSize算 alert title 的長度。如果size改成原始碼長度,alert 的位置會出錯,兩邊就必須一起升級。這次在Token#size的 JSDoc 和 paragraph/lheading 的註解寫清楚這個定義,並加了測試鎖住。lheading.mjs的heading_close本來就正確,只補了註解。文件
lib/token.mjs:Token#position說明paragraph_close的位置;Token#size說明 inline 的size是 content 長度。CHANGELOG.md:新增[14.2.1] - Unreleased。測試
test/annotation.js新增 4 個測試。修正前,其中 3 個會失敗:zwspIndent開和關各跑一次。檢查三件事:src[paragraph_close.position - 1]是 content 的最後一個字元;inline.position到paragraph_close.position之間的原始碼以這個字元結尾;這個字元在 content 最後一行對應的原始碼行。size等於content.length,修正前後都通過。npm test(Node 24):1624 passing、1 pending,lint 通過。hackmd-production 驗證
在 hackmd-production 用 symlink 換成這個 branch build 出來的 fork,用
bin/agent/test跑和 markdown 相關的 spec,包括test/browser/render/position-invariant.test.ts(涵蓋 alert)、code-source-map、excerpt、linkify-position、markdown-it-plugins,以及 render 相關的測試:用的是 hackmd-production#6100 的 branch(已升到 14.2.0),因為 fork 的 master 已經包含 DEV-3358 的
srcLineStarts改動,要搭配 #6100 才對。hackmd-production 不需要改 code,14.2.1 發版後升級依賴就可以。🤖 Generated with Claude Code