Class: Solargraph::Pin::Documenting::DocSection
- Inherits:
-
Object
- Object
- Solargraph::Pin::Documenting::DocSection
- Defined in:
- lib/solargraph/pin/documenting.rb
Overview
A documentation formatter that either performs Markdown conversion for text, or applies backticks for code blocks.
Instance Attribute Summary collapse
- #plaintext ⇒ String readonly
Instance Method Summary collapse
- #code? ⇒ Boolean
- #concat(text) ⇒ String
-
#initialize(code) ⇒ DocSection
constructor
A new instance of DocSection.
- #to_s ⇒ Object
Constructor Details
#initialize(code) ⇒ DocSection
Returns a new instance of DocSection.
27 28 29 30 |
# File 'lib/solargraph/pin/documenting.rb', line 27 def initialize code @plaintext = String.new('') @code = code end |
Instance Attribute Details
#plaintext ⇒ String (readonly)
24 25 26 |
# File 'lib/solargraph/pin/documenting.rb', line 24 def plaintext @plaintext end |
Instance Method Details
#code? ⇒ Boolean
32 33 34 |
# File 'lib/solargraph/pin/documenting.rb', line 32 def code? @code end |
#concat(text) ⇒ String
38 39 40 |
# File 'lib/solargraph/pin/documenting.rb', line 38 def concat text @plaintext.concat text end |
#to_s ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/solargraph/pin/documenting.rb', line 42 def to_s return "\n```ruby\n#{@plaintext}#{@plaintext.end_with?("\n") ? '' : "\n"}```\n\n" if code? ReverseMarkdown.convert unescape_brackets(Maruku.new(escape_brackets(@plaintext), on_error: :raise).to_html) rescue MaRuKu::Exception # Maruku exceptions usually indicate that the documentation is in # RDoc syntax. ReverseMarkdown.convert YARD::Templates::Helpers::Markup::RDocMarkup.new(@plaintext).to_html end |