class Solargraph::Pin::Documenting::DocSection
A documentation formatter that either performs Markdown conversion for text, or applies backticks for code blocks.
Attributes
plaintext[R]
@return [String]
Public Class Methods
new(code)
click to toggle source
@param code [Boolean] True if this section is a code block
# File lib/solargraph/pin/documenting.rb, line 24 def initialize code @plaintext = String.new('') @code = code end
Public Instance Methods
code?()
click to toggle source
# File lib/solargraph/pin/documenting.rb, line 29 def code? @code end
concat(text)
click to toggle source
@param text [String] @return [String]
# File lib/solargraph/pin/documenting.rb, line 35 def concat text @plaintext.concat text end
to_s()
click to toggle source
# File lib/solargraph/pin/documenting.rb, line 39 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
Private Instance Methods
escape_brackets(text)
click to toggle source
@param text [String] @return [String]
# File lib/solargraph/pin/documenting.rb, line 48 def escape_brackets text # text.gsub(/(\[[^\]]*\])([^\(]|\z)/, '!!!^\1^!!!\2') text.gsub('[', '!!!!b').gsub(']', 'e!!!!') end
unescape_brackets(text)
click to toggle source
@param text [String] @return [String]
# File lib/solargraph/pin/documenting.rb, line 55 def unescape_brackets text text.gsub('!!!!b', '[').gsub('e!!!!', ']') end