upmark 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,9 +8,9 @@ module Upmark
8
8
  # http://www.w3.org/TR/2000/REC-xml-20001006
9
9
  #
10
10
  class XML < Parslet::Parser
11
- root(:content)
11
+ root(:node)
12
12
 
13
- rule(:content) {
13
+ rule(:node) {
14
14
  (
15
15
  element.as(:element) |
16
16
  text.as(:text)
@@ -20,7 +20,7 @@ module Upmark
20
20
  rule(:element) {
21
21
  (
22
22
  start_tag.as(:start_tag) >>
23
- content.as(:content) >>
23
+ node.as(:children) >>
24
24
  end_tag.as(:end_tag)
25
25
  ) |
26
26
  empty_tag.as(:empty_tag)
@@ -0,0 +1,19 @@
1
+ module Upmark
2
+ module Transform
3
+ # A transform class which marks all elements in a subtree as ignored.
4
+ class Ignore < Parslet::Transform
5
+ include TransformHelpers
6
+
7
+ element(:*) do |element|
8
+ {
9
+ element: {
10
+ name: element[:name],
11
+ attributes: element[:attributes],
12
+ children: element[:children],
13
+ ignore: true
14
+ }
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,55 +5,37 @@ module Upmark
5
5
  # Transforms an abstract syntax tree (AST) into a Markdown document.
6
6
  #
7
7
  class Markdown < Parslet::Transform
8
- def self.tag(tag_name)
9
- tag_name = tag_name.to_s.downcase
10
- {
11
- tag: {name: tag_name, attributes: subtree(:attributes)},
12
- content: sequence(:values)
13
- }
14
- end
15
-
16
- def self.map_attributes_subtree(ast)
17
- ast.inject({}) do |hash, attribute|
18
- hash[attribute[:name].to_sym] = attribute[:value]
19
- hash
20
- end
21
- end
22
-
23
- rule(element: subtree(:values)) { values }
8
+ include TransformHelpers
24
9
 
25
10
  rule(text: simple(:value)) { value.to_s }
26
11
 
27
- rule(tag(:p)) { "#{values.join}\n\n" }
28
- rule(tag(:strong)) { "**#{values.join}**" }
29
- rule(tag(:em)) { "*#{values.join}*" }
30
- rule(tag(:li)) { "#{values.join}" }
31
- rule(tag(:h1)) { "# #{values.join}" }
32
- rule(tag(:h2)) { "## #{values.join}" }
33
- rule(tag(:h3)) { "### #{values.join}" }
34
- rule(tag(:br)) { "\n" }
12
+ element(:p) {|element| "#{element[:children].join}\n\n" }
13
+ element(:h1) {|element| "# #{element[:children].join}" }
14
+ element(:h2) {|element| "## #{element[:children].join}" }
15
+ element(:h3) {|element| "### #{element[:children].join}" }
16
+ element(:li) {|element| "#{element[:children].join}" }
35
17
 
36
- rule(tag(:ul)) do |dictionary|
37
- values = dictionary[:values].map {|value| value.strip != "" ? value : nil }.compact
38
- values.map {|value| "* #{value}\n" }
18
+ element(:ul) do |element|
19
+ children = element[:children].map {|value| value.strip != "" ? value : nil }.compact
20
+ children.map {|value| "* #{value}\n" }
39
21
  end
40
22
 
41
- rule(tag(:ol)) do |dictionary|
42
- values = dictionary[:values].map {|value| value.strip != "" ? value : nil }.compact
43
- values.map_with_index {|value, i| "#{i + 1}. #{value}\n" }
23
+ element(:ol) do |element|
24
+ children = element[:children].map {|value| value.strip != "" ? value : nil }.compact
25
+ children.map_with_index {|value, i| "#{i + 1}. #{value}\n" }
44
26
  end
45
27
 
46
- rule(tag(:a)) do |dictionary|
47
- attributes = map_attributes_subtree(dictionary[:attributes])
28
+ element(:a) do |element|
29
+ attributes = map_attributes_subtree(element[:attributes])
48
30
  href = attributes[:href]
49
31
  title = attributes[:title]
50
- values = dictionary[:values].join
32
+ children = element[:children].join
51
33
 
52
- %Q{[#{values}](#{href} "#{title}")}
34
+ %Q{[#{children}](#{href} "#{title}")}
53
35
  end
54
36
 
55
- rule(tag(:img)) do |dictionary|
56
- attributes = map_attributes_subtree(dictionary[:attributes])
37
+ element(:img) do |element|
38
+ attributes = map_attributes_subtree(element[:attributes])
57
39
  href = attributes[:src]
58
40
  title = attributes[:title]
59
41
  alt_text = attributes[:alt]
@@ -61,14 +43,23 @@ module Upmark
61
43
  %Q{![#{alt_text}](#{href} "#{title}")}
62
44
  end
63
45
 
64
- # Catch-all rule to pass all tags through.
46
+ element(:b, :strong) {|element| "**#{element[:children].join}**" }
47
+ element(:i, :em) {|element| "*#{element[:children].join}*" }
48
+
49
+ element(:br) { "\n" }
50
+
51
+ # Pass all unmatched elements through.
65
52
  rule(
66
- tag: {name: simple(:tag_name), attributes: subtree(:attributes)},
67
- content: sequence(:values)
68
- ) do |dictionary|
69
- attributes = map_attributes_subtree(dictionary[:attributes])
70
- values = dictionary[:values].join
71
- tag_name = dictionary[:tag_name]
53
+ element: {
54
+ name: simple(:name),
55
+ attributes: subtree(:attributes),
56
+ children: sequence(:children),
57
+ ignore: simple(:ignore)
58
+ }
59
+ ) do |element|
60
+ attributes = map_attributes_subtree(element[:attributes])
61
+ children = element[:children].join
62
+ name = element[:name]
72
63
 
73
64
  attributes_list =
74
65
  if attributes.any?
@@ -77,7 +68,11 @@ module Upmark
77
68
  ""
78
69
  end
79
70
 
80
- %Q{<#{tag_name}#{attributes_list}>#{values}</#{tag_name}>}
71
+ if children.empty?
72
+ %Q{<#{name}#{attributes_list} />}
73
+ else
74
+ %Q{<#{name}#{attributes_list}>#{children}</#{name}>}
75
+ end
81
76
  end
82
77
  end
83
78
  end
@@ -0,0 +1,20 @@
1
+ require "upmark/transform/ignore"
2
+
3
+ module Upmark
4
+ module Transform
5
+ class PassThrough < Parslet::Transform
6
+ include TransformHelpers
7
+
8
+ element(:div, :table, :pre) do |element|
9
+ {
10
+ element: {
11
+ name: element[:name],
12
+ attributes: element[:attributes],
13
+ children: Ignore.new.apply(element[:children]),
14
+ ignore: true
15
+ }
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,23 +1,36 @@
1
1
  module Upmark
2
2
  module Transform
3
+ # A preprocess transform which normalises start/end/empty tags into the same structure.
3
4
  class Preprocess < Parslet::Transform
4
5
  rule(
5
- start_tag: {name: simple(:tag_name), attributes: subtree(:attributes)},
6
- end_tag: {name: simple(:tag_name)},
7
- content: subtree(:values)
6
+ element: {
7
+ start_tag: {name: simple(:name), attributes: subtree(:attributes)},
8
+ end_tag: {name: simple(:name)},
9
+ children: subtree(:children)
10
+ }
8
11
  ) do
9
12
  {
10
- tag: {name: tag_name, attributes: attributes},
11
- content: values
13
+ element: {
14
+ name: name,
15
+ attributes: attributes,
16
+ children: children,
17
+ ignore: false
18
+ }
12
19
  }
13
20
  end
14
21
 
15
22
  rule(
16
- empty_tag: {name: simple(:tag_name), attributes: subtree(:attributes)}
23
+ element: {
24
+ empty_tag: {name: simple(:name), attributes: subtree(:attributes)}
25
+ }
17
26
  ) do
18
27
  {
19
- tag: {name: tag_name, attributes: attributes},
20
- content: []
28
+ element: {
29
+ name: name,
30
+ attributes: attributes,
31
+ children: [],
32
+ ignore: false
33
+ }
21
34
  }
22
35
  end
23
36
  end
@@ -0,0 +1,35 @@
1
+ module Upmark
2
+ module TransformHelpers
3
+ def self.included(base)
4
+ base.send :extend, ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def element(*names, &block)
9
+ names.each do |name|
10
+ name = name.to_s.downcase
11
+ rule(
12
+ {
13
+ element: {
14
+ name: (name != "*" ? name : simple(:name)),
15
+ attributes: subtree(:attributes),
16
+ children: subtree(:children),
17
+ ignore: false
18
+ }
19
+ }
20
+ ) do |element|
21
+ element[:name] ||= name
22
+ block.call(element)
23
+ end
24
+ end
25
+ end
26
+
27
+ def map_attributes_subtree(ast)
28
+ ast.inject({}) do |hash, attribute|
29
+ hash[attribute[:name].to_sym] = attribute[:value]
30
+ hash
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Upmark
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/upmark.rb CHANGED
@@ -3,18 +3,22 @@ require "parslet"
3
3
  require "core_ext/array"
4
4
 
5
5
  require "upmark/parser/xml"
6
+ require 'upmark/transform_helpers'
6
7
  require "upmark/transform/markdown"
8
+ require "upmark/transform/pass_through"
7
9
  require "upmark/transform/preprocess"
8
10
  require "upmark/version"
9
11
 
10
12
  module Upmark
11
13
  def self.convert(html)
12
- xml = Parser::XML.new
13
- preprocess = Transform::Preprocess.new
14
- markdown = Transform::Markdown.new
14
+ xml = Parser::XML.new
15
+ preprocess = Transform::Preprocess.new
16
+ pass_through = Transform::PassThrough.new
17
+ markdown = Transform::Markdown.new
15
18
 
16
19
  ast = xml.parse(html.strip)
17
20
  ast = preprocess.apply(ast)
21
+ ast = pass_through.apply(ast)
18
22
  ast = markdown.apply(ast)
19
23
 
20
24
  # The result is either a String or an Array.
@@ -3,17 +3,44 @@ require "spec_helper"
3
3
  describe Upmark, ".convert" do
4
4
  subject { Upmark.convert(html) }
5
5
 
6
- let(:html) { <<-HTML.strip }
7
- <h1>messenger bag skateboard</h1>
6
+ context "<a>" do
7
+ let(:html) { <<-HTML.strip }
8
+ <p><a href="http://helvetica.com/" title="art party organic">messenger <strong>bag</strong> skateboard</a></p>
9
+ HTML
8
10
 
9
- <p>messenger bag skateboard</p>
11
+ it { should == <<-MD.strip }
12
+ [messenger **bag** skateboard](http://helvetica.com/ "art party organic")
13
+ MD
14
+ end
10
15
 
11
- <p>messenger <em>bag</em> <strong>skateboard</strong></p>
16
+ context "<img>" do
17
+ let(:html) { <<-HTML.strip }
18
+ <img src="http://helvetica.com/image.gif" title="art party organic" alt="messenger bag skateboard" />
12
19
 
13
- <p><a href="http://helvetica.com/" title="art party organic">messenger <strong>bag</strong> skateboard</a></p>
20
+ HTML
14
21
 
15
- <img src="http://helvetica.com/image.gif" title="art party organic" alt="messenger bag skateboard" />
22
+ it { should == <<-MD.strip }
23
+ ![messenger bag skateboard](http://helvetica.com/image.gif "art party organic")
24
+ MD
25
+ end
16
26
 
27
+ context "<p>" do
28
+ let(:html) { <<-HTML.strip }
29
+ <p>messenger <strong>bag</strong> skateboard</p>
30
+
31
+ <p>art party<br />organic</p>
32
+ HTML
33
+
34
+ it { should == <<-MD.strip }
35
+ messenger **bag** skateboard
36
+
37
+ art party
38
+ organic
39
+ MD
40
+ end
41
+
42
+ context "<ul>" do
43
+ let(:html) { <<-HTML.strip }
17
44
  <ul>
18
45
  <li>messenger</li>
19
46
  <li><strong>bag</strong></li>
@@ -25,7 +52,23 @@ describe Upmark, ".convert" do
25
52
  <li><p><strong>bag</strong></p></li>
26
53
  <li><p>skateboard</p></li>
27
54
  </ul>
55
+ HTML
56
+
57
+ it { should == <<-MD.strip }
58
+ * messenger
59
+ * **bag**
60
+ * skateboard
61
+
62
+ * messenger
28
63
 
64
+ * **bag**
65
+
66
+ * skateboard
67
+ MD
68
+ end
69
+
70
+ context "<ol>" do
71
+ let(:html) { <<-HTML.strip }
29
72
  <ol>
30
73
  <li>messenger</li>
31
74
  <li><strong>bag</strong></li>
@@ -37,32 +80,9 @@ describe Upmark, ".convert" do
37
80
  <li><p><strong>bag</strong></p></li>
38
81
  <li><p>skateboard</p></li>
39
82
  </ol>
83
+ HTML
40
84
 
41
- <div>messenger <strong>bag</strong> skateboard</div>
42
- <div id="tofu" class="art party">messenger <strong>bag</strong> skateboard</div>
43
- HTML
44
-
45
- it { should == <<-MD.strip }
46
- # messenger bag skateboard
47
-
48
- messenger bag skateboard
49
-
50
- messenger *bag* **skateboard**
51
-
52
- [messenger **bag** skateboard](http://helvetica.com/ "art party organic")
53
-
54
- ![messenger bag skateboard](http://helvetica.com/image.gif "art party organic")
55
-
56
- * messenger
57
- * **bag**
58
- * skateboard
59
-
60
- * messenger
61
-
62
- * **bag**
63
-
64
- * skateboard
65
-
85
+ it { should == <<-MD.strip }
66
86
  1. messenger
67
87
  2. **bag**
68
88
  3. skateboard
@@ -72,8 +92,90 @@ messenger *bag* **skateboard**
72
92
  2. **bag**
73
93
 
74
94
  3. skateboard
95
+ MD
96
+ end
97
+
98
+ context "<h1>" do
99
+ let(:html) { <<-HTML.strip }
100
+ <h1>messenger bag skateboard</h1>
101
+ <h2>messenger bag skateboard</h2>
102
+ <h3>messenger bag skateboard</h3>
103
+ HTML
104
+
105
+ it { should == <<-MD.strip }
106
+ # messenger bag skateboard
107
+ ## messenger bag skateboard
108
+ ### messenger bag skateboard
109
+ MD
110
+ end
111
+
112
+ context "<div>" do
113
+ let(:html) { <<-HTML.strip }
114
+ <div>messenger <strong>bag</strong> skateboard</div>
115
+ <div id="tofu" class="art party">messenger <strong>bag</strong> skateboard</div>
116
+ HTML
75
117
 
76
- <div>messenger **bag** skateboard</div>
77
- <div id="tofu" class="art party">messenger **bag** skateboard</div>
78
- MD
118
+ it { should == <<-MD.strip }
119
+ <div>messenger <strong>bag</strong> skateboard</div>
120
+ <div id="tofu" class="art party">messenger <strong>bag</strong> skateboard</div>
121
+ MD
122
+ end
123
+
124
+ context "<table>" do
125
+ let(:html) { <<-HTML.strip }
126
+ <table>
127
+ <tr>
128
+ <td>messenger</td>
129
+ </tr>
130
+ <tr>
131
+ <td><strong>bag</strong></td>
132
+ </tr>
133
+ <tr>
134
+ <td>skateboard</td>
135
+ </tr>
136
+ </table>
137
+ HTML
138
+
139
+ it { should == <<-MD.strip }
140
+ <table>
141
+ <tr>
142
+ <td>messenger</td>
143
+ </tr>
144
+ <tr>
145
+ <td><strong>bag</strong></td>
146
+ </tr>
147
+ <tr>
148
+ <td>skateboard</td>
149
+ </tr>
150
+ </table>
151
+ MD
152
+ end
153
+
154
+ context "<pre>" do
155
+ let(:html) { <<-HTML.strip }
156
+ <pre>
157
+ <code>
158
+ messenger bag skateboard
159
+ </code>
160
+ </pre>
161
+ HTML
162
+
163
+ it { should == <<-MD.strip }
164
+ <pre>
165
+ <code>
166
+ messenger bag skateboard
167
+ </code>
168
+ </pre>
169
+ MD
170
+ end
171
+
172
+ context "<span>" do
173
+ let(:html) { <<-HTML.strip }
174
+ <span>messenger <strong>bag</strong> skateboard</span>
175
+ HTML
176
+
177
+ it { should == <<-MD.strip }
178
+ <span>messenger **bag** skateboard</span>
179
+ MD
180
+ end
79
181
  end
@@ -3,8 +3,8 @@ require "spec_helper"
3
3
  describe Upmark::Parser::XML do
4
4
  let(:parser) { Upmark::Parser::XML.new }
5
5
 
6
- context "#content" do
7
- subject { parser.content }
6
+ context "#node" do
7
+ subject { parser.node }
8
8
 
9
9
  it { should parse "" }
10
10
  it { should parse "messenger bag skateboard" }
@@ -58,6 +58,7 @@ describe Upmark::Parser::XML do
58
58
  context "#empty_tag" do
59
59
  subject { parser.empty_tag }
60
60
 
61
+ it { should parse %q{<tofu />} }
61
62
  it { should parse %q{<tofu art="party" />} }
62
63
  it { should parse %q{<tofu art="party" synth="letterpress" />} }
63
64
  it { should_not parse "<tofu>" }
@@ -91,7 +92,7 @@ describe Upmark::Parser::XML do
91
92
  context "#parse" do
92
93
  subject { parser.parse(html) }
93
94
 
94
- context "single element" do
95
+ context "single tag" do
95
96
  let(:html) { "<p>messenger</p>" }
96
97
 
97
98
  it do
@@ -100,14 +101,28 @@ describe Upmark::Parser::XML do
100
101
  element: {
101
102
  start_tag: {name: "p", attributes: []},
102
103
  end_tag: {name: "p"},
103
- content: [{text: "messenger"}]
104
+ children: [{text: "messenger"}]
104
105
  }
105
106
  }
106
107
  ]
107
108
  end
108
109
  end
109
110
 
110
- context "single element with attributes" do
111
+ context "empty tag" do
112
+ let(:html) { "<br />" }
113
+
114
+ it do
115
+ should == [
116
+ {
117
+ element: {
118
+ empty_tag: {name: "br", attributes: []}
119
+ }
120
+ }
121
+ ]
122
+ end
123
+ end
124
+
125
+ context "single tag with attributes" do
111
126
  let(:html) { %q{<a href="http://helvetica.com/" title="art party organic">messenger bag skateboard</a>} }
112
127
 
113
128
  it do
@@ -121,15 +136,15 @@ describe Upmark::Parser::XML do
121
136
  {name: "title", value: "art party organic"}
122
137
  ]
123
138
  },
124
- end_tag: {name: "a"},
125
- content: [{text: "messenger bag skateboard"}]
139
+ end_tag: {name: "a"},
140
+ children: [{text: "messenger bag skateboard"}]
126
141
  }
127
142
  }
128
143
  ]
129
144
  end
130
145
  end
131
146
 
132
- context "multiple inline elements" do
147
+ context "multiple inline tags" do
133
148
  let(:html) { "<p>messenger</p><p>bag</p><p>skateboard</p>" }
134
149
 
135
150
  it do
@@ -138,26 +153,26 @@ describe Upmark::Parser::XML do
138
153
  element: {
139
154
  start_tag: {name: "p", attributes: []},
140
155
  end_tag: {name: "p"},
141
- content: [{text: "messenger"}]
156
+ children: [{text: "messenger"}]
142
157
  }
143
158
  }, {
144
159
  element: {
145
160
  start_tag: {name: "p", attributes: []},
146
161
  end_tag: {name: "p"},
147
- content: [{text: "bag"}]
162
+ children: [{text: "bag"}]
148
163
  }
149
164
  }, {
150
165
  element: {
151
166
  start_tag: {name: "p", attributes: []},
152
167
  end_tag: {name: "p"},
153
- content: [{text: "skateboard"}]
168
+ children: [{text: "skateboard"}]
154
169
  }
155
170
  }
156
171
  ]
157
172
  end
158
173
  end
159
174
 
160
- context "multiple elements" do
175
+ context "multiple tags" do
161
176
  let(:html) { "<p>messenger</p>\n<p>bag</p>\n<p>skateboard</p>" }
162
177
 
163
178
  it do
@@ -166,7 +181,7 @@ describe Upmark::Parser::XML do
166
181
  element: {
167
182
  start_tag: {name: "p", attributes: []},
168
183
  end_tag: {name: "p"},
169
- content: [{text: "messenger"}]
184
+ children: [{text: "messenger"}]
170
185
  }
171
186
  }, {
172
187
  text: "\n"
@@ -174,7 +189,7 @@ describe Upmark::Parser::XML do
174
189
  element: {
175
190
  start_tag: {name: "p", attributes: []},
176
191
  end_tag: {name: "p"},
177
- content: [{text: "bag"}]
192
+ children: [{text: "bag"}]
178
193
  }
179
194
  }, {
180
195
  text: "\n"
@@ -182,14 +197,14 @@ describe Upmark::Parser::XML do
182
197
  element: {
183
198
  start_tag: {name: "p", attributes: []},
184
199
  end_tag: {name: "p"},
185
- content: [{text: "skateboard"}]
200
+ children: [{text: "skateboard"}]
186
201
  }
187
202
  }
188
203
  ]
189
204
  end
190
205
  end
191
206
 
192
- context "nested elements" do
207
+ context "nested tags" do
193
208
  let(:html) { "<p>messenger <strong>bag</strong> skateboard</p>" }
194
209
 
195
210
  it do
@@ -198,12 +213,13 @@ describe Upmark::Parser::XML do
198
213
  element: {
199
214
  start_tag: {name: "p", attributes: []},
200
215
  end_tag: {name: "p"},
201
- content: [
202
- {text: "messenger "},
216
+ children: [
203
217
  {
218
+ text: "messenger "
219
+ }, {
204
220
  element: {
205
221
  start_tag: {name: "strong", attributes: []},
206
- content: [{text: "bag"}],
222
+ children: [{text: "bag"}],
207
223
  end_tag: {name: "strong"}
208
224
  }
209
225
  }, {
@@ -7,13 +7,15 @@ describe Upmark::Transform::Markdown do
7
7
  subject { transform.apply(ast) }
8
8
 
9
9
  context "<p>" do
10
- context "single element" do
10
+ context "single tag" do
11
11
  let(:ast) do
12
12
  [
13
13
  {
14
14
  element: {
15
- tag: {name: "p", attributes: []},
16
- content: [{text: "messenger bag skateboard"}]
15
+ name: "p",
16
+ attributes: [],
17
+ children: [{text: "messenger bag skateboard"}],
18
+ ignore: false
17
19
  }
18
20
  }
19
21
  ]
@@ -22,23 +24,29 @@ describe Upmark::Transform::Markdown do
22
24
  it { should == ["messenger bag skateboard\n\n"] }
23
25
  end
24
26
 
25
- context "multiple elements" do
27
+ context "multiple tags" do
26
28
  let(:ast) do
27
29
  [
28
30
  {
29
31
  element: {
30
- tag: {name: "p", attributes: []},
31
- content: [{text: "messenger"}]
32
+ name: "p",
33
+ attributes: [],
34
+ children: [{text: "messenger"}],
35
+ ignore: false
32
36
  }
33
37
  }, {
34
38
  element: {
35
- tag: {name: "p", attributes: []},
36
- content: [{text: "bag"}]
39
+ name: "p",
40
+ attributes: [],
41
+ children: [{text: "bag"}],
42
+ ignore: false
37
43
  }
38
44
  }, {
39
45
  element: {
40
- tag: {name: "p", attributes: []},
41
- content: [{text: "skateboard"}]
46
+ name: "p",
47
+ attributes: [],
48
+ children: [{text: "skateboard"}],
49
+ ignore: false
42
50
  }
43
51
  }
44
52
  ]
@@ -49,19 +57,18 @@ describe Upmark::Transform::Markdown do
49
57
  end
50
58
 
51
59
  context "<a>" do
52
- context "single element" do
60
+ context "single tag" do
53
61
  let(:ast) do
54
62
  [
55
63
  {
56
64
  element: {
57
- tag: {
58
- name: "a",
59
- attributes: [
60
- {name: "href", value: "http://helvetica.com/"},
61
- {name: "title", value: "art party organic"}
62
- ]
63
- },
64
- content: [{text: "messenger bag skateboard"}]
65
+ name: "a",
66
+ attributes: [
67
+ {name: "href", value: "http://helvetica.com/"},
68
+ {name: "title", value: "art party organic"}
69
+ ],
70
+ children: [{text: "messenger bag skateboard"}],
71
+ ignore: false
65
72
  }
66
73
  }
67
74
  ]
@@ -72,20 +79,19 @@ describe Upmark::Transform::Markdown do
72
79
  end
73
80
 
74
81
  context "<img>" do
75
- context "empty element" do
82
+ context "empty tag" do
76
83
  let(:ast) do
77
84
  [
78
85
  {
79
86
  element: {
80
- tag: {
81
- name: "img",
82
- attributes: [
83
- {name: "src", value: "http://helvetica.com/image.gif"},
84
- {name: "title", value: "art party organic"},
85
- {name: "alt", value: "messenger bag skateboard"}
86
- ]
87
- },
88
- content: []
87
+ name: "img",
88
+ attributes: [
89
+ {name: "src", value: "http://helvetica.com/image.gif"},
90
+ {name: "title", value: "art party organic"},
91
+ {name: "alt", value: "messenger bag skateboard"}
92
+ ],
93
+ children: [],
94
+ ignore: false
89
95
  }
90
96
  }
91
97
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-23 00:00:00.000000000 Z
13
+ date: 2011-09-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &70160857809560 !ruby/object:Gem::Requirement
17
+ requirement: &70218294771840 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70160857809560
25
+ version_requirements: *70218294771840
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: parslet
28
- requirement: &70160857808520 !ruby/object:Gem::Requirement
28
+ requirement: &70218294771320 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70160857808520
36
+ version_requirements: *70218294771320
37
37
  description: Upmark has the skills to convert your HTML to Markdown.
38
38
  email: dev@theconversation.edu.au
39
39
  executables:
@@ -51,8 +51,11 @@ files:
51
51
  - lib/core_ext/array.rb
52
52
  - lib/upmark.rb
53
53
  - lib/upmark/parser/xml.rb
54
+ - lib/upmark/transform/ignore.rb
54
55
  - lib/upmark/transform/markdown.rb
56
+ - lib/upmark/transform/pass_through.rb
55
57
  - lib/upmark/transform/preprocess.rb
58
+ - lib/upmark/transform_helpers.rb
56
59
  - lib/upmark/version.rb
57
60
  - spec/acceptance/upmark_spec.rb
58
61
  - spec/spec_helper.rb