Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
export function escapeHtml(text) {
|
||||
return String(text)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
|
||||
export function highlightDiff(text, diffRanges) {
|
||||
if (!diffRanges || diffRanges.length === 0) {
|
||||
return escapeHtml(text)
|
||||
}
|
||||
|
||||
let result = ''
|
||||
let lastIndex = 0
|
||||
|
||||
diffRanges.forEach(range => {
|
||||
if (range.start > lastIndex) {
|
||||
result += escapeHtml(text.substring(lastIndex, range.start))
|
||||
}
|
||||
result += `<span class="diff-highlight">${escapeHtml(text.substring(range.start, range.end))}</span>`
|
||||
lastIndex = range.end
|
||||
})
|
||||
|
||||
if (lastIndex < text.length) {
|
||||
result += escapeHtml(text.substring(lastIndex))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user