Class: ClothRed

Inherits:
String
  • Object
show all
Defined in:
lib/clothred.rb

Constant Summary collapse

TEXT_FORMATTING =

[
  ["<b>", "**"], ["</b>","**"], ["<em>","_"], ["</em>", "_"], ["<b>", "*"], 
  ["</b>", "*"], ["<cite>", "??"], ["</cite>", "??"], ["<code>", "@"], 
  ["</code>", "@"], ["<del>", "-"], ["</del>", "-"], ["<ins>", "+"], 
  ["</ins>", "+"], ["<sup>","^"], ["</sup>","^"], ["<sub>","~"], ["</sub>","~"], 
  ["<strong>", "*"], ["</strong>", "*"], ["<i>","__"], ["</i>", "__"]
]
HEADINGS =
[
  ["<h1>","h1. "], ["</h1>", "\n\n"], ["<h2>","h2. "], ["</h2>", "\n\n"], 
  ["<h3>","h3. "], ["</h3>", "\n\n"], ["<h4>","h4. "], ["</h4>", "\n\n"], 
  ["<h5>","h5. "], ["</h5>", "\n\n"], ["<h6>","h6. "], ["</h6>", "\n\n"], 
  ["<h7>","h7. "], ["</h7>", "\n\n"]
]
STRUCTURES =
[
  ["<p>", "p. "],["</p>","\n\n"], ["<blockquote>", "bq. "], ["</blockquote>",""], 
  ["<br />", "\n"], ["<br>", "\n"]
]
ENTITIES =
[
  ["&#8220;", '"'], ["&#8221;", '"'], ["&#8212;", "--"], ["&#8212;", "--"], 
  ["&#8211;","-"], ["&#8230;", "..."], ["&#215;", " x "], ["&#8482;","(TM)"], 
  ["&#174;","(R)"], ["&#169;","(C)"], ["&#8217;", "'"]
]
TABLES =
[
  ["<table>",""], ["</table>",""], ["<tr>",""], ["</tr>","|\n"], ["<td>","|"], 
  ["</td>",""], ["<th>", "|_."], ["</th>", ""]
]

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ ClothRed

Returns a new instance of ClothRed.



50
51
52
53
# File 'lib/clothred.rb', line 50

def initialize (html)
  super(html)
  @workingcopy = html
end

Instance Method Details

#to_textileObject

Call all necessary methods to convert a string of HTML into Textile markup.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/clothred.rb', line 57

def to_textile

  
  headings(@workingcopy)
  structure(@workingcopy)
  text_formatting(@workingcopy)
  entities(@workingcopy)
  tables(@workingcopy)
  @workingcopy = CGI::unescapeHTML(@workingcopy)
  @workingcopy
  
end