From: Tim Düsterhus Date: Wed, 28 Nov 2018 12:27:04 +0000 (+0100) Subject: Replace highlightSeparateLines by wscSplitIntoLines X-Git-Tag: 5.2.0_Alpha_1~420^2~5^2~15 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=108cb5a51b16e9302a51c2a3f893f6d551a9b60d;p=GitHub%2FWoltLab%2FWCF.git Replace highlightSeparateLines by wscSplitIntoLines This allows to perform the two steps in different idle callbacks. see #2752 --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js index daf77966d5..c8985beff1 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js @@ -69,7 +69,17 @@ define(['WoltLabSuite/Core/Prism', 'prism/prism-meta'], function(Prism, PrismMet return require(['prism/components/prism-' + PrismMeta[this.language].file]) .then(idleify(function () { - var highlighted = Prism.highlightSeparateLines(this.codeContainer.textContent, this.language); + var grammar = Prism.languages[this.language]; + if (!grammar) { + throw new Error('Invalid language ' + language + ' given.'); + } + + var container = elCreate('div'); + container.innerHTML = Prism.highlight(this.codeContainer.textContent, grammar, this.language); + return container; + }.bind(this))) + .then(idleify(function (container) { + var highlighted = Prism.wscSplitIntoLines(container); var highlightedLines = elBySelAll('[data-number]', highlighted); var originalLines = elBySelAll('.codeBoxLine > span', this.codeContainer); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Prism.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Prism.js index 76195f8929..7a5d3290fe 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Prism.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Prism.js @@ -11,10 +11,10 @@ window.Prism = window.Prism || {} window.Prism.manual = true define(['prism/prism'], function () { - Prism.highlightSeparateLines = function (text, language) { - var frag = new DocumentFragment(), - lineNo = 1, - it, node, line, grammar, container; + Prism.wscSplitIntoLines = function (container) { + var frag = new DocumentFragment(); + var lineNo = 1; + var it, node, line; function newLine() { var line = elCreate('span'); @@ -24,18 +24,6 @@ define(['prism/prism'], function () { return line; } - function highlightStringIntoContainer() { - var container = elCreate('div'); - container.innerHTML = Prism.highlight(text, grammar, language); - return container; - } - - grammar = Prism.languages[language]; - if (!grammar) { - throw new Error('Invalid language ' + language + ' given.'); - } - - container = highlightStringIntoContainer(); it = document.createNodeIterator(container, NodeFilter.SHOW_TEXT); line = newLine(lineNo);