diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..9aab0e7
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,20 @@
+{
+ "root": true,
+
+ "extends": "jquery",
+
+ "reportUnusedDisableDirectives": true,
+
+ "parserOptions": {
+ "ecmaVersion": 2018
+ },
+
+ "env": {
+ "es6": true,
+ "node": true
+ },
+
+ "rules": {
+ "strict": ["error", "global"]
+ }
+}
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index d34c42d..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "boss": true,
- "curly": true,
- "eqeqeq": true,
- "eqnull": true,
- "expr": true,
- "immed": true,
- "noarg": true,
- "onevar": true,
- "quotmark": "double",
- "smarttabs": true,
- "trailing": true,
- "undef": true,
- "unused": true,
-
- "node": true
-}
diff --git a/.npmrc b/.npmrc
deleted file mode 100644
index cffe8cd..0000000
--- a/.npmrc
+++ /dev/null
@@ -1 +0,0 @@
-save-exact=true
diff --git a/Gruntfile.js b/Gruntfile.js
index 0e77a9a..df57e25 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,20 +1,22 @@
-module.exports = function( grunt ) {
+"use strict";
-grunt.loadNpmTasks( "grunt-contrib-jshint" );
+module.exports = function( grunt ) {
-grunt.initConfig({
+grunt.initConfig( {
watch: {
files: "",
tasks: "default"
},
- jshint: {
+ eslint: {
options: {
jshintrc: true
},
- files: [ "Gruntfile.js", "tasks/**/*.js" ]
+ files: [ "*.js", "lib/**/*.js", "tasks/**/*.js" ]
}
-});
+} );
+
+grunt.loadNpmTasks( "grunt-eslint" );
-grunt.registerTask( "default", "jshint" );
+grunt.registerTask( "default", "eslint" );
};
diff --git a/index.js b/index.js
index d959c0f..08bea70 100644
--- a/index.js
+++ b/index.js
@@ -1,9 +1,11 @@
-var syntaxHighlight = require( "./lib/highlight" );
+"use strict";
+
+const syntaxHighlight = require( "./lib/highlight" );
exports.syntaxHighlight = syntaxHighlight;
exports.postPreprocessors = {
- _default: function( post, fileName, callback ) {
+ _default( post, _fileName, callback ) {
callback( null, post );
}
};
diff --git a/lib/highlight.js b/lib/highlight.js
index 375f1dc..aa62c5e 100644
--- a/lib/highlight.js
+++ b/lib/highlight.js
@@ -1,20 +1,22 @@
-var fs = require( "fs" ),
- hljs = require( "highlight.js" ),
- cheerio = require( "cheerio" ),
- he = require( "he" ),
- grunt = require( "grunt" ),
- lineNumberTemplate = fs.readFileSync( __dirname + "/lineNumberTemplate.jst", "utf-8" );
+"use strict";
+
+const fs = require( "fs" );
+const hljs = require( "highlight.js" );
+const cheerio = require( "cheerio" );
+const he = require( "he" );
+const grunt = require( "grunt" );
+const lineNumberTemplate = fs.readFileSync( __dirname + "/lineNumberTemplate.jst", "utf-8" );
// When parsing the class attribute, make sure a class matches an actually
// highlightable language, instead of being presentational (e.g. 'example')
function getLanguageFromClass( str ) {
- var classes = (str || "").split( " " ),
+ var classes = ( str || "" ).split( " " ),
i = 0,
length = classes.length;
for ( ; i < length; i++ ) {
- if ( hljs.LANGUAGES[ classes[ i ].replace( /^lang-/, "" ) ] ) {
- return classes[i].replace( /^lang-/, "" );
+ if ( hljs.getLanguage( classes[ i ].replace( /^lang-/, "" ) ) ) {
+ return classes[ i ].replace( /^lang-/, "" );
}
}
@@ -27,34 +29,34 @@ function outdent( string ) {
minTabs = Infinity,
rLeadingTabs = /^\t+/;
- string.split( "\n" ).forEach(function( line, i, arr ) {
+ string.split( "\n" ).forEach( function( line, i, arr ) {
// Don't include first or last line if it's nothing but whitespace
- if ( (i === 0 || i === arr.length - 1) && !line.trim().length ) {
+ if ( ( i === 0 || i === arr.length - 1 ) && !line.trim().length ) {
return;
}
// For empty lines inside the snippet, push a space so the line renders properly
if ( !line.trim().length ) {
- adjustedLines.push(" ");
+ adjustedLines.push( " " );
return;
}
// Count how many leading tabs there are and update the global minimum
var match = line.match( rLeadingTabs ),
- tabs = match ? match[0].length : 0;
+ tabs = match ? match[ 0 ].length : 0;
minTabs = Math.min( minTabs, tabs );
adjustedLines.push( line );
- });
+ } );
if ( minTabs !== Infinity ) {
// Outdent the lines as much as possible
rOutdent = new RegExp( "^\t{" + minTabs + "}" );
- adjustedLines = adjustedLines.map(function( line ) {
+ adjustedLines = adjustedLines.map( function( line ) {
return line.replace( rOutdent, "" );
- });
+ } );
}
return adjustedLines.join( "\n" );
@@ -63,25 +65,25 @@ function outdent( string ) {
function syntaxHighlight( html ) {
var $ = cheerio.load( html );
- $( "pre > code" ).each(function() {
+ $( "pre > code" ).each( function() {
var $t = $( this ),
code = he.decode( outdent( $t.html() ) ),
lang = $t.attr( "data-lang" ) ||
getLanguageFromClass( $t.attr( "class" ) ) ||
- (code.trim().charAt( 0 ) === "<" ? "xml" : "") ||
+ ( code.trim().charAt( 0 ) === "<" ? "xml" : "" ) ||
"javascript",
linenumAttr = $t.attr( "data-linenum" ),
linenum = parseInt( linenumAttr, 10 ) || 1,
- gutter = linenumAttr === "false" ? false : true,
- highlighted = hljs.highlight( lang, code ),
- fixed = hljs.fixMarkup( highlighted.value, " " );
+ gutter = linenumAttr !== "false",
+ highlighted = hljs.highlight( code, { language: lang } ),
+ fixed = highlighted.value.replace( /\t/g, " " );
// Handle multi-line comments (#32)
fixed = fixed.replace(
- /