feat: render >>{number} as interactive quote links with hover preview

Added bidirectional `usePostNumberStore` for post number ↔ CID mapping, populated from thread views. Preprocesses `>>{number}` into markdown links, renders them via `NumberQuoteLink` and `ReplyQuotePreview`, and deduplicates against `quotedCids` when both refer to the same post.
This commit is contained in:
plebeius
2026-02-10 16:23:06 +08:00
parent db70a9148b
commit c4b6c77d4c
4 changed files with 73 additions and 1 deletions
+9 -1
View File
@@ -180,14 +180,22 @@ export const isValidCrossboardPattern = (pattern: string): boolean => {
return isValidDomain(pathPart) || isValidIPNSKey(pathPart);
};
// Transform >>{number} post number patterns to markdown links with special anchor
const preprocessPostNumberPatterns = (content: string): string => {
// Match >> followed by digits, avoid overlap with greentext (>>>), cross-board (>>>/), URLs, CID-like patterns
const pattern = /(?<![>/\w])>>(\d+)(?![\d/])/g;
return content.replace(pattern, (_, num) => `[>>${num}](#q-${num})`);
};
// Preprocess content to convert plain text 5chan cross-board patterns to markdown links
export const preprocess5chanPatterns = (content: string): string => {
const withPostNumbers = preprocessPostNumberPatterns(content);
// Pattern to match ">>>/something" or ">>>/something/cid"
// Negative lookbehind prevents matching patterns that are already part of URLs
// Matches: >>>/directory/, >>>/directory/cid (46 chars), >>>/address, >>>/address/cid (46 chars)
const pattern = /(?<!https?:\/\/[^\s]*)>>>\/([a-zA-Z0-9]{1,10}\/(?:[a-zA-Z0-9]{46})?|[a-zA-Z0-9\-.]+(?:\/[a-zA-Z0-9]{46})?)[.,:;!?]*/g;
return content.replace(pattern, (match, capturedPath) => {
return withPostNumbers.replace(pattern, (match, capturedPath) => {
// Remove any trailing punctuation from the captured path
const cleanPath = capturedPath.replace(/[.,:;!?]+$/, '');
const fullPattern = `>>>/${cleanPath}`;