mirror of
https://github.com/dergigi/boris.git
synced 2026-02-23 07:54:59 +01:00
fix(highlights): remove existing highlight marks before applying new ones
- Strip all existing mark elements from HTML before re-highlighting - Prevents old broken highlights from persisting in the DOM - Ensures clean text is used as the base for new highlight application - Fixes 'We b' spacing issue caused by corrupted marks from previous buggy renders - Remove debug logging now that position mapping is working correctly
This commit is contained in:
@@ -22,6 +22,17 @@ export function applyHighlightsToHTML(
|
||||
const tempDiv = document.createElement('div')
|
||||
tempDiv.innerHTML = html
|
||||
|
||||
// CRITICAL: Remove any existing highlight marks to start with clean HTML
|
||||
// This prevents old broken highlights from corrupting the new rendering
|
||||
const existingMarks = tempDiv.querySelectorAll('mark[data-highlight-id]')
|
||||
existingMarks.forEach(mark => {
|
||||
// Replace the mark with its text content
|
||||
const textNode = document.createTextNode(mark.textContent || '')
|
||||
mark.parentNode?.replaceChild(textNode, mark)
|
||||
})
|
||||
|
||||
console.log('🧹 Removed', existingMarks.length, 'existing highlight marks')
|
||||
|
||||
let appliedCount = 0
|
||||
|
||||
for (const highlight of highlights) {
|
||||
|
||||
Reference in New Issue
Block a user