debian-mirror-gitlab/spec/lib/banzai/filter/markdown_filter_spec.rb

83 lines
2.2 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Banzai::Filter::MarkdownFilter do
2017-08-17 22:00:37 +05:30
include FilterSpecHelper
2018-11-08 19:23:39 +05:30
describe 'markdown engine from context' do
it 'defaults to CommonMark' do
expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return('test')
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
filter('test')
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
it 'uses CommonMark' do
expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return('test')
filter('test', { markdown_engine: :common_mark })
end
end
describe 'code block' do
context 'using CommonMark' do
before do
stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark)
end
it 'adds language to lang attribute when specified' do
2019-03-02 22:35:43 +05:30
result = filter("```html\nsome code\n```", no_sourcepos: true)
2018-11-08 19:23:39 +05:30
2019-03-02 22:35:43 +05:30
expect(result).to start_with('<pre><code lang="html">')
2018-11-08 19:23:39 +05:30
end
it 'does not add language to lang attribute when not specified' do
2019-03-02 22:35:43 +05:30
result = filter("```\nsome code\n```", no_sourcepos: true)
2018-11-08 19:23:39 +05:30
2019-03-02 22:35:43 +05:30
expect(result).to start_with('<pre><code>')
2018-11-08 19:23:39 +05:30
end
2018-11-20 20:47:30 +05:30
it 'works with utf8 chars in language' do
2019-03-02 22:35:43 +05:30
result = filter("```日\nsome code\n```", no_sourcepos: true)
2018-11-20 20:47:30 +05:30
2019-03-02 22:35:43 +05:30
expect(result).to start_with('<pre><code lang="日">')
2018-11-20 20:47:30 +05:30
end
2018-11-08 19:23:39 +05:30
end
2019-03-02 22:35:43 +05:30
end
2018-11-08 19:23:39 +05:30
2019-03-02 22:35:43 +05:30
describe 'source line position' do
context 'using CommonMark' do
2018-11-08 19:23:39 +05:30
before do
2019-03-02 22:35:43 +05:30
stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark)
2018-11-08 19:23:39 +05:30
end
2019-03-02 22:35:43 +05:30
it 'defaults to add data-sourcepos' do
result = filter('test')
2018-11-08 19:23:39 +05:30
2019-03-02 22:35:43 +05:30
expect(result).to eq '<p data-sourcepos="1:1-1:4">test</p>'
2018-11-08 19:23:39 +05:30
end
2019-03-02 22:35:43 +05:30
it 'disables data-sourcepos' do
result = filter('test', no_sourcepos: true)
2018-11-08 19:23:39 +05:30
2019-03-02 22:35:43 +05:30
expect(result).to eq '<p>test</p>'
2018-11-08 19:23:39 +05:30
end
2017-08-17 22:00:37 +05:30
end
end
2018-11-20 20:47:30 +05:30
describe 'footnotes in tables' do
it 'processes footnotes in table cells' do
text = <<-MD.strip_heredoc
| Column1 |
| --------- |
| foot [^1] |
[^1]: a footnote
MD
2019-03-02 22:35:43 +05:30
result = filter(text, no_sourcepos: true)
2018-11-20 20:47:30 +05:30
expect(result).to include('<td>foot <sup')
expect(result).to include('<section class="footnotes">')
end
end
2017-08-17 22:00:37 +05:30
end