|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require File.dirname(__FILE__) + '/integration_spec_helper' |
| 4 | + |
| 5 | +RSpec.describe 'Markdown processrors integration' do |
| 6 | + include_context 'shared helpers for markup processor integration specs' |
| 7 | + |
| 8 | + shared_examples 'shared examples for markdown processors' do |
| 9 | + let(:document) do |
| 10 | + <<-MARKDOWN |
| 11 | +## Example code listings |
| 12 | +
|
| 13 | +Indented block of Ruby code: |
| 14 | +
|
| 15 | + x = 1 |
| 16 | +
|
| 17 | +Fenced block of Ruby code: |
| 18 | +
|
| 19 | +``` |
| 20 | +x = 2 |
| 21 | +``` |
| 22 | +
|
| 23 | +Fenced and annotated block of Ruby code: |
| 24 | +
|
| 25 | +```ruby |
| 26 | +x = 3 |
| 27 | +``` |
| 28 | +
|
| 29 | +Fenced and annotated block of non-Ruby code: |
| 30 | +
|
| 31 | +```plain |
| 32 | +x = 4 |
| 33 | +``` |
| 34 | +
|
| 35 | +### Example line break |
| 36 | +
|
| 37 | +commonmark line break with\\ |
| 38 | +a backslash |
| 39 | +MARKDOWN |
| 40 | + end |
| 41 | + |
| 42 | + it 'renders level 2 header' do |
| 43 | + expect(rendered_document).to match(header_regexp(2, 'Example code listings')) |
| 44 | + end |
| 45 | + |
| 46 | + it 'renders indented block of code, and applies Ruby syntax highlight' do |
| 47 | + expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '1')) |
| 48 | + end |
| 49 | + |
| 50 | + it 'renders fenced block of code, and applies Ruby syntax highlight' do |
| 51 | + expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '2')) |
| 52 | + end |
| 53 | + |
| 54 | + it 'renders fenced and annotated block of Ruby code, and applies syntax highlight' do |
| 55 | + expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '3')) |
| 56 | + end |
| 57 | + |
| 58 | + it 'renders fenced and annotated block of non-Ruby code, and does not apply syntax highlight' do |
| 59 | + expect(rendered_document).to match('x = 4') |
| 60 | + end |
| 61 | + |
| 62 | + it "autolinks URLs" do |
| 63 | + expect(html_renderer.htmlify('http://example.com', :markdown).chomp.gsub('/', '/')).to eq( |
| 64 | + '<p><a href="http://example.com">http://example.com</a></p>' |
| 65 | + ) |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + describe 'Redcarpet' do |
| 70 | + let(:markup) { :markdown } |
| 71 | + let(:markup_provider) { :redcarpet } |
| 72 | + |
| 73 | + include_examples 'shared examples for markdown processors' |
| 74 | + |
| 75 | + |
| 76 | + it 'generates anchor tags for level 2 header' do |
| 77 | + expect(rendered_document).to include('<h2 id="example-code-listings">Example code listings</h2>') |
| 78 | + end |
| 79 | + |
| 80 | + it 'does not create line break via backslash' do |
| 81 | + expect(rendered_document).to include("commonmark line break with\\\na backslash") |
| 82 | + end |
| 83 | + end |
| 84 | + |
| 85 | + describe 'CommonMarker', if: RUBY_VERSION >= '2.3' do |
| 86 | + let(:markup) { :markdown } |
| 87 | + let(:markup_provider) { :commonmarker } |
| 88 | + |
| 89 | + include_examples 'shared examples for markdown processors' |
| 90 | + |
| 91 | + it 'generates level 2 header without id' do |
| 92 | + expect(rendered_document).to include('<h2>Example code listings</h2>') |
| 93 | + end |
| 94 | + |
| 95 | + it 'creates line break via backslash' do |
| 96 | + expect(rendered_document).to include("commonmark line break with<br />\na backslash") |
| 97 | + end |
| 98 | + end |
| 99 | +end |
0 commit comments