module Solargraph::Pin::Documenting

def documentation

Returns:
  • (String) -
def documentation
  @documentation ||= begin
    html = Kramdown::Document.new(
      normalize_indentation(docstring.to_s),
      input: 'GFM',
      entity_output: :symbolic,
      syntax_highlighter: nil
    ).to_html
    ReverseMarkdown.convert(html, github_flavored: true).lines.map(&:rstrip).join("\n")
  end
end

def normalize_indentation text

Returns:
  • (String) -

Parameters:
  • text (String) --
def normalize_indentation text
  text.lines.map { |l| remove_odd_spaces(l).gsub(/^  /, "\t") }.join
end

def remove_odd_spaces line

Returns:
  • (String) -

Parameters:
  • line (String) --
def remove_odd_spaces line
  return line unless line.start_with?(' ')
  spaces = line.match(/^ +/)[0].length
  return line unless spaces.odd?
  line[1..-1]
end