Fixed #902: a bug of code block caused by span tags that cross multiple lines.#904
Closed
xing5 wants to merge 5 commits intohexojs:masterfrom
Closed
Fixed #902: a bug of code block caused by span tags that cross multiple lines.#904xing5 wants to merge 5 commits intohexojs:masterfrom
xing5 wants to merge 5 commits intohexojs:masterfrom
Conversation
This patch makes sure all tags are enclosed in every line with the correct syntax class.
Author
|
After reading #795, I did some other changes, I can add these to this pull request if you guys agree. @@ -88,8 +101,12 @@ module.exports = function(str, options){
firstLine = options.first_line;
lines.forEach(function(item, i){
- numbers += '<div class="line">' + (i + firstLine) + '</div>';
- content += '<div class="line">' + item + '</div>';
+ if (i !== 0) {
+ numbers += '\n';
+ content += '\n';
+ }
+ numbers += '<span class="line">' + (i + firstLine) + '</span>';
+ content += '<span class="line">' + item + '</span>';
});
var result = '<figure class="highlight' + (options.lang ? ' ' + options.lang : '') + '">' + |
Closed
|
Hey guys. Is this issue really fixed? i still got a problem with multi line comments. <pre>
<div class="line">
<span class="comment">/**
</div>
<div class="line">
* Test
</div>
<div class="line">
*/</span>
</div>
</pre> |
Member
|
Yes! The issue #902 and this pull request #904 are not fixed on current version of Hexo. $ hexo version
hexo: 3.2.2
hexo-cli: 1.0.2
os: Linux 4.4.0-64-generic linux x64
http_parser: 2.7.0
node: 7.6.0
v8: 5.5.372.40
uv: 1.11.0
zlib: 1.2.11
ares: 1.10.1-DEV
modules: 51
openssl: 1.0.2k
icu: 58.2
unicode: 9.0
cldr: 30.0.3
tz: 2016j
$ grep 'version' node_modules/hexo-util/package.json
"version": "0.6.0",
$To fix this issue, modify diff --git a/lib/highlight.js b/lib/highlight.js
index dcdd734..ff0ef2a 100644
--- a/lib/highlight.js
+++ b/lib/highlight.js
@@ -122,7 +122,17 @@ function highlight(str, options) {
function tryHighlight(str, lang) {
try {
- return hljs.highlight(lang, str);
+ var matching = str.match(/(\r?\n)/);
+ var separator = matching ? matching[1] : '';
+ var lines = matching ? str.split(separator) : [str];
+ var result = hljs.highlight(lang, lines.shift());
+ var html = result.value + separator;
+ while (lines.length > 0) {
+ result = hljs.highlight(lang, lines.shift(), false, result.top);
+ html += result.value + separator;
+ }
+ result.value = html;
+ return result;
} catch (err) {
return;
}I will add some tests for this issue, and make a new pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch makes sure all tags are enclosed in every line with the
correct syntax class.
Input:
Original output:
With this patch: