Skip to content

Commit

Permalink
Use semantic HTML elements for highlights, insertions, and deletions
Browse files Browse the repository at this point in the history
Ref. 11ty#6.
  • Loading branch information
mathiasbynens committed Sep 24, 2018
1 parent 0502cf5 commit 091503f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/markdownSyntaxHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ module.exports = function(str, language) {

let lines = html.split("\n").slice(0, -1); // The last line is empty.
let highlightedLines = lines.map(function(line, j) {
return "<span class=\"highlight-line" +
(highlights.isHighlighted(j) ? " highlight-line-active" : "") +
(highlights.isHighlightedAdd(j) ? " highlight-line-add" : "") +
(highlights.isHighlightedRemove(j) ? " highlight-line-remove" : "") +
"\">" +
line +
"</span>";
if (highlights.isHighlighted(j)) {
return "<mark class=\"highlight-line highlight-line-active\">" + line + "</mark>";
}
if (highlights.isHighlightedAdd(j)) {
return "<ins class=\"highlight-line highlight-line-add\">" + line + "</ins>";
}
if (highlights.isHighlightedRemove(j)) {
return "<del class=\"highlight-line highlight-line-remove\">" + line + "</del>";
}
return "<span class=\"highlight-line\">" + line + "</span>";
});

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

0 comments on commit 091503f

Please sign in to comment.