Fixed 'Syntax highlighter' operation. Using highlight.js instead of google-code-prettify.

This commit is contained in:
n1474335 2018-01-25 18:41:47 +00:00
parent 2b703b2b9b
commit e55cfe0bc1
6 changed files with 18 additions and 26 deletions

10
package-lock.json generated
View file

@ -4341,11 +4341,6 @@
"pinkie-promise": "2.0.1" "pinkie-promise": "2.0.1"
} }
}, },
"google-code-prettify": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/google-code-prettify/-/google-code-prettify-1.0.5.tgz",
"integrity": "sha1-n0d/Ik2/piNy5e+AOn4VdBBAAIQ="
},
"graceful-fs": { "graceful-fs": {
"version": "4.1.11", "version": "4.1.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
@ -4745,6 +4740,11 @@
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=",
"dev": true "dev": true
}, },
"highlight.js": {
"version": "9.12.0",
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.12.0.tgz",
"integrity": "sha1-5tnb5Xy+/mB1HwKvM2GVhwyQwB4="
},
"hmac-drbg": { "hmac-drbg": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz",

View file

@ -80,7 +80,7 @@
"esprima": "^4.0.0", "esprima": "^4.0.0",
"exif-parser": "^0.1.12", "exif-parser": "^0.1.12",
"file-saver": "^1.3.3", "file-saver": "^1.3.3",
"google-code-prettify": "^1.0.5", "highlight.js": "^9.12.0",
"jquery": "^3.2.1", "jquery": "^3.2.1",
"js-crc": "^0.2.0", "js-crc": "^0.2.0",
"js-sha3": "^0.7.0", "js-sha3": "^0.7.0",

View file

@ -3462,15 +3462,10 @@ const OperationConfig = {
outputType: "html", outputType: "html",
args: [ args: [
{ {
name: "Language/File extension", name: "Language",
type: "option", type: "option",
value: Code.LANGUAGES value: Code.LANGUAGES
}, },
{
name: "Display line numbers",
type: "boolean",
value: Code.LINE_NUMS
}
] ]
}, },
"TCP/IP Checksum": { "TCP/IP Checksum": {

View file

@ -11,7 +11,7 @@ import Code from "../../operations/Code.js";
* - xmldom * - xmldom
* - xpath * - xpath
* - jpath * - jpath
* - googlecodeprettify * - highlight.js
* *
* @author n1474335 [n1474335@gmail.com] * @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2017 * @copyright Crown Copyright 2017

View file

@ -1,12 +1,10 @@
import {camelCase, kebabCase, snakeCase} from "lodash"; import {camelCase, kebabCase, snakeCase} from "lodash";
import Utils from "../Utils.js";
import vkbeautify from "vkbeautify"; import vkbeautify from "vkbeautify";
import {DOMParser} from "xmldom"; import {DOMParser} from "xmldom";
import xpath from "xpath"; import xpath from "xpath";
import jpath from "jsonpath"; import jpath from "jsonpath";
import nwmatcher from "nwmatcher"; import nwmatcher from "nwmatcher";
import prettyPrintOne from "imports-loader?window=>global!exports-loader?prettyPrintOne!google-code-prettify/bin/prettify.min.js"; import hljs from "highlight.js";
/** /**
@ -24,12 +22,7 @@ const Code = {
* @constant * @constant
* @default * @default
*/ */
LANGUAGES: ["default-code", "default-markup", "bash", "bsh", "c", "cc", "coffee", "cpp", "cs", "csh", "cv", "cxx", "cyc", "htm", "html", "in.tag", "java", "javascript", "js", "json", "m", "mxml", "perl", "pl", "pm", "py", "python", "rb", "rc", "rs", "ruby", "rust", "sh", "uq.val", "xhtml", "xml", "xsl"], LANGUAGES: ["auto detect"].concat(hljs.listLanguages()),
/**
* @constant
* @default
*/
LINE_NUMS: false,
/** /**
* Syntax highlighter operation. * Syntax highlighter operation.
@ -39,9 +32,13 @@ const Code = {
* @returns {html} * @returns {html}
*/ */
runSyntaxHighlight: function(input, args) { runSyntaxHighlight: function(input, args) {
let language = args[0], const language = args[0];
lineNums = args[1];
return "<code class='prettyprint'>" + prettyPrintOne(Utils.escapeHtml(input), language, lineNums) + "</code>"; if (language === "auto detect") {
return hljs.highlightAuto(input).value;
}
return hljs.highlight(language, input, true).value;
}, },

View file

@ -7,7 +7,7 @@
*/ */
/* Libraries */ /* Libraries */
import "google-code-prettify/src/prettify.css"; import "highlight.js/styles/vs.css";
/* Frameworks */ /* Frameworks */
import "./vendors/bootstrap.less"; import "./vendors/bootstrap.less";