fix: missing pos/size on linkify text token - #20
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
size is computed from normalized display text length, which can diverge from the original source span and still produce incorrect highlight ranges.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR addresses incorrect source-range metadata for linkified URLs by adding missing position and size to the text token produced by the inline linkify rule, so downstream consumers (e.g., highlighting) can map link tokens back to the original source correctly.
Changes:
- Set
token_t.positionfor inline linkify text tokens to the start of the matched URL. - Set
token_t.sizefor inline linkify text tokens to represent the token span length.
File summaries
| File | Description |
|---|---|
| lib/rules_inline/linkify.mjs | Adds position/size metadata to the linkified text token to improve source mapping for link ranges. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The new position calculation does not apply blockquote/alert line offsets (getLineOffset), which can still produce incorrect source-span mapping in those contexts.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
| const token_t = state.push('text', '', 0) | ||
| token_t.content = state.md.normalizeLinkText(url) | ||
| token_t.position = pos - proto.length | ||
| token_t.size = url.length |
| token_t.position = pos - proto.length | ||
| token_t.size = url.length |
https://linear.app/hackmd-product/issue/DEV-3100/emoji-reply-%E9%A1%AF%E7%A4%BA%E4%BD%8D%E7%BD%AE%E5%81%8F%E7%A7%BB
這個 issue 的原因是因為 linkify 的 text token 沒有給 pos/size 資訊
導致 link 的 pos = block 的起點, size = 0
所以同一個 block 裡面的 highlight 會被重複上在 link 上面