LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-code-prettify.js”的版本间差异
跳转到导航
跳转到搜索
小 |
小 标签:移动版网页编辑 移动版编辑 |
||
第1行: | 第1行: | ||
//<nowiki> |
|||
// 由ResourceLoader直接调用,不可使用ES6语法 |
// 由ResourceLoader直接调用,不可使用ES6语法 |
||
/* 引自[[moegirl:mediawiki:gadget-code-prettify.js]] */ |
/* 引自[[moegirl:mediawiki:gadget-code-prettify.js]] */ |
||
"use strict"; |
"use strict"; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
}, |
|||
⚫ | |||
⚫ | |||
mw.hook( 'wikipage.content' ).add(function($content) { |
mw.hook( 'wikipage.content' ).add(function($content) { |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
}, |
|||
⚫ | |||
⚫ | |||
if (contentModel in acceptLangs) { |
if (contentModel in acceptLangs) { |
||
$content.find( '.mw-code' ).addClass( 'hljs linenums ' + acceptLangs[contentModel] ); |
$content.find( '.mw-code' ).addClass( 'hljs linenums ' + acceptLangs[contentModel] ); |
||
第23行: | 第24行: | ||
return "hljs " + acceptLangs[lang] + (self.is('pre') ? " linenums" : ""); |
return "hljs " + acceptLangs[lang] + (self.is('pre') ? " linenums" : ""); |
||
} |
} |
||
else { return ""; } |
|||
}); |
}); |
||
if ($content.find( '.hljs' ).length) { |
if ($content.find( '.hljs:not(.highlighted)' ).length) { |
||
mw.loader.load( script + '?title=mediawiki:gadget-code-prettify-core.js&action=raw&ctype=text/javascript' ); |
mw.loader.load( script + '?title=mediawiki:gadget-code-prettify-core.js&action=raw&ctype=text/javascript' ); |
||
} |
} |
||
}); |
}); |
||
//</nowiki> |
|||
// [[category:小工具加载器]] [[category:作为模块的小工具]] [[category:阅读工具]] [[category:默认开启的小工具]] [[category:桌面版小工具]] [[category:手机版小工具]] |
// [[category:小工具加载器]] [[category:作为模块的小工具]] [[category:阅读工具]] [[category:默认开启的小工具]] [[category:桌面版小工具]] [[category:手机版小工具]] |
||
// {{DEFAULTSORT:code-prettify.js}} |
// {{DEFAULTSORT:code-prettify.js}} |
2020年11月22日 (日) 13:56的版本
//<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" : ""); } }); if ($content.find( '.hljs:not(.highlighted)' ).length) { mw.loader.load( script + '?title=mediawiki:gadget-code-prettify-core.js&action=raw&ctype=text/javascript' ); } }); //</nowiki> // [[category:小工具加载器]] [[category:作为模块的小工具]] [[category:阅读工具]] [[category:默认开启的小工具]] [[category:桌面版小工具]] [[category:手机版小工具]] // {{DEFAULTSORT:code-prettify.js}}