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.
25 26 27 28 |
# File 'lib/solargraph/pin/documenting.rb', line 25 def initialize code @plaintext = String.new('') @code = code end |
Instance Attribute Details
#plaintext ⇒ String (readonly)
22 23 24 |
# File 'lib/solargraph/pin/documenting.rb', line 22 def plaintext @plaintext end |
Instance Method Details
#code? ⇒ Boolean
30 31 32 |
# File 'lib/solargraph/pin/documenting.rb', line 30 def code? @code end |
#concat(text) ⇒ String
36 37 38 |
# File 'lib/solargraph/pin/documenting.rb', line 36 def concat text @plaintext.concat text end |
#to_s ⇒ Object
40 41 42 43 |
# File 'lib/solargraph/pin/documenting.rb', line 40 def to_s return "\n```ruby\n#{@plaintext}#{@plaintext.end_with?("\n") ? '' : "\n"}```\n\n" if code? ReverseMarkdown.convert unescape_brackets(Kramdown::Document.new(escape_brackets(@plaintext), input: 'GFM').to_html) end |