MediaWiki:Gadget-scssHighlight.js

Матеріал з Terraria Wiki
Перейти до навігації Перейти до пошуку

Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.

  • Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
  • Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
  • Internet Explorer / Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5
  • Opera: натисніть Ctrl-F5
// Adds syntax highlighting for SCSS pages (see [[MediaWiki:Common.css/src]])
$(function() {
	// only on pages that have the CSS content model and are named '*.scss'
	if (!(
		mw.config.get('wgPageContentModel') === 'css' &&
		mw.config.get('wgPageName').length > 5 && // page name must be longer than just '.scss'
		mw.config.get('wgPageName').endsWith('.scss')
	)) {
		return;
	}
	// syntax higlighting in the editor (Extension:CodeEditor)
	if (mw.config.get('wgAction') === 'edit') {
		mw.hook('codeEditor.configure').add(function(editSession) {
			editSession.setMode('ace/mode/scss'); // default for CSS is 'ace/mode/css'
			console.log('edit mode changed');
		});
		return;
	}
	
	// Note:  the parser can not handle comment properly. Comment atfer a rule will be treated as text.
	// Example:
	// div{
	//     /* This comment is ok */
	//     margin: 0;
	//     /* This comment will not be considered as a comment */
	//     border: 1px solid red;
	// }

	// var cssTextToReplace = $('.mw-parser-output .mw-highlight.mw-highlight-lang-css');
	// if (mw.config.get('wgAction') !== 'view' || !cssTextToReplace.length) {
	// 	// we must be viewing the page and there must be a CSS-syntax-higlighted div to replace with SCSS syntax highlighting
	// 	return;
	// }
	// // syntax highlighting when viewing the page
	// var pageid = mw.config.get('wgArticleId');
	// var revisionid = mw.config.get('wgRevisionId');
	// new mw.Api().get({ // get the raw content of the page
	//     action: 'query',
	// 	prop: 'revisions',
	// 	revids: revisionid,
	// 	rvslots: '*',
	// 	rvprop: 'content'
	// }).then(function(apiResult) {
	// 	var pagetext = apiResult.query.pages[pageid].revisions[0].slots.main['*'];
	// 	rawtext = pagetext;
	// 	// add the SCSS syntaxhighlighting tag around the raw page content
	// 	pagetext = '<syntaxhighlight lang="scss" line linelinks="L">' + pagetext + '</syntaxhighlight>';
	// 	// parse it (i.e. perform the SCSS syntax highlighting)
	//     new mw.Api().post({
	//         action: 'parse',
	//         prop: 'text',
	//         contentmodel: 'wikitext',
	//         wrapoutputclass: '',
	//         disablelimitreport: true,
	//         text: pagetext
	//     }).then(function(apiResult) {
	//     	var highlightedPagetext = apiResult.parse.text['*'];
	//     	// remove the CSS-highlighted text and add our SCSS-highlighted text in its place
	// 		cssTextToReplace.replaceWith(highlightedPagetext);
	//     });
	// });
});