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

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

来自LLWiki
跳转到导航 跳转到搜索
第21行: 第21行:
else if (lang == "html") { self.addClass("prettyprint"); }
else if (lang == "html") { self.addClass("prettyprint"); }
});
});
if ($content.find('.hljs').length > 0) { mw.loader.load( '/zh?title=user:bhsd/highlight.js&action=raw&ctype=text/javascript' ); }
if ($content.find('.hljs').length > 0) { mw.loader.load( '/zh?title=mediawiki:gadget-code-prettify-core.js&action=raw&ctype=text/javascript' ); }
if ($content.find('.prettyprint').length > 0) {
if ($content.find('.prettyprint').length > 0) {
mw.loader.getScript('/zh?title=user:bhsd/code-prettify.js&action=raw&ctype=text/javascript').then(function() {
mw.loader.getScript('/zh?title=user:bhsd/code-prettify.js&action=raw&ctype=text/javascript').then(function() {

2020年11月4日 (三) 05:42的版本

/* 引自[[moegirl:mediawiki:gadget-code-prettify.js]] */

mw.hook('wikipage.content').add( function($content) {
    var acceptsLangs = {
        "js": "javascript",
        "javascript": "javascript",
        "json": "json",
        "css": "css",
        "scribunto": "lua",
        "lua": "lua"
    };
    var wgPageContentModel = mw.config.get( "wgPageContentModel" ).toLowerCase();
    if (wgPageContentModel in acceptsLangs) { $content.find('.mw-code').addClass( 'hljs linenums ' + acceptsLangs[wgPageContentModel] ); }
    $content.find('pre[lang], code[lang]').each(function() {
        var self = $(this),
            lang = self.attr("lang").toLowerCase();
        if (lang in acceptsLangs) {
            self.addClass("hljs " + acceptsLangs[lang]);
            if ( self.is('pre') ) { self.addClass("linenums"); }
        }
        else if (lang == "html") { self.addClass("prettyprint"); }
    });
    if ($content.find('.hljs').length > 0) { mw.loader.load( '/zh?title=mediawiki:gadget-code-prettify-core.js&action=raw&ctype=text/javascript' ); }
    if ($content.find('.prettyprint').length > 0) {
    	mw.loader.getScript('/zh?title=user:bhsd/code-prettify.js&action=raw&ctype=text/javascript').then(function() {
    		prettyPrint();
    	});
    }
});