metalsmith-prism 4.2.0 → 4.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +11 -9
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -14,9 +14,9 @@ const isHTMLFile = (filePath) => {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Metalsmith plugin to highlight code syntax with PrismJS
|
|
17
|
-
*
|
|
18
|
-
* @param {Object} options
|
|
19
|
-
* @returns
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} options
|
|
19
|
+
* @returns
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
module.exports = (options) => {
|
|
@@ -38,8 +38,8 @@ module.exports = (options) => {
|
|
|
38
38
|
/**
|
|
39
39
|
* requireLanguage
|
|
40
40
|
* Require optional language package
|
|
41
|
-
*
|
|
42
|
-
* @param {*} language
|
|
41
|
+
*
|
|
42
|
+
* @param {*} language
|
|
43
43
|
*/
|
|
44
44
|
function requireLanguage(language) {
|
|
45
45
|
if (!languages[language]) {
|
|
@@ -56,11 +56,11 @@ module.exports = (options) => {
|
|
|
56
56
|
/**
|
|
57
57
|
* Prism hook "after-tokenize" used to add html for line numbers
|
|
58
58
|
* Neccessary as we don't have a browser
|
|
59
|
-
*
|
|
59
|
+
*
|
|
60
60
|
* Sources:
|
|
61
61
|
* https://github.com/PrismJS/prism/blob/master/plugins/line-numbers/prism-line-numbers.js#L109
|
|
62
62
|
* https://stackoverflow.com/questions/59508413/static-html-generation-with-prismjs-how-to-enable-line-numbers
|
|
63
|
-
*
|
|
63
|
+
*
|
|
64
64
|
*/
|
|
65
65
|
const NEW_LINE_EXP = /\n(?!$)/g;
|
|
66
66
|
let lineNumbersWrapper;
|
|
@@ -84,11 +84,13 @@ module.exports = (options) => {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
const contents = files[file].contents.toString();
|
|
87
|
-
const $ = cheerio.load(contents, { decodeEntities: false },
|
|
87
|
+
const $ = cheerio.load(contents, { decodeEntities: false }, true);
|
|
88
88
|
let highlighted = false;
|
|
89
|
+
const code = $('code');
|
|
89
90
|
|
|
90
|
-
|
|
91
|
+
if (!code.length) return;
|
|
91
92
|
|
|
93
|
+
code.each(function() {
|
|
92
94
|
const $this = $(this);
|
|
93
95
|
const className = $this.attr('class') || '';
|
|
94
96
|
const targets = className.split('language-');
|