Skip to content

Commit

Permalink
Merge pull request #7 from mathiasbynens/change-html
Browse files Browse the repository at this point in the history
Use semantic HTML elements for highlights, insertions, and deletions
  • Loading branch information
zachleat authored Sep 25, 2018
2 parents 0502cf5 + 091503f commit 01e9c6a
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 01e9c6a

Please sign in to comment.