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
Click here to lend your support to: clothblue and make a donation at www.pledgie.com !
remove all traces of texttile - use markdown instead of course
cpjolicoeur (author)
Wed May 14 09:29:38 -0700 2008
commit  b5a1b4027c81826868588783fbc47cff854bb0cf
tree    5c078b6deec67f8a7c78792eb89e866dc9814a24
parent  daee589339cca71d6a3473c1f8c96d12801b84d7
...
17
18
19
20
 
21
22
23
24
25
26
27
 
 
 
28
29
30
31
32
 
 
33
34
35
...
37
38
39
 
 
 
 
40
41
42
...
48
49
50
51
 
52
53
 
54
55
56
 
57
58
59
...
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
...
17
18
19
 
20
21
22
23
24
 
 
 
25
26
27
28
29
30
 
 
31
32
33
34
35
...
37
38
39
40
41
42
43
44
45
46
...
52
53
54
 
55
56
 
57
58
59
60
61
62
63
64
...
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
 
 
112
113
114
115
116
0
@@ -17,19 +17,19 @@ class ClothBlue < String
0
 #--
0
   TEXT_FORMATTING = [
0
     ["<b>", "**"], ["</b>","**"], ["<em>","_"], ["</em>", "_"], ["<b>", "**"],
0
- ["</b>", "**"], ["<code>", "`"], ["<i>","_"], ["</i>", "_"]
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
+ ["<h1>","# "], ["</h1>", " #\n\n"], ["<h2>","## "], ["</h2>", " ##\n\n"],
0
+ ["<h3>","### "], ["</h3>", " ###\n\n"], ["<h4>","#### "], ["</h4>", " ####\n\n"],
0
+ ["<h5>","##### "], ["</h5>", " #####\n\n"], ["<h6>","###### "], ["</h6>", " ######\n\n"]
0
   ]
0
 
0
   STRUCTURES = [
0
- ["<p>", ""],["</p>","\n\n"], ["<blockquote>", "> "], ["</blockquote>","\n"],
0
- ["<br />", "\n\n"], ["<br>", "\n\n"]
0
+ ["<p>", "\n\n"],["</p>","\n\n"], ["<blockquote>", "> "], ["</blockquote>","\n"],
0
+ ["<br />", "\n"], ["<br>", "\n"]
0
   ]
0
 
0
   ENTITIES = [
0
@@ -37,6 +37,10 @@ class ClothBlue < String
0
     ["&#8211;","-"], ["&#8230;", "..."], ["&#215;", " x "], ["&#8482;","(TM)"],
0
     ["&#174;","(R)"], ["&#169;","(C)"], ["&#8217;", "'"]
0
   ]
0
+
0
+ LISTS = [
0
+ ["<ol>", ""], ["</ol>", "\n\n"], ["<ul>", ""], ["</ul>", "\n\n"], ["<li>", "+ "], ["</li>", "\n"]
0
+ ]
0
 
0
   TABLES = [
0
     ["<table>","\n\n<table>"], ["</table>","</table>\n\n"]
0
@@ -48,12 +52,13 @@ class ClothBlue < String
0
   end
0
 
0
 #++
0
- #Call all necessary methods to convert a string of HTML into Textile markup.
0
+ #Call all necessary methods to convert a string of HTML into Markdown markup.
0
 
0
- def to_textile
0
+ def to_markdown
0
     headings(@workingcopy)
0
     structure(@workingcopy)
0
     text_formatting(@workingcopy)
0
+ lists(@workingcopy)
0
     entities(@workingcopy)
0
     tables(@workingcopy)
0
     @workingcopy = CGI::unescapeHTML(@workingcopy)
0
@@ -65,39 +70,47 @@ class ClothBlue < String
0
   private
0
 
0
   def text_formatting(text)
0
- TEXT_FORMATTING.each do |htmltag, textiletag|
0
- text.gsub!(htmltag, textiletag)
0
+ TEXT_FORMATTING.each do |htmltag, markdowntag|
0
+ text.gsub!(htmltag, markdowntag)
0
     end
0
     text
0
   end
0
 
0
 
0
   def headings(text)
0
- HEADINGS.each do |htmltag, textiletag|
0
- text.gsub!(htmltag, textiletag)
0
+ HEADINGS.each do |htmltag, markdowntag|
0
+ text.gsub!(htmltag, markdowntag)
0
+ end
0
+ text
0
+ end
0
+
0
+
0
+ def lists(text)
0
+ LISTS.each do |htmltag, markdowntag|
0
+ text.gsub!(htmltag, markdowntag)
0
     end
0
     text
0
   end
0
 
0
 
0
   def entities(text)
0
- ENTITIES.each do |htmlentity, textileentity|
0
- text.gsub!(htmlentity, textileentity)
0
+ ENTITIES.each do |htmlentity, markdownentity|
0
+ text.gsub!(htmlentity, markdownentity)
0
     end
0
     text
0
   end
0
 
0
 
0
   def structure(text)
0
- STRUCTURES.each do |htmltag, textiletag|
0
- text.gsub!(htmltag, textiletag)
0
+ STRUCTURES.each do |htmltag, markdowntag|
0
+ text.gsub!(htmltag, markdowntag)
0
     end
0
     text
0
   end
0
 
0
   def tables(text)
0
- TABLES.each do |htmltag, textiletag|
0
- text.gsub!(htmltag, textiletag)
0
+ TABLES.each do |htmltag, markdowntag|
0
+ text.gsub!(htmltag, markdowntag)
0
     end
0
     text
0
   end

Comments

    No one has commented yet.