Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type Hexo from '../../../hexo';
import type { RenderData } from '../../../types';

const rBacktick = /^((?:[^\S\r\n]*>){0,3}[^\S\r\n]*)(`{3,}|~{3,})[^\S\r\n]*((?:.*?[^`\s])?)[^\S\r\n]*\n((?:[\s\S]*?\n)?)(?:(?:[^\S\r\n]*>){0,3}[^\S\r\n]*)\2[^\S\r\n]?(\n+|$)/gm;
const rBacktick = /^((?:(?:[^\S\r\n]*>){0,3}|[-*+]|[0-9]+\.)[^\S\r\n]*)(`{3,}|~{3,})[^\S\r\n]*((?:.*?[^`\s])?)[^\S\r\n]*\n((?:[\s\S]*?\n)?)(?:(?:[^\S\r\n]*>){0,3}[^\S\r\n]*)\2[^\S\r\n]?(\n+|$)/gm;
const rAllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/;
const rLangCaption = /([^\s]+)\s*(.+)?/;

Expand Down
74 changes: 74 additions & 0 deletions test/scripts/filters/backtick_code_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,80 @@ describe('Backtick code block', () => {
codeBlock(data);
data.content.should.contain('\n\n# New line');
});

// https://github.com/hexojs/hexo/issues/5423
it('with ordered list', () => {
const data = {
content: [
'1. ``` js',
code,
'```',
'2. ``` js',
code,
'```'
].join('\n')
};

codeBlock(data);
data.content.should.eql([
'1. <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>',
'2. <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>'
].join('\n'));
});

// https://github.com/hexojs/hexo/issues/5423
it('with unordered list', () => {
let data = {
content: [
'- ``` js',
code,
'```',
'- ``` js',
code,
'```'
].join('\n')
};

codeBlock(data);
data.content.should.eql([
'- <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>',
'- <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>'
].join('\n'));

data = {
content: [
'* ``` js',
code,
'```',
'* ``` js',
code,
'```'
].join('\n')
};

codeBlock(data);
data.content.should.eql([
'* <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>',
'* <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>'
].join('\n'));

data = {
content: [
'+ ``` js',
code,
'```',
'+ ``` js',
code,
'```'
].join('\n')
};

codeBlock(data);
data.content.should.eql([
'+ <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>',
'+ <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>'
].join('\n'));
});
});

describe('prismjs', () => {
Expand Down
Loading