Skip to content

Commit

Permalink
fix(filter/highlight): avoid escaping curly bracket when highlight & …
Browse files Browse the repository at this point in the history
…prismjs are disabled (#4489)
  • Loading branch information
curbengh committed Aug 23, 2020
1 parent ebc9008 commit 5795c12
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lib/plugins/filter/before_post_render/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const escapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}')
function backtickCodeBlock(data) {
const dataContent = data.content;

if (!dataContent.includes('```') && !dataContent.includes('~~~')) return;

const hljsCfg = this.config.highlight || {};
const prismCfg = this.config.prismjs || {};

if ((!dataContent.includes('```') && !dataContent.includes('~~~')) || (!hljsCfg.enable && !prismCfg.enable)) return;

data.content = dataContent.replace(rBacktick, ($0, start, $2, _args, _content, end) => {
let content = _content.replace(/\n$/, '');

Expand Down
62 changes: 31 additions & 31 deletions test/scripts/filters/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,43 @@ describe('Backtick code block', () => {
hexo.config.prismjs = defaultConfig.prismjs;
});

describe('highlightjs', () => {
it('disabled', () => {
const content = [
'``` js',
code,
'```'
].join('\n');

const data = {content};

hexo.config.highlight.enable = false;
hexo.config.prismjs.enable = false;
codeBlock(data);
data.content.should.eql(content.replace(/{/g, '{').replace(/}/g, '}'));
});
it('disabled', () => {
const content = [
'``` js',
code,
'```'
].join('\n');

const data = {content};

hexo.config.highlight.enable = false;
hexo.config.prismjs.enable = false;
codeBlock(data);
data.content.should.eql(content);
});

it('with no config (disabled)', () => {
const content = [
'``` js',
code,
'```'
].join('\n');
it('with no config (disabled)', () => {
const content = [
'``` js',
code,
'```'
].join('\n');

const data = {content};
const data = {content};

const oldHljsCfg = hexo.config.highlight;
const oldPrismCfg = hexo.config.prismjs;
delete hexo.config.highlight;
delete hexo.config.prismjs;
const oldHljsCfg = hexo.config.highlight;
const oldPrismCfg = hexo.config.prismjs;
delete hexo.config.highlight;
delete hexo.config.prismjs;

codeBlock(data);
data.content.should.eql(content.replace(/{/g, '{').replace(/}/g, '}'));
codeBlock(data);
data.content.should.eql(content);

hexo.config.highlight = oldHljsCfg;
hexo.config.prismjs = oldPrismCfg;
});
hexo.config.highlight = oldHljsCfg;
hexo.config.prismjs = oldPrismCfg;
});

describe('highlightjs', () => {
it('shorthand', () => {
const data = {
content: 'Hello, world!'
Expand Down

0 comments on commit 5795c12

Please sign in to comment.