{
@@ -455,29 +473,32 @@ export default class MdToHtml {
// The strings includes the last \n that is part of the fence,
// so we remove it because we need the exact code in the source block
- const trimmedStr = str.replace(/(.*)\n$/, '$1');
+ const trimmedStr = this.removeLastNewLine(str);
const sourceBlockHtml = `${markdownIt.utils.escapeHtml(trimmedStr)}
`;
- try {
- let hlCode = '';
+ if (this.shouldSkipHighlighting(trimmedStr, lang)) {
+ outputCodeHtml = markdownIt.utils.escapeHtml(trimmedStr);
+ } else {
+ try {
+ let hlCode = '';
- const cacheKey = md5(`${str}_${lang}`);
+ const cacheKey = md5(`${str}_${lang}`);
- if (options.codeHighlightCacheKey && this.cachedHighlightedCode_[cacheKey]) {
- hlCode = this.cachedHighlightedCode_[cacheKey];
- } else {
- if (lang && hljs.getLanguage(lang)) {
- // hlCode = hljs.highlight(lang, trimmedStr, true).value;
- hlCode = hljs.highlight(trimmedStr, { language: lang, ignoreIllegals: true }).value;
+ if (options.codeHighlightCacheKey && this.cachedHighlightedCode_[cacheKey]) {
+ hlCode = this.cachedHighlightedCode_[cacheKey];
} else {
- hlCode = hljs.highlightAuto(trimmedStr).value;
+ if (lang && hljs.getLanguage(lang)) {
+ hlCode = hljs.highlight(trimmedStr, { language: lang, ignoreIllegals: true }).value;
+ } else {
+ hlCode = hljs.highlightAuto(trimmedStr).value;
+ }
+ this.cachedHighlightedCode_[cacheKey] = hlCode;
}
- this.cachedHighlightedCode_[cacheKey] = hlCode;
- }
- outputCodeHtml = hlCode;
- } catch (error) {
- outputCodeHtml = markdownIt.utils.escapeHtml(trimmedStr);
+ outputCodeHtml = hlCode;
+ } catch (error) {
+ outputCodeHtml = markdownIt.utils.escapeHtml(trimmedStr);
+ }
}
const html = `${sourceBlockHtml}
${outputCodeHtml}
`;