public
Rubygem
Description: BlueCloth's evil twin - convert HTML into Markdown
Homepage: http://www.craigjolicoeur.com/clothblue
Clone URL: git://github.com/cpjolicoeur/clothblue.git
Search Repo:
Click here to lend your support to: clothblue and make a donation at www.pledgie.com !
rework the textile codes into the corresponding markdown codes.  remove 
codes that arent used by markdown
cpjolicoeur (author)
Wed May 14 08:52:19 -0700 2008
commit  adf26df220d96609c80fb13d81249a14c9431ceb
tree    435d371a612be348f83639f8630182b13f4a48cb
parent  8d25f21e4e9eab4c47d28e335133bb1fa424df0e
...
14
15
16
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
14
15
16
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
0
@@ -14,5 +14,99 @@
0
 $KCODE = "U"
0
 
0
 class ClothBlue < String
0
-end
0
+#--
0
+ TEXT_FORMATTING = [
0
+ ["<b>", "**"], ["</b>","**"], ["<em>","_"], ["</em>", "_"], ["<b>", "**"],
0
+ ["</b>", "**"], ["<code>", "`"], ["<i>","_"], ["</i>", "_"]
0
+ ["</code>", "`"], ["<strong>", "**"], ["</strong>", "**"]
0
+ ]
0
+
0
+ HEADINGS = [
0
+ ["<h1>","# "], ["</h1>", "#"], ["<h2>","## "], ["</h2>", "##"],
0
+ ["<h3>","### "], ["</h3>", "###"], ["<h4>","#### "], ["</h4>", "####"],
0
+ ["<h5>","##### "], ["</h5>", "#####"], ["<h6>","###### "], ["</h6>", "######"]
0
+ ]
0
+
0
+ STRUCTURES = [
0
+ ["<p>", ""],["</p>","\n\n"], ["<blockquote>", "> "], ["</blockquote>","\n"],
0
+ ["<br />", "\n\n"], ["<br>", "\n\n"]
0
+ ]
0
+
0
+ ENTITIES = [
0
+ ["&#8220;", '"'], ["&#8221;", '"'], ["&#8212;", "--"], ["&#8212;", "--"],
0
+ ["&#8211;","-"], ["&#8230;", "..."], ["&#215;", " x "], ["&#8482;","(TM)"],
0
+ ["&#174;","(R)"], ["&#169;","(C)"], ["&#8217;", "'"]
0
+ ]
0
+
0
+ TABLES = [
0
+ ["<table>","\n\n<table>"], ["</table>","</table>\n\n"]
0
+ ]
0
+
0
+ def initialize (html)
0
+ super(html)
0
+ @workingcopy = html
0
+ end
0
+
0
+#++
0
+ #Call all necessary methods to convert a string of HTML into Textile markup.
0
+
0
+ def to_textile
0
+ headings(@workingcopy)
0
+ structure(@workingcopy)
0
+ text_formatting(@workingcopy)
0
+ entities(@workingcopy)
0
+ tables(@workingcopy)
0
+ @workingcopy = CGI::unescapeHTML(@workingcopy)
0
+ @workingcopy
0
+ end
0
+
0
+#--
0
+ #The conversion methods themselves are private.
0
+ private
0
+
0
+ def text_formatting(text)
0
+ TEXT_FORMATTING.each do |htmltag, textiletag|
0
+ text.gsub!(htmltag, textiletag)
0
+ end
0
+ text
0
+ end
0
+
0
+
0
+ def headings(text)
0
+ HEADINGS.each do |htmltag, textiletag|
0
+ text.gsub!(htmltag, textiletag)
0
+ end
0
+ text
0
+ end
0
+
0
+
0
+ def entities(text)
0
+ ENTITIES.each do |htmlentity, textileentity|
0
+ text.gsub!(htmlentity, textileentity)
0
+ end
0
+ text
0
+ end
0
+
0
+
0
+ def structure(text)
0
+ STRUCTURES.each do |htmltag, textiletag|
0
+ text.gsub!(htmltag, textiletag)
0
+ end
0
+ text
0
+ end
0
+
0
+ def tables(text)
0
+ TABLES.each do |htmltag, textiletag|
0
+ text.gsub!(htmltag, textiletag)
0
+ end
0
+ text
0
+ end
0
+
0
+
0
+ def css_styles(text)
0
+ #TODO: Translate CSS-styles
0
+ text
0
+ end
0
+#++
0
+end # end class ClothBlue

Comments

    No one has commented yet.