nwodkram 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/lib/nwodkram_parser.rb +14 -13
- data/nwodkram.gemspec +4 -3
- data/spec/nwodkram_spec.rb +12 -0
- data/spec/spec_helper.rb +2 -2
- metadata +11 -21
data/README.md
CHANGED
@@ -16,7 +16,7 @@ My use case was to migrate a blog from wordpress.com to something more civilised
|
|
16
16
|
## Supports ##
|
17
17
|
|
18
18
|
*tags*:
|
19
|
-
p, a, img, ul, ol, li, h1, h2, h3, em, strong
|
19
|
+
p, a, img, ul, ol, li, h1, h2, h3, em, strong, blockquote
|
20
20
|
|
21
21
|
*rubies*:
|
22
22
|
tested with MRI ruby 1.8.7 and 1.9.2 (preview1)
|
data/lib/nwodkram_parser.rb
CHANGED
@@ -2,16 +2,17 @@ class NwodkramParser < Nokogiri::XML::SAX::Document
|
|
2
2
|
|
3
3
|
attr_accessor :attr, :name
|
4
4
|
|
5
|
-
MARKDOWN = { 'p'
|
6
|
-
'a'
|
7
|
-
'img'
|
8
|
-
'li'
|
9
|
-
'code'
|
10
|
-
'h1'
|
11
|
-
'h2'
|
12
|
-
'h3'
|
13
|
-
'em'
|
14
|
-
'
|
5
|
+
MARKDOWN = { 'p' => ["" , "\n"],
|
6
|
+
'a' => ["[" , lambda { "](#{@attr['href']})" }],
|
7
|
+
'img' => [ lambda {"![#{@attr['title'] || @attr['alt']}](#{@attr['src']})"}, ""],
|
8
|
+
'li' => [ lambda { @parent == "ul" ? "* " : "1. " } , "\n"],
|
9
|
+
'code' => ["" , ""],
|
10
|
+
'h1' => ["# " , " #\n" ],
|
11
|
+
'h2' => ["## " , " ##\n" ],
|
12
|
+
'h3' => ["### " , " ###\n"],
|
13
|
+
'em' => ["*" , "*"],
|
14
|
+
'blockquote' => ["> " , ""],
|
15
|
+
'strong' => ["**" , "**"] }
|
15
16
|
|
16
17
|
def start_element(name,attributes = [])
|
17
18
|
@name, @attr = name, attr_hash(attributes)
|
@@ -20,6 +21,7 @@ class NwodkramParser < Nokogiri::XML::SAX::Document
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def end_element(name)
|
24
|
+
@name = name
|
23
25
|
MARKDOWN[name] ? print(local_value(MARKDOWN[name][1])) : print("")
|
24
26
|
end
|
25
27
|
|
@@ -32,11 +34,10 @@ class NwodkramParser < Nokogiri::XML::SAX::Document
|
|
32
34
|
}
|
33
35
|
when "img"
|
34
36
|
print "" # image doesn't contain any children, normally
|
35
|
-
when 'p','h1','h2','h3', 'li', 'ul','ol'
|
37
|
+
when 'p','h1','h2','h3', 'li', 'ul','ol','blockquote'
|
36
38
|
print string.chomp
|
37
39
|
else
|
38
|
-
|
39
|
-
string[0] == 10 ? print("\n") : print(string)
|
40
|
+
print string
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
data/nwodkram.gemspec
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'nwodkram'
|
3
|
-
s.version = '0.
|
4
|
-
s.date = '2010-05-
|
3
|
+
s.version = '0.3'
|
4
|
+
s.date = '2010-05-12'
|
5
5
|
|
6
6
|
s.description = 'Convert html into markdown'
|
7
|
-
s.summary = 'Convert html into markdown'
|
7
|
+
s.summary = 'Convert html into markdown - this might be useful when going from a traditional blog to a more text-based blog.'
|
8
8
|
|
9
9
|
s.authors = ['Elise Huard']
|
10
10
|
s.email = 'nwodkram@elisehuard.be'
|
11
|
+
s.homepage = 'http://github.com/elisehuard/nwodkram'
|
11
12
|
|
12
13
|
s.files = %w[
|
13
14
|
README.md
|
data/spec/nwodkram_spec.rb
CHANGED
@@ -64,6 +64,18 @@ describe "converting html to markdown" do
|
|
64
64
|
html.to_markdown.should == markdown
|
65
65
|
end
|
66
66
|
|
67
|
+
it "should convert a blockquote" do
|
68
|
+
markdown = "> boo !\n\n that was scary\n"
|
69
|
+
html = markdown.to_html
|
70
|
+
html.to_markdown.should == markdown
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should convert a text with several bits of code" do
|
74
|
+
html = File.open(File.expand_path(File.dirname(__FILE__) + "/code_test.txt")).read
|
75
|
+
markdown = html.to_markdown
|
76
|
+
markdown.to_html.should == html
|
77
|
+
end
|
78
|
+
|
67
79
|
# the ultimate test: convert the readme
|
68
80
|
it "should convert a whole text" do
|
69
81
|
markdown = File.open(File.expand_path(File.dirname(__FILE__) + "/../README.md")).read
|
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,7 @@ require 'rubygems'
|
|
5
5
|
require 'spec'
|
6
6
|
require 'nwodkram'
|
7
7
|
require 'bluecloth' # markdown converter to test against
|
8
|
-
require '
|
8
|
+
require 'spec/matchers'
|
9
9
|
|
10
10
|
Spec::Runner.configure do |config|
|
11
11
|
end
|
@@ -17,7 +17,7 @@ class String
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
Spec::Matchers.define :convert_to_html_and_back do
|
21
21
|
match do |markdown|
|
22
22
|
html = markdown.to_html
|
23
23
|
html.to_markdown == markdown
|
metadata
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nwodkram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
version: "0.2"
|
4
|
+
version: "0.3"
|
9
5
|
platform: ruby
|
10
6
|
authors:
|
11
7
|
- Elise Huard
|
@@ -13,23 +9,19 @@ autorequire:
|
|
13
9
|
bindir: bin
|
14
10
|
cert_chain: []
|
15
11
|
|
16
|
-
date: 2010-05-
|
12
|
+
date: 2010-05-12 00:00:00 +02:00
|
17
13
|
default_executable:
|
18
14
|
dependencies:
|
19
15
|
- !ruby/object:Gem::Dependency
|
20
16
|
name: nokogiri
|
21
|
-
|
22
|
-
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
20
|
requirements:
|
24
21
|
- - ">="
|
25
22
|
- !ruby/object:Gem::Version
|
26
|
-
segments:
|
27
|
-
- 1
|
28
|
-
- 4
|
29
|
-
- 1
|
30
23
|
version: 1.4.1
|
31
|
-
|
32
|
-
version_requirements: *id001
|
24
|
+
version:
|
33
25
|
description: Convert html into markdown
|
34
26
|
email: nwodkram@elisehuard.be
|
35
27
|
executables: []
|
@@ -49,7 +41,7 @@ files:
|
|
49
41
|
- spec/rcov.opts
|
50
42
|
- spec/nwodkram_spec.rb
|
51
43
|
has_rdoc: true
|
52
|
-
homepage:
|
44
|
+
homepage: http://github.com/elisehuard/nwodkram
|
53
45
|
licenses: []
|
54
46
|
|
55
47
|
post_install_message:
|
@@ -61,22 +53,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
53
|
requirements:
|
62
54
|
- - ">="
|
63
55
|
- !ruby/object:Gem::Version
|
64
|
-
segments:
|
65
|
-
- 0
|
66
56
|
version: "0"
|
57
|
+
version:
|
67
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
59
|
requirements:
|
69
60
|
- - ">="
|
70
61
|
- !ruby/object:Gem::Version
|
71
|
-
segments:
|
72
|
-
- 0
|
73
62
|
version: "0"
|
63
|
+
version:
|
74
64
|
requirements: []
|
75
65
|
|
76
66
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.3.
|
67
|
+
rubygems_version: 1.3.5
|
78
68
|
signing_key:
|
79
69
|
specification_version: 3
|
80
|
-
summary: Convert html into markdown
|
70
|
+
summary: Convert html into markdown - this might be useful when going from a traditional blog to a more text-based blog.
|
81
71
|
test_files:
|
82
72
|
- spec/nwodkram_spec.rb
|