LLWiki正在建设中,欢迎加入我们

“MediaWiki:Gadget-code-prettify.js”的版本间差异

跳转到导航 跳转到搜索
无编辑摘要
const $color = $('<span>', {class: 'hljs-color'});
$cssblock.find( '.hljs-number:contains(#)' ).before(function() { // 16进制颜色
returnconst $color.clone().css('color', = this.textContent);,
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 = $siblingsthis.slice(textContent.length index== ).toArray().findIndex(function(ele)4 ? 9 : 7, // {rgba/hsla或rgb/hsl
return// ele.nodeType == 3 && ele.textContent.startsWith( ')' );右半括号那一项可能有分号
color = $siblings.slice(index, index + n).map(function() { return this.textContent; }).toArray().join('') + ')');
});
return $color.clone().css('{color',: $siblingscolor.slicejoin(index, index'') + n')', //opacity: 右半括号那一项可能有分号color[9]});
.map(function() { return this.textContent; }).toArray().join('') + ')');
});
}, function(reason) { mw.apiFailure(reason, 'highlight.js'); });
16,874

个编辑

导航菜单