markitdown 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/markitdown.rb +11 -5
- data/lib/markitdown/version.rb +1 -1
- data/spec/doc.html +9 -0
- data/spec/doc.markdown +9 -0
- data/spec/nesting_spec.rb +2 -0
- data/spec/tag_spec.rb +11 -2
- metadata +4 -4
data/lib/markitdown.rb
CHANGED
@@ -20,6 +20,7 @@ module Markitdown
|
|
20
20
|
after = nil
|
21
21
|
states.unshift node.name.downcase
|
22
22
|
pre = prefix(states)
|
23
|
+
recurse = true
|
23
24
|
strip_contents = false
|
24
25
|
case node.name
|
25
26
|
when "head"
|
@@ -82,7 +83,7 @@ module Markitdown
|
|
82
83
|
when "blockquote"
|
83
84
|
results << "\n\n"
|
84
85
|
results << pre
|
85
|
-
after = "\n"
|
86
|
+
after = "\n\n"
|
86
87
|
when "ol"
|
87
88
|
unless self.nested_list?(states)
|
88
89
|
results << self.newline(pre, nil)
|
@@ -108,11 +109,16 @@ module Markitdown
|
|
108
109
|
results << ") "
|
109
110
|
when "text"
|
110
111
|
results << node.text.strip.gsub("\n","").gsub(/ {2,}/," ")
|
112
|
+
when "code"
|
113
|
+
results << " `#{node.text}` "
|
114
|
+
recurse = false
|
111
115
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
+
if recurse
|
117
|
+
node.children.each do |child|
|
118
|
+
contents = self.parse_node(child, states)
|
119
|
+
contents = contents.flatten.compact.join.strip if strip_content
|
120
|
+
results << contents
|
121
|
+
end
|
116
122
|
end
|
117
123
|
results << after
|
118
124
|
states.shift
|
data/lib/markitdown/version.rb
CHANGED
data/spec/doc.html
CHANGED
data/spec/doc.markdown
CHANGED
data/spec/nesting_spec.rb
CHANGED
@@ -101,6 +101,7 @@ describe Markitdown do
|
|
101
101
|
> This is a quote with a list
|
102
102
|
> * item 1
|
103
103
|
> * item 2
|
104
|
+
|
104
105
|
"
|
105
106
|
end
|
106
107
|
end
|
@@ -128,6 +129,7 @@ describe Markitdown do
|
|
128
129
|
> 1. item [2.1](http://www.google.com)
|
129
130
|
> 1. item 2.2
|
130
131
|
> * item 1.2
|
132
|
+
|
131
133
|
"
|
132
134
|
end
|
133
135
|
end
|
data/spec/tag_spec.rb
CHANGED
@@ -199,7 +199,7 @@ describe Markitdown do
|
|
199
199
|
let(:html) { "<blockquote>this is a block quote</blockquote>" }
|
200
200
|
|
201
201
|
it "should return valid markdown" do
|
202
|
-
Markitdown.from_html(html).should == "\n\n > this is a block quote\n"
|
202
|
+
Markitdown.from_html(html).should == "\n\n > this is a block quote\n\n"
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
@@ -211,7 +211,16 @@ describe Markitdown do
|
|
211
211
|
</blockquote>" }
|
212
212
|
|
213
213
|
it "should return valid markdown" do
|
214
|
-
Markitdown.from_html(html).should == "\n\n > line 1 line 2 line 3\n"
|
214
|
+
Markitdown.from_html(html).should == "\n\n > line 1 line 2 line 3\n\n"
|
215
215
|
end
|
216
216
|
end
|
217
|
+
|
218
|
+
context "When parsing an CODE element" do
|
219
|
+
let(:html) { "<code>code block</code>" }
|
220
|
+
|
221
|
+
it "should return valid markdown" do
|
222
|
+
Markitdown.from_html(html).should == " `code block` "
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
217
226
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markitdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -96,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
segments:
|
98
98
|
- 0
|
99
|
-
hash:
|
99
|
+
hash: 966018070183228939
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
none: false
|
102
102
|
requirements:
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
segments:
|
107
107
|
- 0
|
108
|
-
hash:
|
108
|
+
hash: 966018070183228939
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
111
|
rubygems_version: 1.8.24
|