Skip to content

Commit

Permalink
Merge pull request 11ty#5 from mathiasbynens/patch-1
Browse files Browse the repository at this point in the history
Support multiple consecutive line breaks in code snippets
  • Loading branch information
zachleat authored Sep 24, 2018
2 parents db6b1cc + a8de161 commit 0502cf5
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/markdownSyntaxHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,16 @@ module.exports = function(str, language) {

let highlights = new HighlightLinesGroup(split.join("/"), "/");

let lines = html.split("\n");
let lines = html.split("\n").slice(0, -1); // The last line is empty.
let highlightedLines = lines.map(function(line, j) {
if( j + 1 === lines.length ) {
return "";
}

return "<div class=\"highlight-line" +
return "<span class=\"highlight-line" +
(highlights.isHighlighted(j) ? " highlight-line-active" : "") +
(highlights.isHighlightedAdd(j) ? " highlight-line-add" : "") +
(highlights.isHighlightedRemove(j) ? " highlight-line-remove" : "") +
"\">" +
line +
"</div>";
"</span>";
});

return `<pre class="language-${language}"><code class="language-${language}">${highlightedLines.join("")}</code></pre>`;
return `<pre class="language-${language}"><code class="language-${language}">${highlightedLines.join("<br>")}</code></pre>`;
};

0 comments on commit 0502cf5

Please sign in to comment.