Skip to content

Commit

Permalink
bump: Update highlight.js
Browse files Browse the repository at this point in the history
  • Loading branch information
rtfpessoa committed May 9, 2020
1 parent c37321b commit ae91dce
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 80 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -89,7 +89,7 @@
"hogan.js": "3.0.2"
},
"optionalDependencies": {
"highlight.js": "9.18.1"
"highlight.js": "10.0.2"
},
"devDependencies": {
"@types/clipboard": "2.0.1",
Expand Down
4 changes: 1 addition & 3 deletions src/render-utils.ts
Expand Up @@ -186,9 +186,7 @@ export function filenameDiff(file: DiffFileName): string {
* Generates a unique string numerical identifier based on the names of the file diff
*/
export function getHtmlId(file: DiffFileName): string {
return `d2h-${hashCode(filenameDiff(file))
.toString()
.slice(-6)}`;
return `d2h-${hashCode(filenameDiff(file)).toString().slice(-6)}`;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ui/js/diff2html-ui-base.ts
@@ -1,4 +1,4 @@
import * as HighlightJS from 'highlight.js/lib/highlight.js';
import * as HighlightJS from 'highlight.js/lib/core';
import { ICompiledMode, IHighlightResult, IAutoHighlightResult } from 'highlight.js';
import { nodeStream, mergeStreams } from './highlight.js-helpers';

Expand Down
14 changes: 6 additions & 8 deletions src/ui/js/highlight.js-helpers.ts
Expand Up @@ -5,11 +5,8 @@

/* Utility functions */

function escape(value: string): string {
return value
.replace(/&/gm, '&')
.replace(/</gm, '&lt;')
.replace(/>/gm, '&gt;');
function escapeHTML(value: string): string {
return value.replace(/&/gm, '&amp;').replace(/</gm, '&lt;').replace(/>/gm, '&gt;');
}

function tag(node: Node): string {
Expand Down Expand Up @@ -97,7 +94,7 @@ export function mergeStreams(original: NodeEvent[], highlighted: NodeEvent[], va
}

result += `<${tag(node)} ${Array<Attr>()
.map.call(node.attributes, attr => `${attr.nodeName}="${escape(attr.value)}"`)
.map.call(node.attributes, attr => `${attr.nodeName}="${escapeHTML(attr.value).replace(/"/g, '&quot;')}"`)
.join(' ')}>`;
}

Expand All @@ -111,7 +108,7 @@ export function mergeStreams(original: NodeEvent[], highlighted: NodeEvent[], va

while (original.length || highlighted.length) {
let stream = selectStream();
result += escape(value.substring(processed, stream[0].offset));
result += escapeHTML(value.substring(processed, stream[0].offset));
processed = stream[0].offset;
if (stream === original) {
/*
Expand All @@ -135,5 +132,6 @@ export function mergeStreams(original: NodeEvent[], highlighted: NodeEvent[], va
render(stream.splice(0, 1)[0]);
}
}
return result + escape(value.substr(processed));

return result + escapeHTML(value.substr(processed));
}
130 changes: 69 additions & 61 deletions src/ui/js/highlight.js-slim.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion typings/highlight.js/highlight.js.d.ts
@@ -1,4 +1,4 @@
declare module 'highlight.js/lib/highlight.js' {
declare module 'highlight.js/lib/core' {
import hljs from 'highlight.js';

export = hljs;
Expand Down
2 changes: 1 addition & 1 deletion typings/highlight.js/languages.d.ts
@@ -1,5 +1,5 @@
declare module 'highlight.js/lib/languages/*' {
import { HLJSStatic, IModeBase } from 'highlight.js';

export default function(hljs?: HLJSStatic): IModeBase;
export default function (hljs?: HLJSStatic): IModeBase;
}
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -4573,10 +4573,10 @@ hex-color-regex@^1.1.0:
resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e"
integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==

highlight.js@9.18.1:
version "9.18.1"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.18.1.tgz#ed21aa001fe6252bb10a3d76d47573c6539fe13c"
integrity sha512-OrVKYz70LHsnCgmbXctv/bfuvntIKDz177h0Co37DQ5jamGZLVmoCVMtjMtNZY3X9DrCcKfklHPNeA0uPZhSJg==
highlight.js@10.0.2:
version "10.0.2"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.0.2.tgz#d2c732544f8f68bceaf0cefb4b0575bce8eddbee"
integrity sha512-2gMT2MHU6/2OjAlnaOE2LFdr9dwviDN3Q2lSw7Ois3/5uTtahbgYTkr4EPoY828ps+2eQWiixPTF8+phU6Ofkg==

hmac-drbg@^1.0.0:
version "1.0.1"
Expand Down

0 comments on commit ae91dce

Please sign in to comment.