Seize the day

POST : Android Dev Study

syntaxhighlighter에 Kotlin 언어 적용

블로그에 syntaxhighlighter-3.0.83을 적용 중이다. 개발 관련 소스코드를 구문 강조할 때 사용한다. 최근에 새로 작성하는 코드는 대부분 Kotlin 언어로 작성하기 때문에 Kotlin 언어에만 있는 키워드를 구문 강조할 필요가 생겼다. Kotlin은 자바의 키워드도 많이 포함하기에 기존의 JAVA 구문 정의 파일에 Kotlin의 구문 정의를 추가하였다.

;(function()
{
	// CommonJS
	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;

	function Brush()
	{
		var keywords =	'abstract assert boolean break byte case catch char class const ' +
						'continue default do double else enum extends ' +
						'false final finally float for goto if implements import ' +
						'instanceof int interface long native new null ' +
						'package private protected public return ' +
						'short static strictfp super switch synchronized this throw throws true ' +
						'transient try void volatile while ' +
						'Int Long Float Double Short Byte String Any Boolean ' +
						'val var fun object typealias constructor delegate dynamic field file get init param property receiveris set setparam where Unit ' +
						'actual annotation companion crossinline data expect external infix inline inner internal lateinit noinline open operator out override reified sealed suspend tailrec vararg';
						
		var operators = 'shl shr ushr and or xor inv as in is to by';
		
		var functions = 'run let apply with also';

		this.regexList = [
			{ regex: SyntaxHighlighter.regexLib.singleLineCComments,	css: 'comments' },		// one line comments
			{ regex: /\/\*([^\*][\s\S]*)?\*\//gm,						css: 'comments' },	 	// multiline comments
			{ regex: /\/\*(?!\*\/)\*[\s\S]*?\*\//gm,					css: 'preprocessor' },	// documentation comments
			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },		// strings
			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },		// strings
			{ regex: /\b([\d]+(\.[\d]+)?|0x[a-f0-9]+)\b/gi,				css: 'value' },			// numbers
			{ regex: /(?!\@interface\b)\@[\$\w]+\b/g,					css: 'color1' },		// annotation @anno
			{ regex: /\@interface\b/g,									css: 'color2' },		// @interface keyword
			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword' },		// java keyword
			{ regex: new RegExp(this.getKeywords(operators), 'gm'),		css: 'color3' },	    // kotlin operators
			{ regex: new RegExp(this.getKeywords(functions), 'gm'),		css: 'color3' }	        // kotlin functions
			];

		this.forHtmlScript({
			left	: /(<|<)%[@!=]?/g, 
			right	: /%(>|>)/g 
		});
	};

	Brush.prototype	= new SyntaxHighlighter.Highlighter();
	Brush.aliases	= ['java'];

	SyntaxHighlighter.brushes.Java = Brush;

	// CommonJS
	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
})(); 

shBrushJavaKotlin.js


RegExp를 사용하기 때문에 XRegExp.js를 먼저 포함시켜야 합니다. 

XRegExp.js



top

posted at

2018. 6. 3. 15:38


CONTENTS

Seize the day
BLOG main image
김대정의 앱 개발 노트와 사는 이야기
RSS 2.0Tattertools
공지
아카이브
최근 글 최근 댓글
카테고리 태그 구름사이트 링크