Skip to content

Commit

Permalink
Merge pull request #1229 from naokiy/fix_backtick_codeblock_regex
Browse files Browse the repository at this point in the history
Fix backtick_code_block for ignore tab character.
  • Loading branch information
tommy351 committed Apr 26, 2015
2 parents eaa0ed5 + 63e66c3 commit 1a16481
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/plugins/filter/before_post_render/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ function backtickCodeBlock(data){
match = args.match(rLangCaption);
}

options.lang = match[1];
if (match) {
options.lang = match[1];

if (match[2]){
options.caption = '<span>' + match[2] + '</span>';
if (match[2]){
options.caption = '<span>' + match[2] + '</span>';

if (match[3]){
options.caption += '<a href="' + match[3] + '">' + (match[4] ? match[4] : 'link') + '</a>';
if (match[3]){
options.caption += '<a href="' + match[3] + '">' + (match[4] ? match[4] : 'link') + '</a>';
}
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions test/scripts/filters/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,36 @@ describe('Backtick code block', function(){
data.content.should.eql('<escape>' + highlight(code, {lang: 'js'}) + '</escape>');
});

it('without language name', function(){
var data = {
content: [
'```',
code,
'```'
].join('\n')
};

var expected = highlight(code);

codeBlock(data);
data.content.should.eql('<escape>' + expected + '</escape>');
});

it('without language name - ignore tab character', function(){
var data = {
content: [
'``` \t',
code,
'```'
].join('\n')
};

var expected = highlight(code);

codeBlock(data);
data.content.should.eql('<escape>' + expected + '</escape>');
});

it('title', function(){
var data = {
content: [
Expand Down

0 comments on commit 1a16481

Please sign in to comment.