Class: Habari2md::Text
- Inherits:
-
Object
- Object
- Habari2md::Text
- Defined in:
- lib/habari2md.rb
Class Method Summary collapse
-
.html2text(content) ⇒ Object
Fork (!) html2text.py to convert form HTML to Markdown.
-
.simple_format(text) ⇒ String
Shameless snatch from Rails.
Class Method Details
.html2text(content) ⇒ Object
Fork (!) html2text.py to convert form HTML to Markdown.
31 32 33 34 35 36 37 38 39 |
# File 'lib/habari2md.rb', line 31 def self.html2text(content) IO.popen(html2text_script, "r+") do |io| io.write content io.close_write content = io.read io.close_read end content end |
.simple_format(text) ⇒ String
Shameless snatch from Rails.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/habari2md.rb', line 14 def self.simple_format(text) text = '' if text.nil? text = text.dup start_tag = '<p>' text = text.to_str text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br text.insert(0, start_tag) text << '</p>' return text end |