mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
fix: prevent double-processing of markdown to avoid nested links
Added check to detect if markdown has already been processed by looking for our internal routes (/a/naddr1... or /p/npub1...) in markdown links. If found, skip re-processing to prevent nested markdown link issues. This addresses timing issues where markdown might be processed multiple times, causing nostr URIs that were already converted to links to be processed again, creating nested/duplicated markdown link structures.
This commit is contained in:
@@ -123,6 +123,18 @@ function replaceNostrUrisSafely(
|
||||
const existingLinkCount = (markdown.match(/\]\(/g) || []).length
|
||||
console.log('[nostrUriResolver] Existing markdown links in input:', existingLinkCount)
|
||||
|
||||
// Check if markdown already contains our internal routes (indicates it's been processed)
|
||||
// This prevents double-processing which can cause nested links
|
||||
const hasInternalRoutes = /\]\(\/(?:a|p)\/[a-z0-9]+1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}\)/i.test(markdown)
|
||||
if (hasInternalRoutes) {
|
||||
// Count how many internal routes we see
|
||||
const internalRouteMatches = markdown.match(/\]\(\/(?:a|p)\/[a-z0-9]+1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}\)/gi) || []
|
||||
console.log('[nostrUriResolver] ⚠️ WARNING: Markdown appears to already be processed (contains', internalRouteMatches.length, 'internal routes like /a/naddr1... or /p/npub1...)')
|
||||
console.log('[nostrUriResolver] Skipping re-processing to avoid nested links')
|
||||
// Return as-is - don't process again
|
||||
return markdown
|
||||
}
|
||||
|
||||
// Track positions where we're inside a markdown link URL
|
||||
// Use a parser approach to correctly handle URLs with brackets/parentheses
|
||||
const linkRanges: Array<{ start: number, end: number }> = []
|
||||
|
||||
Reference in New Issue
Block a user