Skip to content

Commit

Permalink
Merge 7b7a7d3 into cfa62ae
Browse files Browse the repository at this point in the history
  • Loading branch information
ojab committed Jun 13, 2021
2 parents cfa62ae + 7b7a7d3 commit 9c0a331
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 71 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -18,6 +18,7 @@ end

group :markdown do
gem 'redcarpet'
gem 'commonmarker'
end

group :textile do
Expand Down
7 changes: 5 additions & 2 deletions lib/yard/templates/helpers/html_helper.rb
Expand Up @@ -78,16 +78,19 @@ def htmlify(text, markup = options.markup)
def html_markup_markdown(text)
# TODO: other libraries might be more complex
provider = markup_class(:markdown)
if provider.to_s == 'RDiscount'
case provider.to_s
when 'RDiscount'
provider.new(text, :autolink).to_html
elsif provider.to_s == 'RedcarpetCompat'
when 'RedcarpetCompat'
provider.new(text, :autolink,
:fenced_code,
:gh_blockcode,
:lax_spacing,
:tables,
:with_toc_data,
:no_intraemphasis).to_html
when 'CommonMarker'
CommonMarker.render_html(text, %i[DEFAULT GITHUB_PRE_LANG], %i[autolink])
else
provider.new(text).to_html
end
Expand Down
3 changes: 2 additions & 1 deletion lib/yard/templates/helpers/markup_helper.rb
Expand Up @@ -29,7 +29,8 @@ def clear_markup_cache
{:lib => :bluecloth, :const => 'BlueCloth'},
{:lib => :maruku, :const => 'Maruku'},
{:lib => :'rpeg-markdown', :const => 'PEGMarkdown'},
{:lib => :rdoc, :const => 'YARD::Templates::Helpers::Markup::RDocMarkdown'}
{:lib => :rdoc, :const => 'YARD::Templates::Helpers::Markup::RDocMarkdown'},
{:lib => :commonmarker, :const => 'CommonMarker'}
],
:textile => [
{:lib => :redcloth, :const => 'RedCloth'}
Expand Down
99 changes: 99 additions & 0 deletions spec/templates/markup_processor_integrations/markdown_spec.rb
@@ -0,0 +1,99 @@
# frozen_string_literal: true

require File.dirname(__FILE__) + '/integration_spec_helper'

RSpec.describe 'Markdown processrors integration' do
include_context 'shared helpers for markup processor integration specs'

shared_examples 'shared examples for markdown processors' do
let(:document) do
<<-MARKDOWN
## Example code listings
Indented block of Ruby code:
x = 1
Fenced block of Ruby code:
```
x = 2
```
Fenced and annotated block of Ruby code:
```ruby
x = 3
```
Fenced and annotated block of non-Ruby code:
```plain
x = 4
```
### Example line break
commonmark line break with\\
a backslash
MARKDOWN
end

it 'renders level 2 header' do
expect(rendered_document).to match(header_regexp(2, 'Example code listings'))
end

it 'renders indented block of code, and applies Ruby syntax highlight' do
expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '1'))
end

it 'renders fenced block of code, and applies Ruby syntax highlight' do
expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '2'))
end

it 'renders fenced and annotated block of Ruby code, and applies syntax highlight' do
expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '3'))
end

it 'renders fenced and annotated block of non-Ruby code, and does not apply syntax highlight' do
expect(rendered_document).to match('x = 4')
end

it "autolinks URLs" do
expect(html_renderer.htmlify('http://example.com', :markdown).chomp.gsub('&#47;', '/')).to eq(
'<p><a href="http://example.com">http://example.com</a></p>'
)
end
end

describe 'Redcarpet' do
let(:markup) { :markdown }
let(:markup_provider) { :redcarpet }

include_examples 'shared examples for markdown processors'


it 'generates anchor tags for level 2 header' do
expect(rendered_document).to include('<h2 id="example-code-listings">Example code listings</h2>')
end

it 'does not create line break via backslash' do
expect(rendered_document).to include("commonmark line break with\\\na backslash")
end
end

describe 'CommonMarker', if: RUBY_VERSION >= '2.3' do
let(:markup) { :markdown }
let(:markup_provider) { :commonmarker }

include_examples 'shared examples for markdown processors'

it 'generates level 2 header without id' do
expect(rendered_document).to include('<h2>Example code listings</h2>')
end

it 'creates line break via backslash' do
expect(rendered_document).to include("commonmark line break with<br />\na backslash")
end
end
end
68 changes: 0 additions & 68 deletions spec/templates/markup_processor_integrations/redcarpet_spec.rb

This file was deleted.

0 comments on commit 9c0a331

Please sign in to comment.