Skip to content

fix: missing pos/size on linkify text token - #20

Open
galaxian85 wants to merge 2 commits into
masterfrom
fix/linkify-text-token-missing-pos
Open

fix: missing pos/size on linkify text token#20
galaxian85 wants to merge 2 commits into
masterfrom
fix/linkify-text-token-missing-pos

Conversation

@galaxian85

Copy link
Copy Markdown

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 上面

image

Copilot AI lite review requested due to automatic review settings September 9, 2026 09:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.position for inline linkify text tokens to the start of the matched URL.
  • Set token_t.size for 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.

Comment thread lib/rules_inline/linkify.mjs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 9, 2026 10:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment on lines 46 to +49
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
Comment on lines +48 to +49
token_t.position = pos - proto.length
token_t.size = url.length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants