mcbean 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ require "test/unit"
2
+ require "mcbean"
3
+ require "shoulda"
4
+
5
+ gem "bluecloth", ">= 2.0"
6
+ require "bluecloth"
@@ -0,0 +1,111 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class TestMcBeanMarkdown < Test::Unit::TestCase
4
+ context "markdown" do
5
+ should "add whitespace around block elements" do
6
+ assert_markdown "before<div>inner</div>after", "before\ninner\nafter", false
7
+ end
8
+
9
+ should "convert h1 tag" do
10
+ assert_markdown "<h1>Foo</h1>", "\nFoo\n==========\n"
11
+ end
12
+
13
+ should "convert h2 tag" do
14
+ assert_markdown "<h2>Foo</h2>", "\nFoo\n----------\n"
15
+ end
16
+
17
+ should "convert h3 tag" do
18
+ assert_markdown "<h3>Foo</h3>", "\n### Foo ###\n"
19
+ end
20
+
21
+ should "convert h4 tag" do
22
+ assert_markdown "<h4>Foo</h4>", "\n#### Foo ####\n"
23
+ end
24
+
25
+ should "convert blockquote tag" do
26
+ assert_markdown "<blockquote><p>Hello\nGoodbye</p></blockquote>",
27
+ "> Hello\n> Goodbye\n"
28
+ end
29
+
30
+ # should "convert nested blockquote tag" do
31
+ # assert_markdown(
32
+ # "<blockquote><p>Hello</p>\n\n<blockquote><p>Nested</p></blockquote>\n\n<p>Goodbye</p></blockquote>",
33
+ # <<-EOM
34
+ # > Hello
35
+ # >
36
+ # > > Nested
37
+ # >
38
+ # > Goodbye
39
+ # EOM
40
+ # )
41
+ # end
42
+
43
+ should "convert unordered list" do
44
+ assert_markdown "<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul>\n",
45
+ "\n* one\n* two\n* three\n"
46
+ end
47
+
48
+ should "convert ordered list" do
49
+ assert_markdown "<ol>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ol>\n",
50
+ "\n1. one\n2. two\n3. three\n"
51
+ end
52
+
53
+ should "ignore empty unordered list items" do
54
+ assert_markdown "<ul>\n<li>one</li>\n<li></li>\n<li>three</li>\n</ul>\n",
55
+ "\n* one\n* three\n",
56
+ false
57
+ end
58
+
59
+ should "ignore empty ordered list items" do
60
+ assert_markdown "<ol>\n<li>one</li>\n<li></li>\n<li>three</li>\n</ol>\n",
61
+ "\n1. one\n3. three\n",
62
+ false
63
+ end
64
+
65
+ should "convert code blocks" do
66
+ assert_markdown "<pre><code>This is a code block\ncontinued\n</code></pre>",
67
+ "\n This is a code block\n continued\n\n"
68
+ end
69
+
70
+ context "anchors" do
71
+ should "convert <a> tags" do
72
+ assert_markdown "<p>Yes, magic helmet. And <a href=\"http://sample.com/\">I'll give you a sample</a>.</p>",
73
+ "\nYes, magic helmet. And [I'll give you a sample](http://sample.com/).\n"
74
+ end
75
+
76
+ context "<a> tags with titles" do
77
+ should "convert fq urls to reference-style" do
78
+ assert_markdown2 "<p>Yes, magic helmet. And <a href=\"http://sample.com/\" title=\"Fudd\">I'll give you a sample</a>.</p>",
79
+ "\nYes, magic helmet. And [I'll give you a sample][1].\n\n[1]: http://sample.com/ \"Fudd\"\n"
80
+ end
81
+
82
+ should "convert relative urls to reference-style" do
83
+ assert_markdown2 "<p>Yes, magic helmet. And <a href=\"/home\" title=\"Fudd\">I'll give you a sample</a>.</p>",
84
+ "\nYes, magic helmet. And [I'll give you a sample][1].\n\n[1]: /home \"Fudd\"\n"
85
+ end
86
+
87
+ should "convert multiple to appear in order at the end of the document" do
88
+ assert_markdown2 "<p>See <a href=\"/prefs\" title=\"Prefs\">Prefs</a> and <a href=\"/home\" title=\"Home\">Home</a>.</p>",
89
+ "\nSee [Prefs][1] and [Home][2].\n\n[1]: /prefs \"Prefs\"\n[2]: /home \"Home\"\n"
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def assert_markdown html, markdown, roundtrip=true
98
+ assert_equal(html, BlueCloth.new(markdown).to_html, "markdown roundtrip failed") if roundtrip
99
+ assert_equal(markdown, McBean.fragment(html).to_markdown, "fragment transformation failed")
100
+ assert_equal(Loofah::Helpers.remove_extraneous_whitespace("\n#{markdown}\n"),
101
+ McBean.document("<div>#{html}</div>").to_markdown, "document transformation failed")
102
+ end
103
+
104
+ def assert_markdown2 html, markdown, roundtrip=true
105
+ # note peskily absent newline at end of document. sigh.
106
+ assert_equal(html, BlueCloth.new(markdown).to_html, "markdown roundtrip failed") if roundtrip
107
+ assert_equal(markdown, McBean.fragment(html).to_markdown, "fragment transformation failed")
108
+ assert_equal(Loofah::Helpers.remove_extraneous_whitespace("\n#{markdown}"),
109
+ McBean.document("<div>#{html}</div>").to_markdown, "document transformation failed")
110
+ end
111
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class TestMcBean < Test::Unit::TestCase
4
+ context "class name" do
5
+ should "set McBean and Mcbean to be the same thing" do
6
+ assert McBean == Mcbean
7
+ end
8
+ end
9
+
10
+ context "cleanup" do
11
+ should "prune unsafe tags" do
12
+ result = McBean.fragment("<div>OK</div><script>BAD</script>").to_markdown
13
+ assert_match /OK/, result
14
+ assert_no_match /BAD/, result
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mcbean
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Mike Dalessio
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDPDCCAiSgAwIBAgIBADANBgkqhkiG9w0BAQUFADBEMRYwFAYDVQQDDA1taWtl
19
+ LmRhbGVzc2lvMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
20
+ FgNjb20wHhcNMDkwODExMDU0MjQ5WhcNMTAwODExMDU0MjQ5WjBEMRYwFAYDVQQD
21
+ DA1taWtlLmRhbGVzc2lvMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJ
22
+ k/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDANjr7
23
+ lZ1DKtK8YvNp+5kBzIpwrpClHRrosqo01qmWfGBxZckQUtrJUwGPxpzvIHVq1VKp
24
+ a9FXU/QWYek/1S0vhkOf9XGmFBnVCtbJhwGeyzsQFFSoQIfs2hd5gO0dSRpuKdi3
25
+ slfJAXzFKg1u/7OCVPgrY/mkdh34MzL5p0gSDzPt7vLPibctHg0GoepYT5Fh1tMQ
26
+ luzgrN0weTw/QoEWTMQcNk6CyUpzv0pOe7d0qEPQ9Lx7Lz64gIym3f0pKFpWLfME
27
+ l7PFLeR95zw2zsuZQwCR5ma5zjXD3mo2jk1mVqiI8qplOL1u30FU7hRhTV5n/Qe9
28
+ elDQoZW9Xz0R5JGDAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0G
29
+ A1UdDgQWBBRXWlUJZXcR1jkZPE24+mjUTCqNxjANBgkqhkiG9w0BAQUFAAOCAQEA
30
+ jDh5M41sg1MZKG1DXzQmo/IADeWRmXyb3EZaED9lhFFpoQqaralgpgmvuc0GswvO
31
+ QIZijh03tPQz8lgp1U1OFZod2ZwbEVTtVZpxs1ssjMraOA6KzlsNROH0XonIiy6j
32
+ r2Q0UF35ax8pvr3D5Y6AKzIW1F3aeiREylUDJlb/i1dPQ2PVK0yRrSQoK2epwM9E
33
+ zoczlHTTJc/tRvH5Up3Agcv9y+J0U9a1Af9NRsnHPVBdo2H32MsJ99x5NRDWJmJg
34
+ ohH37UR7njcc6j4fo22IwTqXaaXJdtVdAWjXP/xs5B3cPYSP6uqFnR46Jf86Iqj1
35
+ FlqnTjy13J3nD30uxy9a1g==
36
+ -----END CERTIFICATE-----
37
+
38
+ date: 2010-03-09 00:00:00 -05:00
39
+ default_executable:
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: loofah
43
+ prerelease: false
44
+ requirement: &id001 !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ segments:
49
+ - 0
50
+ - 4
51
+ - 7
52
+ version: 0.4.7
53
+ type: :runtime
54
+ version_requirements: *id001
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubyforge
57
+ prerelease: false
58
+ requirement: &id002 !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 2
64
+ - 0
65
+ - 3
66
+ version: 2.0.3
67
+ type: :development
68
+ version_requirements: *id002
69
+ - !ruby/object:Gem::Dependency
70
+ name: gemcutter
71
+ prerelease: false
72
+ requirement: &id003 !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ - 3
79
+ - 0
80
+ version: 0.3.0
81
+ type: :development
82
+ version_requirements: *id003
83
+ - !ruby/object:Gem::Dependency
84
+ name: shoulda
85
+ prerelease: false
86
+ requirement: &id004 !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 2
92
+ - 10
93
+ version: "2.10"
94
+ type: :development
95
+ version_requirements: *id004
96
+ - !ruby/object:Gem::Dependency
97
+ name: hoe
98
+ prerelease: false
99
+ requirement: &id005 !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 2
105
+ - 5
106
+ - 0
107
+ version: 2.5.0
108
+ type: :development
109
+ version_requirements: *id005
110
+ description: |-
111
+ "You can't teach a Sneetch."
112
+
113
+ McBean transforms HTML into Markdown with the help of Loofah and Nokogiri.
114
+
115
+ Its goal is to eventually be able to transform (with the help of other
116
+ relevant gems) documents from HTML to Markdown to Textile, and
117
+ anything in between. It will be the Sylvester McMonkey McBean of
118
+ markup, placing stars onto the bellies of all kinds of document
119
+ formats.
120
+ email:
121
+ - mike.dalessio@gmail.com
122
+ executables:
123
+ - mcbean
124
+ extensions: []
125
+
126
+ extra_rdoc_files:
127
+ - History.txt
128
+ - Manifest.txt
129
+ - CHANGELOG.rdoc
130
+ - README.rdoc
131
+ files:
132
+ - .autotest
133
+ - CHANGELOG.rdoc
134
+ - History.txt
135
+ - Manifest.txt
136
+ - README.rdoc
137
+ - Rakefile
138
+ - bin/mcbean
139
+ - lib/mcbean.rb
140
+ - lib/mcbean/markdown.rb
141
+ - markdown-syntax.html
142
+ - test/helper.rb
143
+ - test/test_markdown.rb
144
+ - test/test_mcbean.rb
145
+ has_rdoc: true
146
+ homepage: http://github.com/flavorjones/mcbean
147
+ licenses: []
148
+
149
+ post_install_message:
150
+ rdoc_options:
151
+ - --main
152
+ - README.rdoc
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ segments:
160
+ - 0
161
+ version: "0"
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ segments:
167
+ - 0
168
+ version: "0"
169
+ requirements: []
170
+
171
+ rubyforge_project: mcbean
172
+ rubygems_version: 1.3.6
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: "\"You can't teach a Sneetch.\" McBean transforms HTML into Markdown with the help of Loofah and Nokogiri"
176
+ test_files:
177
+ - test/test_mcbean.rb
178
+ - test/test_markdown.rb
@@ -0,0 +1 @@
1
+ .b*��U�7Q�� &���D�߮�*l��Ǜ�Rb���1�s13�;�l����Wt'�a߂r��]t�������'�ż��r��n�AJa�%�d���:��"I,R�ї��<�rX��������W��"r���j�AY��-�mc�J�&^%�+ܬG���>�Ƈ:v�� A(�