diff --git a/lib/sdoc/postprocessor.rb b/lib/sdoc/postprocessor.rb index 65b3cb47..525257b6 100644 --- a/lib/sdoc/postprocessor.rb +++ b/lib/sdoc/postprocessor.rb @@ -12,6 +12,7 @@ def process(rendered) rebase_urls!(document) version_rails_guides_urls!(document) unlink_unintentional_ref_links!(document) + style_ref_links!(document) highlight_code_blocks!(document) document.to_s @@ -78,6 +79,15 @@ def unlink_unintentional_ref_links!(document) end end + def style_ref_links!(document) + document.css(".description a[href^='classes/']:has(> text():only-child)").each do |element| + text = element.inner_text + if !text.include?(" ") || text.match?(/\S\(/) + element.inner_html = "#{element.inner_html}" + end + end + end + def highlight_code_blocks!(document) document.css(".description pre > code, .sourcecode pre > code").each do |element| code = element.inner_text diff --git a/spec/postprocessor_spec.rb b/spec/postprocessor_spec.rb index b6615538..5ba4bd16 100644 --- a/spec/postprocessor_spec.rb +++ b/spec/postprocessor_spec.rb @@ -91,6 +91,42 @@ _(SDoc::Postprocessor.process(rendered)).must_include expected end + it "styles unstyled code ref links in descriptions" do + rendered = <<~HTML + + +
+ Qux + Qux + Foo#bar?(qux, &block) + *_bar! + + Qux + Not Code + (also) not code +
+ + Permalink + HTML + + expected = <<~HTML +
+ Qux + Qux + Foo#bar?(qux, &block) + *_bar! + + Qux + Not Code + (also) not code +
+ + Permalink + HTML + + _(SDoc::Postprocessor.process(rendered)).must_include expected + end + it "highlights code blocks" do rendered = <<~HTML