reverse_markdown 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +7 -0
- data/README.md +4 -4
- data/lib/reverse_markdown.rb +4 -3
- data/lib/reverse_markdown/config.rb +14 -8
- data/lib/reverse_markdown/converters/text.rb +7 -1
- data/lib/reverse_markdown/version.rb +1 -1
- data/reverse_markdown.gemspec +1 -1
- data/spec/assets/paragraphs.html +9 -0
- data/spec/components/paragraphs_spec.rb +3 -0
- data/spec/lib/reverse_markdown/config_spec.rb +26 -0
- data/spec/lib/reverse_markdown/converters/text_spec.rb +6 -0
- data/spec/spec_helper.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae1d23f69d1494799f0b6773df49559fb53c6979
|
4
|
+
data.tar.gz: 65231dac3cf20c1a549dd3807ad9c8a9c44a05ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 850a262c23e1ef0c661fa4e338cba4fc3e4a7c420ca5f7381eeaf65c63280ba00d861ee11f92b7340d7336caf441981eab1453f8b9c89d592678935eda0ec121
|
7
|
+
data.tar.gz: d135d8464c76aa9a10cf03cbafe7670b8100c2dd10b9b7c62245f4b8bde79441eb9aeffaa13ec630c153595bde78d8f069a3929533109a7f19eb24fe77e8d68a
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 0.6.1 - January 2015
|
5
|
+
### Changed
|
6
|
+
- Setting config options in block style will last for all following `convert` calls.
|
7
|
+
- Inline config options are only applied to this particular operation
|
8
|
+
|
9
|
+
### Removed
|
10
|
+
- `config.reset` is removed
|
4
11
|
|
5
12
|
## 0.6.0 - September 2014
|
6
13
|
### Added
|
data/README.md
CHANGED
@@ -70,7 +70,7 @@ The following options are available:
|
|
70
70
|
|
71
71
|
### As options
|
72
72
|
|
73
|
-
Just pass your chosen configuration options in after the input
|
73
|
+
Just pass your chosen configuration options in after the input. The given options will last for this operation only.
|
74
74
|
|
75
75
|
```ruby
|
76
76
|
ReverseMarkdown.convert(input, unknown_tags: :raise, github_flavored: true)
|
@@ -78,12 +78,12 @@ ReverseMarkdown.convert(input, unknown_tags: :raise, github_flavored: true)
|
|
78
78
|
|
79
79
|
### Preconfigure
|
80
80
|
|
81
|
-
Or configure it block style on a initializer level
|
81
|
+
Or configure it block style on a initializer level. These configurations will last for all conversions until they are set to something different.
|
82
82
|
|
83
83
|
```ruby
|
84
84
|
ReverseMarkdown.config do |config|
|
85
|
-
config.
|
86
|
-
config.github_flavored
|
85
|
+
config.unknown_tags = :bypass
|
86
|
+
config.github_flavored = true
|
87
87
|
end
|
88
88
|
```
|
89
89
|
|
data/lib/reverse_markdown.rb
CHANGED
@@ -40,9 +40,10 @@ module ReverseMarkdown
|
|
40
40
|
end
|
41
41
|
|
42
42
|
root or return ''
|
43
|
-
|
44
|
-
result =
|
45
|
-
|
43
|
+
|
44
|
+
result = config.with(options) do
|
45
|
+
ReverseMarkdown::Converters.lookup(root.name).convert(root)
|
46
|
+
end
|
46
47
|
cleaner.tidy(result)
|
47
48
|
end
|
48
49
|
|
@@ -3,18 +3,24 @@ module ReverseMarkdown
|
|
3
3
|
attr_accessor :unknown_tags, :github_flavored
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
|
6
|
+
@unknown_tags = :pass_through
|
7
|
+
@github_flavored = false
|
8
|
+
@inline_options = {}
|
7
9
|
end
|
8
10
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def with(options = {})
|
12
|
+
@inline_options = options
|
13
|
+
result = yield
|
14
|
+
@inline_options = {}
|
15
|
+
result
|
13
16
|
end
|
14
17
|
|
15
|
-
def
|
16
|
-
@unknown_tags
|
17
|
-
|
18
|
+
def unknown_tags
|
19
|
+
@inline_options[:unknown_tags] || @unknown_tags
|
20
|
+
end
|
21
|
+
|
22
|
+
def github_flavored
|
23
|
+
@inline_options[:github_flavored] || @github_flavored
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
@@ -23,11 +23,17 @@ module ReverseMarkdown
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def treat_text(node)
|
26
|
-
text =
|
26
|
+
text = node.text
|
27
|
+
text = preserve_nbsp(text)
|
28
|
+
text = remove_border_newlines(text)
|
27
29
|
text = remove_inner_newlines(text)
|
28
30
|
escape_keychars text
|
29
31
|
end
|
30
32
|
|
33
|
+
def preserve_nbsp(text)
|
34
|
+
text.gsub(/\u00A0/, " ")
|
35
|
+
end
|
36
|
+
|
31
37
|
def remove_border_newlines(text)
|
32
38
|
text.gsub(/\A\n+/, '').gsub(/\n+\z/, '')
|
33
39
|
end
|
data/reverse_markdown.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "reverse_markdown"
|
7
7
|
s.version = ReverseMarkdown::VERSION
|
8
8
|
s.authors = ["Johannes Opper"]
|
9
|
-
s.email = ["
|
9
|
+
s.email = ["johannes.opper@gmail.com"]
|
10
10
|
s.homepage = "http://github.com/xijo/reverse_markdown"
|
11
11
|
s.summary = %q{Convert html code into markdown.}
|
12
12
|
s.description = %q{Map simple html back into markdown, e.g. if you want to import existing html data in your application.}
|
data/spec/assets/paragraphs.html
CHANGED
@@ -11,5 +11,14 @@
|
|
11
11
|
<code>Content</code>
|
12
12
|
</pre>
|
13
13
|
</p>
|
14
|
+
<p>
|
15
|
+
<strong>Trailing whitespace: </strong>
|
16
|
+
</p>
|
17
|
+
<p>
|
18
|
+
<strong>Trailing non-breaking space: </strong>
|
19
|
+
</p>
|
20
|
+
<p>
|
21
|
+
<strong><em>Combination: </em></strong>
|
22
|
+
</p>
|
14
23
|
</body>
|
15
24
|
</html>
|
@@ -9,4 +9,7 @@ describe ReverseMarkdown do
|
|
9
9
|
it { should_not start_with "\n\n" }
|
10
10
|
it { should start_with "First content\n\nSecond content\n\n" }
|
11
11
|
it { should include "\n\n_Complex_\n\n Content" }
|
12
|
+
it { should include "**Trailing whitespace:**" }
|
13
|
+
it { should include "**Trailing non-breaking space: **" }
|
14
|
+
it { should include "**_Combination: _**" }
|
12
15
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ReverseMarkdown::Config do
|
4
|
+
describe '#with' do
|
5
|
+
let(:config) { ReverseMarkdown.config }
|
6
|
+
|
7
|
+
it 'takes additional options into account' do
|
8
|
+
config.with(github_flavored: :foobar) do
|
9
|
+
expect(ReverseMarkdown.config.github_flavored).to eq :foobar
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns the result of a given block' do
|
14
|
+
expect(config.with { :something }).to eq :something
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'resets to original settings afterwards' do
|
18
|
+
config.github_flavored = :foo
|
19
|
+
config.with(github_flavored: :bar) do
|
20
|
+
expect(ReverseMarkdown.config.github_flavored).to eq :bar
|
21
|
+
end
|
22
|
+
expect(ReverseMarkdown.config.github_flavored).to eq :foo
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -22,4 +22,10 @@ describe ReverseMarkdown::Converters::Text do
|
|
22
22
|
expect(result).to eq 'foo bar'
|
23
23
|
end
|
24
24
|
|
25
|
+
it 'keeps nbsps' do
|
26
|
+
input = Nokogiri::XML.parse("<p>foo\u00A0bar \u00A0</p>").root
|
27
|
+
result = converter.convert(input)
|
28
|
+
expect(result).to eq "foo bar "
|
29
|
+
end
|
30
|
+
|
25
31
|
end
|
data/spec/spec_helper.rb
CHANGED
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.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Opper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -97,7 +97,7 @@ dependencies:
|
|
97
97
|
description: Map simple html back into markdown, e.g. if you want to import existing
|
98
98
|
html data in your application.
|
99
99
|
email:
|
100
|
-
-
|
100
|
+
- johannes.opper@gmail.com
|
101
101
|
executables:
|
102
102
|
- reverse_markdown
|
103
103
|
extensions: []
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- spec/components/unknown_tags_spec.rb
|
170
170
|
- spec/html_to_markdown_to_html_spec.rb
|
171
171
|
- spec/lib/reverse_markdown/cleaner_spec.rb
|
172
|
+
- spec/lib/reverse_markdown/config_spec.rb
|
172
173
|
- spec/lib/reverse_markdown/converters/blockquote_spec.rb
|
173
174
|
- spec/lib/reverse_markdown/converters/br_spec.rb
|
174
175
|
- spec/lib/reverse_markdown/converters/del_spec.rb
|
@@ -226,6 +227,7 @@ test_files:
|
|
226
227
|
- spec/components/unknown_tags_spec.rb
|
227
228
|
- spec/html_to_markdown_to_html_spec.rb
|
228
229
|
- spec/lib/reverse_markdown/cleaner_spec.rb
|
230
|
+
- spec/lib/reverse_markdown/config_spec.rb
|
229
231
|
- spec/lib/reverse_markdown/converters/blockquote_spec.rb
|
230
232
|
- spec/lib/reverse_markdown/converters/br_spec.rb
|
231
233
|
- spec/lib/reverse_markdown/converters/del_spec.rb
|