From 3a5d6ea6dbc0f1a6d401b60dac1ae191fd6ee2da Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Mon, 11 Nov 2019 21:28:05 -0500 Subject: [PATCH] more generic implementation (though not perfect yet) --- src/highlight.js | 62 +++++++++++++++++++++++++++++++++++--------- src/languages/cpp.js | 12 +++------ 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/highlight.js b/src/highlight.js index bac0a5fbee..0dc394a1ca 100644 --- a/src/highlight.js +++ b/src/highlight.js @@ -108,7 +108,7 @@ https://highlightjs.org/ } } - function inherit(parent) { // inherit(parent, override_obj, override_obj, ...) + var inherit = function(parent) { // inherit(parent, override_obj, override_obj, ...) var key; var result = {}; var objects = Array.prototype.slice.call(arguments, 1); @@ -122,6 +122,15 @@ https://highlightjs.org/ return result; } + // ES2015 version (we would hope it's faster?) + if (Object.assign) { + inherit = function() { + Array.prototype.unshift.call(arguments, {}) + return Object.assign.apply(null, arguments) + } + } + + /* Stream merging */ function nodeStream(node) { @@ -415,18 +424,32 @@ https://highlightjs.org/ var match = matcherRe.exec(s); if (!match) { return null; } - for(var i = 0; i