diff --git a/test/fixtures/post_render.js b/test/fixtures/post_render.js index c6f7f067a0..a03afe7f09 100644 --- a/test/fixtures/post_render.js +++ b/test/fixtures/post_render.js @@ -7,7 +7,7 @@ const code = [ ' sleep()' ].join('\n'); -const content = [ +exports.content = [ '# Title', '``` python', code, @@ -24,8 +24,6 @@ const content = [ '{% endquote %}' ].join('\n'); -exports.content = content; - exports.expected = [ '

Title

', highlight(code, {lang: 'python'}), @@ -50,3 +48,27 @@ exports.expected_disable_nunjucks = [ 'quote content
', '{% endquote %}

' ].join(''); + +exports.content_for_issue_3346 = [ + '# Title', + '```', + '{% test1 %}', + '{{ test2 }}', + '```', + 'some content', + '', + '## Another title', + '{% blockquote %}', + 'quote content', + '{% endblockquote %}' +].join('\n'); + +exports.expected_for_issue_3346 = [ + '

Title

', + highlight('{% test1 %}\n{{ test2 }}').replace(/{/g, '{').replace(/}/g, '}'), // Escaped by backtick_code_block + '\n

some content

\n', + '

Another title

', + '
', + '

quote content

\n', + '
' +].join(''); diff --git a/test/scripts/hexo/post.js b/test/scripts/hexo/post.js index 846c3ef3f5..6e42af176b 100644 --- a/test/scripts/hexo/post.js +++ b/test/scripts/hexo/post.js @@ -939,4 +939,52 @@ describe('Post', () => { }); }); + // test for Issue #3346 + it('render() - swig tag inside backtick code block', async () => { + const content = fixture.content_for_issue_3346; + + const data = await post.render(null, { + content, + engine: 'markdown' + }); + + data.content.trim().should.eql(fixture.expected_for_issue_3346); + }); + + // test for https://github.com/hexojs/hexo/pull/4171#issuecomment-594412367 + it('render() - markdown content right after swig tag', async () => { + const content = [ + '{% pullquote warning %}', + 'Text', + '{% endpullquote %}', + '# Title 0', + '{% pullquote warning %}', + 'Text', + '{% endpullquote %}', + '{% pullquote warning %}', + 'Text', + '{% endpullquote %}', + '# Title 1', + '{% pullquote warning %}', + 'Text', + '{% endpullquote %}', + '{% pullquote warning %}Text{% endpullquote %}', + '# Title 2', + '{% pullquote warning %}Text{% endpullquote %}', + '{% pullquote warning %}Text{% endpullquote %}', + '# Title 3', + '{% pullquote warning %}Text{% endpullquote %}' + ].join('\n'); + + const data = await post.render(null, { + content, + engine: 'markdown' + }); + + // We only to make sure markdown content is rendered correctly + data.content.trim().should.include('

Title 0

'); + data.content.trim().should.include('

Title 1

'); + data.content.trim().should.include('

Title 2

'); + data.content.trim().should.include('

Title 3

'); + }); });