reverse_markdown 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac5927d92e320be20035fe28b809cf87aacae36a
4
- data.tar.gz: 1bead226f4eaf6687c88244c912638a258642c45
3
+ metadata.gz: 0b193cd2ec66cb829fb7cf0ac6e9eaea6d107be3
4
+ data.tar.gz: fa1019b3746e56ad2b5785f801ea9c2588f1ea69
5
5
  SHA512:
6
- metadata.gz: 807f78fcb2367cbb513b05ae6c60e775ef8efcb2af77dd8f654c7e5c1f127b5d7227d5f14f0d3ae491e626caba63ce1c5f2ace8a86699624747bdb58e7b46770
7
- data.tar.gz: 9475e2ce04205f619b5fc9f670a42d1e091b586b469f4185fc290f0415bfeef35102d11b7920e38f9272d5cbfe71a16337610c9cdad5a5f62476f26620f021c6
6
+ metadata.gz: b6281693ae3f543e427c8e3667654eee30e157a54c8cde75900f676096b3acd70473a052904d6470ad2659abcfd473c6a704ee58b49bae8e1887290f15ee7159
7
+ data.tar.gz: 077a7e475ffc4ecd122caa148bac321f3201583a00f5d170b521c2dcf1d4ca96a4531bfc663ee558099618656b20fa2403bd5702b34591ad65a30ebc667a982a
data/README.md CHANGED
@@ -52,7 +52,7 @@ ReverseMarkdown.parse_string(input, github_style_code_blocks: true)
52
52
 
53
53
  Only basic html tags are supported right now. However, it should not be to difficult to add some. Feel free to contribute or notify me about missing stuff.
54
54
 
55
- - supported tags: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `p`, `em`, `strong`, `i`, `b`, `blockquote`, `code`, `img`, `a`, `hr`, `li`, `ol`, `ul`
55
+ - supported tags: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `p`, `em`, `strong`, `i`, `b`, `blockquote`, `code`, `img`, `a`, `hr`, `li`, `ol`, `ul`, `table`, `tr`, `th`, `td`
56
56
  - nested lists
57
57
  - inline and block code
58
58
 
@@ -137,6 +137,16 @@ module ReverseMarkdown
137
137
  "\n* * *\n"
138
138
  when :br
139
139
  " \n"
140
+ when :table
141
+ "\n\n"
142
+ when :tr
143
+ "|"
144
+ when :th, :td
145
+ if element == element.parent.first_element_child
146
+ " "
147
+ else
148
+ "| "
149
+ end
140
150
  else
141
151
  handle_error "unknown start tag: #{element.name.to_s}"
142
152
  ""
@@ -174,6 +184,17 @@ module ReverseMarkdown
174
184
  end
175
185
  when :img
176
186
  "#{element['alt']}](#{element['src']}#{title_markdown(element)}) "
187
+ when :table
188
+ "\n"
189
+ when :tr
190
+ "|\n" + \
191
+ if element.element_children.all? {|child| child.name.to_sym == :th}
192
+ "| " + (['---'] * element.element_children.size).join(' | ') + " |\n"
193
+ else
194
+ ""
195
+ end
196
+ when :th, :td
197
+ " "
177
198
  else
178
199
  handle_error "unknown end tag: #{element.name}"
179
200
  ""
@@ -1,3 +1,3 @@
1
1
  module ReverseMarkdown
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
@@ -0,0 +1,38 @@
1
+ <html>
2
+ <body>
3
+ some text...
4
+
5
+ <table>
6
+ <tr>
7
+ <th>header 1</th>
8
+ <th>header 2</th>
9
+ <th>header 3</th>
10
+ </tr>
11
+ <tr>
12
+ <td>data 1-1</td>
13
+ <td>data 2-1</td>
14
+ <td>data 3-1</td>
15
+ </tr>
16
+ <tr>
17
+ <td>data 1-2</td>
18
+ <td>data 2-2</td>
19
+ <td>data 3-2</td>
20
+ </tr>
21
+ </table>
22
+
23
+ <table>
24
+ <tr>
25
+ <th><i>header oblique</i></th>
26
+ <th><strong>header bold</strong></th>
27
+ <th><code>header code</code></th>
28
+ </tr>
29
+ <tr>
30
+ <td><i>data oblique</i></td>
31
+ <td><strong>data bold</strong></td>
32
+ <td><code>data code</code></td>
33
+ </tr>
34
+ </table>
35
+
36
+ some text...
37
+ </body>
38
+ </html>
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe ReverseMarkdown::Mapper do
4
+
5
+ let(:input) { File.read('spec/assets/tables.html') }
6
+ let(:document) { Nokogiri::HTML(input) }
7
+ subject { ReverseMarkdown.parse_string(input) }
8
+
9
+ it { should match /\n\| header 1 \| header 2 \| header 3 \|\n\| --- \| --- \| --- \|\n/ }
10
+ it { should match /\n\| data 1-1 \| data 2-1 \| data 3-1 \|\n/ }
11
+ it { should match /\n\| data 1-2 \| data 2-2 \| data 3-2 \|\n/ }
12
+
13
+ it { should match /\n\| _header oblique_ \| \*\*header bold\*\* \| `header code` \|\n| --- \| --- \| --- \|\n/ }
14
+ it { should match /\n\| _data oblique_ \| \*\*data bold\*\* \| `data code` \|\n/ }
15
+
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reverse_markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Opper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-11 00:00:00.000000000 Z
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -112,6 +112,7 @@ files:
112
112
  - spec/assets/minimum.html
113
113
  - spec/assets/paragraphs.html
114
114
  - spec/assets/quotation.html
115
+ - spec/assets/tables.html
115
116
  - spec/components/anchors_spec.rb
116
117
  - spec/components/basic_spec.rb
117
118
  - spec/components/code_spec.rb
@@ -121,6 +122,7 @@ files:
121
122
  - spec/components/lists_spec.rb
122
123
  - spec/components/paragraphs_spec.rb
123
124
  - spec/components/quotation_spec.rb
125
+ - spec/components/tables_spec.rb
124
126
  - spec/html_to_markdown_to_html_spec.rb
125
127
  - spec/mapper_spec.rb
126
128
  - spec/reverse_markdown_spec.rb
@@ -160,6 +162,7 @@ test_files:
160
162
  - spec/assets/minimum.html
161
163
  - spec/assets/paragraphs.html
162
164
  - spec/assets/quotation.html
165
+ - spec/assets/tables.html
163
166
  - spec/components/anchors_spec.rb
164
167
  - spec/components/basic_spec.rb
165
168
  - spec/components/code_spec.rb
@@ -169,6 +172,7 @@ test_files:
169
172
  - spec/components/lists_spec.rb
170
173
  - spec/components/paragraphs_spec.rb
171
174
  - spec/components/quotation_spec.rb
175
+ - spec/components/tables_spec.rb
172
176
  - spec/html_to_markdown_to_html_spec.rb
173
177
  - spec/mapper_spec.rb
174
178
  - spec/reverse_markdown_spec.rb