Skip to content

Commit

Permalink
Add a quote translator for code
Browse files Browse the repository at this point in the history
  • Loading branch information
javamind committed Oct 12, 2020
1 parent fbd1261 commit 09feb11
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions extension/highlight-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ var loadLanguages = require('prismjs/components/');
function extHighlightCode(_a) {
var selector = _a.selector;
var updateJava = function (html, language) {
if (language === 'java' || language === 'kotlin' || language === 'typescript') {
console.log(html);
return html.replace(/<span class=\"token operator\">&amp;<\/span>lt<span class=\"token punctuation\">;<\/span>/g, '&lt;')
if (language === 'java' || language === 'kotlin' || language === 'typescript' || language === 'javascript') {
return html
.replace(/<span class=\"token operator\">&amp;<\/span>quot<span class=\"token punctuation\">;<\/span>/g, '&quot;')
.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;
Expand All @@ -28,7 +29,6 @@ function extHighlightCode(_a) {
var language = elem.prop('data-lang') || 'javascript';
var fileContents = elem.html();
loadLanguages(language);
console.log(fileContents, language);
var highlightedContents = Prism.highlight(fileContents, Prism.languages[language], language);
var finalHtml = updateJava(highlightedContents, language);
elem.parent().replaceWith("<pre class=\"language-" + language + "\">" + finalHtml + "</pre>");
Expand Down
6 changes: 4 additions & 2 deletions extension/highlight-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ const loadLanguages = require('prismjs/components/');
export function extHighlightCode({selector}): Transform {

const updateJava = (html, language) => {
if (language === 'java' || language === 'kotlin' || language === 'typescript') {
return html.replace(/<span class=\"token operator\">&amp;<\/span>lt<span class=\"token punctuation\">;<\/span>/g, '&lt;')
if (language === 'java' || language === 'kotlin' || language === 'typescript' || language === 'javascript') {
return html
.replace(/<span class=\"token operator\">&amp;<\/span>quot<span class=\"token punctuation\">;<\/span>/g, '&quot;')
.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;
Expand Down
1 change: 1 addition & 0 deletions src/blog/2018/test2.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Test

[source, java, subs="specialchars"]
----
@RequestMapping("/api/hello")
class CallForPaperServiceTests {
/**
* Java comment
Expand Down

0 comments on commit 09feb11

Please sign in to comment.