Skip to content

Commit

Permalink
Fix bug on Java generics in code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
javamind committed Oct 10, 2018
1 parent 5ac5957 commit e9817be
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion extension/highlight-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ module.exports = function ({ selector }) {

};

const updateJava = (html, language) => {
if(language === 'java' || language === 'Java'){
return html.replace(/<span class=\"token operator\">&amp;<\/span>lt<span class=\"token punctuation\">;<\/span>/g, '&lt;')
.replace(/<span class=\"token operator\">&amp;<\/span>gt<span class=\"token punctuation\">;<\/span>/g, '&gt;')
}
return html;
};

return map((file, next) => {
const $ = cheerio.load(file.contents.toString(), { decodeEntities: false });

Expand All @@ -32,7 +40,9 @@ module.exports = function ({ selector }) {
const language = elem.prop('data-lang');
const fileContents = elem.html();
const highlightedContents = Prism.highlight(fileContents, Prism.languages[language] || Prism.languages.autoit);
elem.parent().replaceWith( `<pre class="language-${language}">${updateComment(highlightedContents)}</pre>`);
const htmlWithComments = updateComment(highlightedContents, language);
const finalHtml = updateJava(htmlWithComments, language);
elem.parent().replaceWith( `<pre class="language-${language}">${finalHtml}</pre>`);
elem.addClass('highlights');
});

Expand Down

0 comments on commit e9817be

Please sign in to comment.