From 63e66c3586b3afd71be518a8b34c08534654381e Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 26 Apr 2015 05:31:00 +0900 Subject: [PATCH] Fix backtick_code_block for ignore tab character. ``` (tab) Hello world! 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. --- .../before_post_render/backtick_code_block.js | 12 ++++---- test/scripts/filters/backtick_code_block.js | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) 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: [