Skip to content

Commit

Permalink
Make sure the exclude_languages will be an array.
Browse files Browse the repository at this point in the history
Signed-off-by: corvofeng <[email protected]>
  • Loading branch information
corvofeng committed Dec 22, 2019
1 parent 8d45180 commit 985c281
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/plugins/filter/before_post_render/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const rLangCaption = /([^\s]+)\s*(.+)?/;

function backtickCodeBlock(data) {
const config = this.config.highlight || {};
const { log } = this;
if (!config.enable) return;
data.content = data.content.replace(rBacktick, ($0, start, $2, _args, content, end) => {
const args = _args.split('=').shift();
Expand All @@ -35,6 +36,13 @@ function backtickCodeBlock(data) {
}
}

if (options.exclude_languages && Array.isArray(options.exclude_languages)) {
// The exclude_languages is an array
} else {
log.debug(`The highlight.exclude_languages does not work with: ${options.exclude_languages}`);
options.exclude_languages = [];
}

if (args) {
const match = rAllOptions.exec(args) || rLangCaption.exec(args);

Expand All @@ -50,13 +58,11 @@ function backtickCodeBlock(data) {
}
}

if (options.exclude_languages) {
if (options.exclude_languages.includes(options.lang)) {
// Only wrap with <pre><code class="lang"></code></pre>
options.wrap = false;
options.gutter = false;
options.autoDetect = false;
}
if (options.exclude_languages.includes(options.lang)) {
// Only wrap with <pre><code class="lang"></code></pre>
options.wrap = false;
options.gutter = false;
options.autoDetect = false;
}
}
}
Expand Down

0 comments on commit 985c281

Please sign in to comment.