Skip to content

Commit 27a54fb

Browse files
authoredMay 21, 2021
Build: Update dependencies
* Update dependencies. * Switch from JSHint to ESLint. Closes #81.
1 parent 8bd0226 commit 27a54fb

12 files changed

+2067
-126
lines changed
 

‎.eslintrc.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"root": true,
3+
4+
"extends": "jquery",
5+
6+
"reportUnusedDisableDirectives": true,
7+
8+
"parserOptions": {
9+
"ecmaVersion": 2018
10+
},
11+
12+
"env": {
13+
"es6": true,
14+
"node": true
15+
},
16+
17+
"rules": {
18+
"strict": ["error", "global"]
19+
}
20+
}

‎.jshintrc

-17
This file was deleted.

‎.npmrc

-1
This file was deleted.

‎Gruntfile.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
module.exports = function( grunt ) {
1+
"use strict";
22

3-
grunt.loadNpmTasks( "grunt-contrib-jshint" );
3+
module.exports = function( grunt ) {
44

5-
grunt.initConfig({
5+
grunt.initConfig( {
66
watch: {
77
files: "<config:lint.files>",
88
tasks: "default"
99
},
10-
jshint: {
10+
eslint: {
1111
options: {
1212
jshintrc: true
1313
},
14-
files: [ "Gruntfile.js", "tasks/**/*.js" ]
14+
files: [ "*.js", "lib/**/*.js", "tasks/**/*.js" ]
1515
}
16-
});
16+
} );
17+
18+
grunt.loadNpmTasks( "grunt-eslint" );
1719

18-
grunt.registerTask( "default", "jshint" );
20+
grunt.registerTask( "default", "eslint" );
1921

2022
};

‎index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
var syntaxHighlight = require( "./lib/highlight" );
1+
"use strict";
2+
3+
const syntaxHighlight = require( "./lib/highlight" );
24

35
exports.syntaxHighlight = syntaxHighlight;
46

57
exports.postPreprocessors = {
6-
_default: function( post, fileName, callback ) {
8+
_default( post, _fileName, callback ) {
79
callback( null, post );
810
}
911
};

‎lib/highlight.js

+29-27
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
var fs = require( "fs" ),
2-
hljs = require( "highlight.js" ),
3-
cheerio = require( "cheerio" ),
4-
he = require( "he" ),
5-
grunt = require( "grunt" ),
6-
lineNumberTemplate = fs.readFileSync( __dirname + "/lineNumberTemplate.jst", "utf-8" );
1+
"use strict";
2+
3+
const fs = require( "fs" );
4+
const hljs = require( "highlight.js" );
5+
const cheerio = require( "cheerio" );
6+
const he = require( "he" );
7+
const grunt = require( "grunt" );
8+
const lineNumberTemplate = fs.readFileSync( __dirname + "/lineNumberTemplate.jst", "utf-8" );
79

810
// When parsing the class attribute, make sure a class matches an actually
911
// highlightable language, instead of being presentational (e.g. 'example')
1012
function getLanguageFromClass( str ) {
11-
var classes = (str || "").split( " " ),
13+
var classes = ( str || "" ).split( " " ),
1214
i = 0,
1315
length = classes.length;
1416

1517
for ( ; i < length; i++ ) {
16-
if ( hljs.LANGUAGES[ classes[ i ].replace( /^lang-/, "" ) ] ) {
17-
return classes[i].replace( /^lang-/, "" );
18+
if ( hljs.getLanguage( classes[ i ].replace( /^lang-/, "" ) ) ) {
19+
return classes[ i ].replace( /^lang-/, "" );
1820
}
1921
}
2022

@@ -27,34 +29,34 @@ function outdent( string ) {
2729
minTabs = Infinity,
2830
rLeadingTabs = /^\t+/;
2931

30-
string.split( "\n" ).forEach(function( line, i, arr ) {
32+
string.split( "\n" ).forEach( function( line, i, arr ) {
3133

3234
// Don't include first or last line if it's nothing but whitespace
33-
if ( (i === 0 || i === arr.length - 1) && !line.trim().length ) {
35+
if ( ( i === 0 || i === arr.length - 1 ) && !line.trim().length ) {
3436
return;
3537
}
3638

3739
// For empty lines inside the snippet, push a space so the line renders properly
3840
if ( !line.trim().length ) {
39-
adjustedLines.push(" ");
41+
adjustedLines.push( " " );
4042
return;
4143
}
4244

4345
// Count how many leading tabs there are and update the global minimum
4446
var match = line.match( rLeadingTabs ),
45-
tabs = match ? match[0].length : 0;
47+
tabs = match ? match[ 0 ].length : 0;
4648
minTabs = Math.min( minTabs, tabs );
4749

4850
adjustedLines.push( line );
49-
});
51+
} );
5052

5153
if ( minTabs !== Infinity ) {
5254

5355
// Outdent the lines as much as possible
5456
rOutdent = new RegExp( "^\t{" + minTabs + "}" );
55-
adjustedLines = adjustedLines.map(function( line ) {
57+
adjustedLines = adjustedLines.map( function( line ) {
5658
return line.replace( rOutdent, "" );
57-
});
59+
} );
5860
}
5961

6062
return adjustedLines.join( "\n" );
@@ -63,25 +65,25 @@ function outdent( string ) {
6365
function syntaxHighlight( html ) {
6466
var $ = cheerio.load( html );
6567

66-
$( "pre > code" ).each(function() {
68+
$( "pre > code" ).each( function() {
6769
var $t = $( this ),
6870
code = he.decode( outdent( $t.html() ) ),
6971
lang = $t.attr( "data-lang" ) ||
7072
getLanguageFromClass( $t.attr( "class" ) ) ||
71-
(code.trim().charAt( 0 ) === "<" ? "xml" : "") ||
73+
( code.trim().charAt( 0 ) === "<" ? "xml" : "" ) ||
7274
"javascript",
7375
linenumAttr = $t.attr( "data-linenum" ),
7476
linenum = parseInt( linenumAttr, 10 ) || 1,
75-
gutter = linenumAttr === "false" ? false : true,
76-
highlighted = hljs.highlight( lang, code ),
77-
fixed = hljs.fixMarkup( highlighted.value, " " );
77+
gutter = linenumAttr !== "false",
78+
highlighted = hljs.highlight( code, { language: lang } ),
79+
fixed = highlighted.value.replace( /\t/g, " " );
7880

7981
// Handle multi-line comments (#32)
8082
fixed = fixed.replace(
81-
/<span class="comment">\/\*([^<]+)\*\/<\/span>/g,
82-
function( full, comment ) {
83-
return "<span class=\"comment\">/*" +
84-
comment.split( "\n" ).join( "</span>\n<span class=\"comment\">" ) +
83+
/<span class="hljs-comment">\/\*([^<]+)\*\/<\/span>/g,
84+
function( _full, comment ) {
85+
return "<span class=\"hljs-comment\">/*" +
86+
comment.split( "\n" ).join( "</span>\n<span class=\"hljs-comment\">" ) +
8587
"*/</span>";
8688
}
8789
);
@@ -93,8 +95,8 @@ function syntaxHighlight( html ) {
9395
gutter: gutter,
9496
lang: lang
9597
}
96-
}));
97-
});
98+
} ) );
99+
} );
98100

99101
return $.html();
100102
}

‎lib/util.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
var fs = require( "fs" ),
2-
async = require( "async" ),
3-
marked = require( "marked" );
1+
"use strict";
2+
3+
const fs = require( "fs" );
4+
const async = require( "async" );
5+
const marked = require( "marked" );
46

57
function htmlEscape( text ) {
68
return text
79

810
// Supports keeping markup in source file, but drop from inline sample
911
.replace(
1012
/<!-- @placeholder-start\((.+)\) -->[\s\S]+@placeholder-end -->/g,
11-
function( match, input ) {
12-
return "<!-- " + input + " -->";
13-
}
13+
( _match, input ) => "<!-- " + input + " -->"
1414
)
1515
.replace( /&/g, "&amp;" )
1616
.replace( /</g, "&lt;" )
@@ -28,7 +28,7 @@ function parseMarkdown( src, options ) {
2828
return marked.parser( tokens );
2929
}
3030

31-
tokens.forEach(function( item ) {
31+
tokens.forEach( function( item ) {
3232
if ( item.type !== "heading" ) {
3333
return;
3434
}
@@ -53,10 +53,10 @@ function parseMarkdown( src, options ) {
5353
"</a> " + parsedText + "</h" + item.depth + ">";
5454

5555
if ( options.generateToc ) {
56-
toc += new Array( (item.depth - 1) * 2 + 1 ).join( " " ) + "* " +
56+
toc += new Array( ( item.depth - 1 ) * 2 + 1 ).join( " " ) + "* " +
5757
"[" + item.tocText + "](#" + item.tocId + ")\n";
5858
}
59-
});
59+
} );
6060

6161
if ( options.generateToc ) {
6262
tokens = marked.lexer( toc ).concat( tokens );
@@ -85,7 +85,7 @@ function eachFile( files, stepFn, complete ) {
8585
}
8686

8787
complete( null, count );
88-
});
88+
} );
8989
}
9090

9191
exports.htmlEscape = htmlEscape;

0 commit comments

Comments
 (0)
Please sign in to comment.