akiomik / akiomik/nostui

Reference::find tells a renderer neither where a mention was nor that one was dropped

未关闭
#566 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
Rust
星标
71
派生
5
平均合并
4 小时 2 分钟
30 天内合并 PR
31

描述

Noticed while reviewing [#564](https://github.com/akiomik/nostui/pull/564). Pre-existing; not worth changing there, because nothing renders NIP-27 yet and the right shape depends on what the renderer needs.

`Reference::find` returns `Vec`, and a `Reference` is `{ nip21, value }`. Two things a renderer will want are missing from that.

## No byte span

Turning a mention into a link means replacing a range of the note with styled text. `find` knows the range — `regex::Match` carries `start()` and `end()` — and throws it away, keeping only the matched string. The renderer would have to search the text again for each `value` to recover what the regex already had, and a note that mentions the same pubkey twice makes that search ambiguous.

## A lexically valid URI that fails to parse vanishes

The pattern accepts `[a-z0-9]{58}` without checking the bech32 checksum, so a mistyped npub matches and then `Nip21::parse` fails. `filter_map` with `.ok()` drops it, and nothing distinguishes that from text that never looked like a mention:

```rust
// verified against the current implementation
let bad = "nostr:npub1f5uuywemqwlejj2d7he6zjw8jz9wr0r5z6q8lhttxj333ph24cjsymjmuh";
assert_eq!(Reference::find(bad), vec![]);
```

Rendering it as plain text is very likely the right behaviour — but it should be a decision the renderer makes, not one the parser makes silently. Today a typo'd mention and ordinary prose are the same thing to the caller.

## Shape

Both point the same way: carry the span on `Reference`, and give the caller a way to see a rejected match rather than a shortened list. Which of the two the renderer actually needs should decide the details, so this is better settled when NIP-27 rendering is wired up than before.

## Acceptance

- A caller can style a mention without searching the note text for it again.
- A URI that matches the pattern but fails `Nip21::parse` is distinguishable from no match at all.

贡献指南

打开贡献指南

调研方向

Start at Reference::find and inspect how regex::Match ranges and Nip21::parse failures are handled. Trace the NIP-27 rendering entry point to determine the needed result shape, then verify that callers can style mentions by span and distinguish rejected URI matches from no match.

由索引模型根据 Issue 内容生成。

评估

技术栈
rust
领域
cli
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
活跃
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。