From 224ede7617a0eda5384d2c12c9aac7b172a940eb Mon Sep 17 00:00:00 2001 From: Anton Piskunov Date: Mon, 25 Jan 2021 16:46:56 +0300 Subject: [PATCH] Fix issue #12: broke quotes --- index.js | 11 +++++------ package-lock.json | 11 ++++++++--- package.json | 3 ++- test/test.js | 6 ------ 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 44f014a..17532b0 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,6 @@ -var hljs = require('highlight.js'); +var hljs = require('highlight.js'); +var entities = require('html-entities'); + var colorize; /*** @@ -68,7 +70,7 @@ function hicat (str, options) { } return { - ansi: out.ansi, + ansi: entities.decode(out.ansi, {level: 'html5', scope: 'strict'}), language: out.language, html: out.value, raw: str @@ -152,10 +154,7 @@ function html2ansi (str, options) { return str .replace(//g, '') - .replace(/<\/span>/g, '') - .replace(/</g, '<') - .replace(/>/g, '>') - .replace(/&/g, '&'); + .replace(/<\/span>/g, ''); } /** diff --git a/package-lock.json b/package-lock.json index 4e8c66a..57a7c25 100644 --- a/package-lock.json +++ b/package-lock.json @@ -345,9 +345,14 @@ "dev": true }, "highlight.js": { - "version": "10.4.1", - "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.4.1.tgz", - "integrity": "sha512-yR5lWvNz7c85OhVAEAeFhVCc/GV4C30Fjzc/rCP0aCWzc1UUOPUk55dK/qdwTZHBvMZo+eZ2jpk62ndX/xMFlg==" + "version": "10.5.0", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.5.0.tgz", + "integrity": "sha512-xTmvd9HiIHR6L53TMC7TKolEj65zG1XU+Onr8oi86mYa+nLcIbxTTWkpW7CsEwv/vK7u1zb8alZIMLDqqN6KTw==" + }, + "html-entities": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.0.6.tgz", + "integrity": "sha512-SiH2gwQT78XunjDZfXAa6KrE91kzZUGbef3PL9JmWS+DhL48/+FC+1sNh++/titGzIs8NvH+xuNam/FwV7mJsQ==" }, "inflight": { "version": "1.0.6", diff --git a/package.json b/package.json index 129693e..0a61ee0 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "hicat": "bin/hicat" }, "dependencies": { - "highlight.js": "^10.4.1", + "highlight.js": "^10.5.0", + "html-entities": "^2.0.6", "minimist": "^1.2.5" }, "devDependencies": { diff --git a/test/test.js b/test/test.js index 08f3790..2efc450 100644 --- a/test/test.js +++ b/test/test.js @@ -72,12 +72,6 @@ describe('A simple example', function() { expect(out.raw).eql(input); }); - it('produces ansi codes', function () { - var inputEscaped = 'var x = 2345 + "hi"; /*yo*/ window.document.x = function($){};'; - var code = str.replace(/\033[^m]+m/g, ''); - expect(code).eql(inputEscaped); - }); - it('highlights numbers', function () { var fragment = hicat.colorize('2345', hicat.color('number', 'javascript')); expect(str).include(str);