Class: TTY::Markdown::Converter

Inherits:
Kramdown::Converter::Base
  • Object
show all
Defined in:
lib/monadic_chat/helper.rb

Overview

Converts a Kramdown::Document tree to a terminal friendly output

Instance Method Summary collapse

Instance Method Details

#convert_p(ell, opts) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/monadic_chat/helper.rb', line 50

def convert_p(ell, opts)
  indent = SPACE * @current_indent
  result = []

  result << indent unless %i[blockquote li].include?(opts[:parent].type)

  opts[:indent] = @current_indent
  opts[:indent] = 0 if opts[:parent].type == :blockquote

  content = inner(ell, opts)

  symbols = %q{[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]}
  # result << content.join.gsub(/(?<!#{symbols})\n(?!#{symbols})/m) { " " }.gsub(/ +/) { " " }
  result << content.join.gsub(/(?<!#{symbols})\n(?!#{symbols})/m) { "" }
  result << NEWLINE unless result.last.to_s.end_with?(NEWLINE)
  result
end