Class: Linebreaker

Inherits:
Object
  • Object
show all
Defined in:
lib/filters/linebreaker.rb

Overview

This filter just replaces single newlines with “<br />” tags.

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Linebreaker

Returns a new instance of Linebreaker.



4
5
6
# File 'lib/filters/linebreaker.rb', line 4

def initialize(input)
  @input = input
end

Instance Method Details

#to_htmlObject



8
9
10
11
12
# File 'lib/filters/linebreaker.rb', line 8

def to_html
  @input.
    gsub(/(\S)\n(\S)/, "\\1<br />\n\\2").
    gsub(/(\S)\r\n(\S)/, "\\1<br />\n\\2")
end