Fri Apr 04 2025
tucker.mcknight@gmail.com
f5b03f3e5a762b3b8b513f3e53e61baafa687ecc
const language = element.attributes['data-language'].value
const language = element.attributes['data-language']?.value || "javascript"
const diffType = element.attributes['data-type'].value const diffIndex = element.attributes['data-diff-index'].value
const diffRanges = diffType === 'before' ? diffMarkers[diffIndex].before
:
diffMarkers[diffIndex].after
if (diffRanges === undefined || diffRanges.length === 0) {
return
const diffType = element.attributes['data-type']?.value || "file"
const diffIndex = element.attributes['data-diff-index']?.value || "1"
let diffRanges = null
switch (diffType) {
case "before":
diffRanges = diffMarkers[diffIndex].before
case "after":
diffRanges = diffMarkers[diffIndex].after
const realRanges = diffRanges.map((diffRange) => {
const realRange = []
let conceptualCharacter = 0
let inATag = false
for (let i = 0; i < result.length; i++) {
// Chomp along until we find diffRange[0]. Increment "conceptualCharacter"
// when we are in a part of the string that is *not* part of an HTML tag that
// highlightjs added. Keep going until conceptualCharacter == diffRange[0].
if (conceptualCharacter === diffRange[0]) {
realRange[0] = i
if (diffRanges !== undefined && diffRanges !== null && diffRanges.length !== 0) {
const realRanges = diffRanges.map((diffRange) => {
const realRange = []
let conceptualCharacter = 0
let inATag = false
for (let i = 0; i < result.length; i++) {
// Chomp along until we find diffRange[0]. Increment "conceptualCharacter"
// when we are in a part of the string that is *not* part of an HTML tag that
// highlightjs added. Keep going until conceptualCharacter == diffRange[0].
if (conceptualCharacter === diffRange[0]) {
realRange[0] = i
}
if (conceptualCharacter === diffRange[1]) {
realRange[1] = i
break
}
if (result[i] === "<") {
inATag = true
continue
}
if (result[i] === ">") {
inATag = false
continue
}
else if (inATag === false) {
conceptualCharacter++
}
if (conceptualCharacter === diffRange[1]) {
realRange[1] = i
break
}
if (result[i] === "<") {
inATag = true
continue
}
if (result[i] === ">") {
inATag = false
continue
}
else if (inATag === false) {
conceptualCharacter++
}
}
return realRange
})
// add red/green span tags on each realRange
realRanges.forEach((range) => {
result = [result.slice(0, range[0]), "<span class='diff-region'>", result.slice(range[0], range[1]), "</span>", result.slice(range[1])].join('')
})
return realRange
})
// add red/green span tags on each realRange
realRanges.forEach((range) => {
result = [result.slice(0, range[0]), "<span class='diff-region'>", result.slice(range[0], range[1]), "</span>", result.slice(range[1])].join('')
})
}