From b4d2df93d30dcf6f071a80b3a17ec555d59b69c7 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 23 Jul 2016 15:37:07 -0700 Subject: [PATCH] Initial import of 4.x module. --- .gitignore | 2 ++ .travis.yml | 5 ++++ README.md | 11 +++++++++ brush.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ mocha.opts | 4 +++ package.json | 46 ++++++++++++++++++++++++++++++++++ sample.txt | 20 +++++++++++++++ test.js | 35 ++++++++++++++++++++++++++ 8 files changed, 193 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 brush.js create mode 100644 mocha.opts create mode 100644 package.json create mode 100644 sample.txt create mode 100644 test.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a088b6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +bower_components diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..16a4582 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +sudo: false +node_js: + - "4" + - "5" diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea9a1eb --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# brush-kotlin + +Kotlin brush module for [SyntaxHighlighter](https://github.com/syntaxhighlighter/syntaxhighlighter). + +## Usage + +Please see [Building Instructions](https://github.com/syntaxhighlighter/syntaxhighlighter/wiki/Building) on the [SyntaxHighlighter Wiki](https://github.com/syntaxhighlighter/syntaxhighlighter/wiki) for details. + +## License + +MIT diff --git a/brush.js b/brush.js new file mode 100644 index 0000000..4955fd8 --- /dev/null +++ b/brush.js @@ -0,0 +1,70 @@ +var BrushBase = require('brush-base'); +var regexLib = require('syntaxhighlighter-regex').commonRegExp; + +function Brush() { + var keywords = 'abstract annotation as break by catch class companion const constructor continue' + + ' crossinline data do dynamic else enum external false final finally for fun get if' + + ' import in infix init inline inner interface internal is lateinit noinline null object' + + ' open operator out override package private protected public reified return sealed' + + ' set super tailrec this throw trait true try type val var vararg when where while' + + ' String Array Unit Int'; + + this.regexList = [ + { + // line comment + regex: regexLib.singleLineCComments, + css: 'comments' + }, + { + // block comment + regex: /\/\*([^\*][\s\S]*?)?\*\//gm, + css: 'comments' + }, + { + // javadoc + regex: /\/\*(?!\*\/)\*[\s\S]*?\*\//gm, + css: 'preprocessor' + }, + { + regex: regexLib.doubleQuotedString, + css: 'string' + }, + { + regex: regexLib.singleQuotedString, + css: 'string' + }, + { + // numbers + regex: /\b([\d]+(\.[\d]+)?f?|[\d]+l?|0x[a-f0-9]+)\b/gi, + css: 'value' + }, + { + // annotations + regex: /\@(Target|Retention|Repeatable|MustBeDocumented|Test|Deprecated)/g, + css: 'color2' + }, + { + // User-site targets + regex: /\@(file|property|field|get|set|receiver|param|setparam|delegate):/g, + css: 'color2' + }, + { + // @Inject annotation + regex: /\@(Inject)\b/g, + css: 'color3' + }, + { + regex: new RegExp(this.getKeywords(keywords), 'gm'), + css: 'keyword' + } + ]; + + this.forHtmlScript({ + left: /(<|<)%[@!=]?/g, + right: /%(>|>)/g + }); +}; + +Brush.prototype = new BrushBase(); +Brush.aliases = ['kotlin']; +module.exports = Brush; \ No newline at end of file diff --git a/mocha.opts b/mocha.opts new file mode 100644 index 0000000..c153cee --- /dev/null +++ b/mocha.opts @@ -0,0 +1,4 @@ +--recursive +--reporter spec +--ui bdd +--timeout 3000 diff --git a/package.json b/package.json new file mode 100644 index 0000000..5b054ef --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "brush-kotlin", + "version": "0.2.0", + "description": "Kotlin brush module for SyntaxHighlighter.", + "keywords": [ + "syntaxhighlighter", + "brush", + "kotlin" + ], + "homepage": "https://github.com/ethauvin/brush-kotlin", + "bugs": "https://github.com/syntaxhighlighter/brush-kotlin/issues", + "author": { + "name": "Erik C. Thauvin", + "url": "https://github.com/ethauvin" + }, + "main": "brush.js", + "repository": { + "type": "git", + "url": "https://github.com/syntaxhighlighter/brush-kotlin.git" + }, + "scripts": { + "test": "babel-node --only='syntaxhighlighter-*,brush-*' node_modules/.bin/_mocha --opts mocha.opts test.js" + }, + "dependencies": { + "brush-base": "^4.0.0", + "syntaxhighlighter-regex": "^4.0.0" + }, + "devDependencies": { + "babel-cli": "^6.4.5", + "babel-core": "^6.1.21", + "babel-preset-es2015": "^6.1.18", + "chai": "^3.4.1", + "mocha": "^2.3.4", + "syntaxhighlighter-match": "^4.0.0" + }, + "engines": { + "node": ">=4", + "npm": ">=2" + }, + "license": "MIT", + "babel": { + "presets": [ + "es2015" + ] + } +} diff --git a/sample.txt b/sample.txt new file mode 100644 index 0000000..b890dcb --- /dev/null +++ b/sample.txt @@ -0,0 +1,20 @@ +package demo + +/** + * This class supports greeting people by name. + * + * @property name The name of the person to be greeted. + */ +class Greeter(val name: String) { + + /** + * Prints the greeting to the standard output. + */ + fun greet() { + println("Hello $name!") + } +} + +fun main(args: Array) { + Greeter(args[0]).greet() +} \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 0000000..58e3d3b --- /dev/null +++ b/test.js @@ -0,0 +1,35 @@ +var chai = require('chai'); +var expect = chai.expect; +var match = require('syntaxhighlighter-match'); +var Brush = require('./brush'); +var sample = require('fs').readFileSync(`${__dirname}/sample.txt`, 'utf8'); + +describe('brush-java', function() { + var instance = null; + + before(function() { + instance = new Brush(); + }); + + it('has populated code sample', function() { + expect(sample).to.not.match(/^Populate/); + }); + + describe('instance', function() { + it('has `regexList`', function() { + expect(instance).to.have.property('regexList'); + }); + }); + + describe('parsing', function() { + var matches = null; + + before(function() { + matches = match.applyRegexList(sample, instance.regexList); + }); + + it('can parse', function() { + expect(matches).to.have.length.above(0); + }); + }); +}); \ No newline at end of file