diff --git a/lib/plugins/filter/before_post_render/backtick_code_block.js b/lib/plugins/filter/before_post_render/backtick_code_block.js index d37eb2ce1a..034a82b97e 100644 --- a/lib/plugins/filter/before_post_render/backtick_code_block.js +++ b/lib/plugins/filter/before_post_render/backtick_code_block.js @@ -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 = '' + match[2] + ''; + if (match[2]){ + options.caption = '' + match[2] + ''; - if (match[3]){ - options.caption += '' + (match[4] ? match[4] : 'link') + ''; + if (match[3]){ + options.caption += '' + (match[4] ? match[4] : 'link') + ''; + } } } } diff --git a/test/scripts/filters/backtick_code_block.js b/test/scripts/filters/backtick_code_block.js index 00e23f2dc9..9cc47ffc92 100644 --- a/test/scripts/filters/backtick_code_block.js +++ b/test/scripts/filters/backtick_code_block.js @@ -54,6 +54,36 @@ describe('Backtick code block', function(){ data.content.should.eql('' + highlight(code, {lang: 'js'}) + ''); }); + it('without language name', function(){ + var data = { + content: [ + '```', + code, + '```' + ].join('\n') + }; + + var expected = highlight(code); + + codeBlock(data); + data.content.should.eql('' + expected + ''); + }); + + 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('' + expected + ''); + }); + it('title', function(){ var data = { content: [