Skip to content

Commit

Permalink
perf(backtick_code): shorthand (#4369)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW authored Jun 23, 2020
1 parent 657a037 commit 0dad211
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/plugins/filter/before_post_render/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ const rLangCaption = /([^\s]+)\s*(.+)?/;
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 || {};

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

// neither highlight or prismjs is enabled, return escaped content directly.
Expand Down
8 changes: 8 additions & 0 deletions test/scripts/filters/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ describe('Backtick code block', () => {
hexo.config.prismjs = oldPrismCfg;
});

it('shorthand', () => {
const data = {
content: 'Hello, world!'
};

should.not.exist(codeBlock(data));
});

it('highlightjs - default', () => {
const data = {
content: [
Expand Down

0 comments on commit 0dad211

Please sign in to comment.