Skip to content

Commit 5ae50fe

Browse files
committed
Commonmarker 1.0+ support
Ruby 2.x install CommonMarker < 1.0 and is tested there. Closes #1601
1 parent e2b43b6 commit 5ae50fe

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Add support for Ruby .rbs files (docstrings included) (#1673)
44
- Add built-in hybrid RDoc/Markdown renderer (`HybridMarkdown`) requiring no external gems (#1674)
55
- Add support for `#-` as a comment-block separator. See Getting Started Guide.
6+
- Add support for `commonmarker` version `>= 1.0`.
67
- Remove usage of jQuery in default templates. jQuery library is still packaged in templates for backward compatibility (#1675)
78
- Fix false self-referential mixin when bare name matches ancestor namespace (#1672)
89
- Fix bracket/brace map corruption from Ruby 3.0+ pattern matching deconstruction (#1671)

lib/yard/templates/helpers/html_helper.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ def html_markup_markdown(text)
9393
:tables,
9494
:with_toc_data,
9595
:no_intraemphasis).to_html
96+
when 'Commonmarker'
97+
provider.to_html(text, :options => { }, :plugins => { :syntax_highlighter => nil })
9698
when 'CommonMarker'
97-
CommonMarker.render_html(text, %i[DEFAULT GITHUB_PRE_LANG], %i[autolink table])
99+
provider.render_html(text, %i[DEFAULT GITHUB_PRE_LANG], %i[autolink table])
98100
else
99-
provider.new(text).to_html
101+
if provider.respond_to?(:to_html)
102+
provider.to_html(text)
103+
else
104+
provider.new(text).to_html
105+
end
100106
end
101107
end
102108

lib/yard/templates/helpers/markup_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def clear_markup_cache
3131
{:lib => :maruku, :const => 'Maruku'},
3232
{:lib => :'rpeg-markdown', :const => 'PEGMarkdown'},
3333
{:lib => :rdoc, :const => 'YARD::Templates::Helpers::Markup::RDocMarkdown'},
34-
{:lib => :commonmarker, :const => 'CommonMarker'}
34+
{:lib => :commonmarker, :const => defined?(CommonMarker) ? 'CommonMarker' : 'Commonmarker' }
3535
],
3636
:textile => [
3737
{:lib => :redcloth, :const => 'RedCloth'}

spec/templates/markup_processor_integrations/markdown_spec.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,12 @@
8282
end
8383
end
8484

85-
describe 'CommonMarker', if: RUBY_VERSION >= '2.3' do
85+
describe 'Commonmarker', if: RUBY_VERSION >= '2.3' do
8686
let(:markup) { :markdown }
8787
let(:markup_provider) { :commonmarker }
8888

8989
include_examples 'shared examples for markdown processors'
9090

91-
it 'generates level 2 header without id' do
92-
expect(rendered_document).to include('<h2>Example code listings</h2>')
93-
end
94-
9591
it 'creates line break via backslash' do
9692
expect(rendered_document).to include("commonmark line break with<br />\na backslash")
9793
end

0 commit comments

Comments
 (0)