Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef Gabrielsson committed Aug 1, 2024
1 parent f4d3671 commit f9777cf
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions nightly/plugins/syntaxhighlighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,35 @@ app.plugin.syntaxhighlighting = {

_colorize: function (text, colors) {
var color = colors.split(','),
rep = '',
style = "display: inline; background: none; color:"

// Tags.
var rep = text.replace(/(<\/?)(\w+)([\s\S]*?)>/g, function (match, p1, tag, attributes) {
var closed = '', equal = ''
var closed = ''
if (p1 === '</') {
attributes = '' // Clear attributes for closing tag
closed = '/'
} else {
// Colorize Attributes if they exist
if (attributes) {
attributes = attributes.replace(/(\w+)(=["'][^"']*["'])?/g, function (attrMatch, attrName, attrValue) {
attrValue = attrValue || '' // Ensure attrValue is not undefined
if (attrValue[0] === '=') {
attrValue = attrValue.slice(1)
equal = '='
var equal = ''
if (attrValue) {
if (attrValue[0] === '=') {
attrValue = attrValue.slice(1)
equal = '='
}
return '<mark style="' + style + color[2] + '">' + attrName + '</mark>' + equal + '<mark style="' + style + color[3] + '">' + attrValue + '</mark>'
} else {
return '<mark style="' + style + color[2] + '">' + attrName + '</mark>'
}
return '<mark style="' + style + color[2] + '">' + attrName + '</mark>' + equal + (attrValue ? '<mark style="' + style + color[3] + '">' + attrValue + '</mark>' : '')
})
}
}

return '<mark style="' + style + color[0] + '">&lt;</mark>' + closed + '<mark style="' + style + color[1] + '">' + tag + '</mark>' + attributes + '<mark style="' + style + color[0] + '">&gt;</mark>'
})


// Comments.
rep = rep.replace(/(&lt;!--[\s\S]*?--&gt;)/g, function (match, comment) {
return '<mark style="' + style + color[4] + '">' + comment + '</mark>'
Expand Down

0 comments on commit f9777cf

Please sign in to comment.