LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-code-prettify.js”的版本间差异
跳转到导航
跳转到搜索
小 标签:移动版网页编辑 移动版编辑 |
|||
第14行: | 第14行: | ||
contentModel = mw.config.get( "wgPageContentModel" ).toLowerCase(), |
contentModel = mw.config.get( "wgPageContentModel" ).toLowerCase(), |
||
script = mw.config.get( "wgScript" ); |
script = mw.config.get( "wgScript" ); |
||
mw.hook( 'wikipage.content' ).add(function($content) { |
mw.hook( 'wikipage.content' ).add(function($content) { |
||
if (contentModel in acceptLangs) { |
if (contentModel in acceptLangs) { |
||
第25行: | 第26行: | ||
} |
} |
||
}); |
}); |
||
const $block = $content.find( '.hljs:not(.highlighted)' ); |
|||
if ($block.length) { |
|||
mw.loader.load( script + '?title=mediawiki:gadget-code-prettify-core.js&action=raw&ctype=text/javascript' ); |
|||
mw.loader.getScript( 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.3.1/build/highlight.min.js' ) |
|||
.then(() => { |
|||
$block.each(function() { hljs.highlightBlock(this); }).addClass( 'highlighted' ) |
|||
.filter(function() { return $(this).hasClass( 'linenums' ); }) |
|||
.html(function() { |
|||
let lines = $(this).html().replace(/\n$/, '').split('\n'); |
|||
if (mw.config.get( 'wgNamespaceNumber' ) == 274) { lines = lines.slice(1, -1); } |
|||
return '<ol>' + lines.map((ele, i) => `<li class="L${i % 2}">${ele}</li>`).join('') + '</ol>'; |
|||
}); |
|||
mw.hook( 'code.prettify' ).fire($block); |
|||
}); |
|||
} |
} |
||
}); |
}); |
||
//</nowiki> |
//</nowiki> |
||
// |
// [[category:作为模块的小工具]] [[category:阅读工具]] [[category:默认开启的小工具]] [[category:桌面版小工具]] [[category:手机版小工具]] |
||
// {{DEFAULTSORT:code-prettify.js}} |
// {{DEFAULTSORT:code-prettify.js}} |
2020年11月23日 (一) 04:04的版本
//<nowiki> // 由ResourceLoader直接调用,不可使用ES6语法 /* 引自[[moegirl:mediawiki:gadget-code-prettify.js]] */ "use strict"; const acceptLangs = { js: "javascript", javascript: "javascript", json: "json", css: "css", scribunto: "lua", lua: "lua", html: "html" }, contentModel = mw.config.get( "wgPageContentModel" ).toLowerCase(), script = mw.config.get( "wgScript" ); mw.hook( 'wikipage.content' ).add(function($content) { if (contentModel in acceptLangs) { $content.find( '.mw-code' ).addClass( 'hljs linenums ' + acceptLangs[contentModel] ); } $content.find('pre[lang], code[lang]').addClass(function() { const self = $(this), lang = self.attr( "lang" ).toLowerCase(); if (lang in acceptLangs) { return "hljs " + acceptLangs[lang] + (self.is('pre') ? " linenums" : ""); } }); const $block = $content.find( '.hljs:not(.highlighted)' ); if ($block.length) { mw.loader.getScript( 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.3.1/build/highlight.min.js' ) .then(() => { $block.each(function() { hljs.highlightBlock(this); }).addClass( 'highlighted' ) .filter(function() { return $(this).hasClass( 'linenums' ); }) .html(function() { let lines = $(this).html().replace(/\n$/, '').split('\n'); if (mw.config.get( 'wgNamespaceNumber' ) == 274) { lines = lines.slice(1, -1); } return '<ol>' + lines.map((ele, i) => `<li class="L${i % 2}">${ele}</li>`).join('') + '</ol>'; }); mw.hook( 'code.prettify' ).fire($block); }); } }); //</nowiki> // [[category:作为模块的小工具]] [[category:阅读工具]] [[category:默认开启的小工具]] [[category:桌面版小工具]] [[category:手机版小工具]] // {{DEFAULTSORT:code-prettify.js}}