16,874
个编辑
LLWiki正在建设中,欢迎加入我们!
小 |
小 |
||
const $color = $('<span>', {class: 'hljs-color'});
$cssblock.find( '.hljs-number:contains(#)' ).before(function() { // 16进制颜色
n = color.length,
alpha = n == 5 ? color[4].repeat(2) : color.slice(7);
return $color.clone().css({color: color, opacity: alpha ? parseInt('0x' + alpha) / 255 : undefined});
});
$cssblock.find( '.hljs-built_in:contains(rgb), .hljs-built_in:contains(hsl)' ).before(function() { // RGB颜色
const $siblings = $(this).parent().contents(), // 标点符号都是text节点,所以需要使用contents
index = $siblings.index( this ),
n =
color = $siblings.slice(index, index + n).map(function() { return this.textContent; }).toArray(
return $color.clone().css(
▲ .map(function() { return this.textContent; }).toArray().join('') + ')');
});
}, function(reason) { mw.apiFailure(reason, 'highlight.js'); });
|