Skip to content

Commit

Permalink
Fix backtick_code_block for ignore tab character.
Browse files Browse the repository at this point in the history
<raw>``` (tab)
Hello world!
</new>

The expressions like this causes a bug.

In this case, `args` in backtickCodeBlock() is not blank (but a tab character).
Then the `args` will not match both of rAllOptions and rLangCaption.
So `match` will be `null`. and we can't get `match[1]` in this case.

To fix it, I check whether `match` is null or not.
  • Loading branch information
naokiy committed Apr 25, 2015
1 parent eaa0ed5 commit 63e66c3
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 63e66c3

Please sign in to comment.