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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 345b5116f393914034fa05e3ceae0f7cabbda791
4
- data.tar.gz: ecc2a58d1b46fb2c338d95009d2866239b4de880
3
+ metadata.gz: ae1d23f69d1494799f0b6773df49559fb53c6979
4
+ data.tar.gz: 65231dac3cf20c1a549dd3807ad9c8a9c44a05ca
5
5
  SHA512:
6
- metadata.gz: d509a043b014bd9e6f72e56bb728befc8923668646b054e7ea6b4cd8576e45e2130a51d1a3100e87c61b518be80e47078b1d19a741e3469ff835790cf901d543
7
- data.tar.gz: f199c4efb681293e100f7c5bfbd7436c6ea194273b3a7e76509ec6387f689ceabdfeb1838de8a8e5de976802f6f7e3945f6458aaa6a01d71751c160d1402c286
6
+ metadata.gz: 850a262c23e1ef0c661fa4e338cba4fc3e4a7c420ca5f7381eeaf65c63280ba00d861ee11f92b7340d7336caf441981eab1453f8b9c89d592678935eda0ec121
7
+ data.tar.gz: d135d8464c76aa9a10cf03cbafe7670b8100c2dd10b9b7c62245f4b8bde79441eb9aeffaa13ec630c153595bde78d8f069a3929533109a7f19eb24fe77e8d68a
@@ -3,6 +3,7 @@ rvm:
3
3
  - 2.0.0
4
4
  - 2.1.0
5
5
  - 2.1.1
6
+ - 2.2.0
6
7
 
7
8
  script: "bundle exec rake spec"
8
9
 
@@ -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.ignore_unknown_tags = false
86
- config.github_flavored = true
85
+ config.unknown_tags = :bypass
86
+ config.github_flavored = true
87
87
  end
88
88
  ```
89
89
 
@@ -40,9 +40,10 @@ module ReverseMarkdown
40
40
  end
41
41
 
42
42
  root or return ''
43
- config.apply(options)
44
- result = ReverseMarkdown::Converters.lookup(root.name).convert(root)
45
- config.reset
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
- reset
6
+ @unknown_tags = :pass_through
7
+ @github_flavored = false
8
+ @inline_options = {}
7
9
  end
8
10
 
9
- def apply(options = {})
10
- options.each do |method, value|
11
- __send__(:"#{method}=", value)
12
- end
11
+ def with(options = {})
12
+ @inline_options = options
13
+ result = yield
14
+ @inline_options = {}
15
+ result
13
16
  end
14
17
 
15
- def reset
16
- @unknown_tags = :pass_through
17
- @github_flavored = false
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 = remove_border_newlines(node.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
@@ -1,3 +1,3 @@
1
1
  module ReverseMarkdown
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -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 = ["xijo@gmx.de"]
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.}
@@ -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:&nbsp;</strong>
19
+ </p>
20
+ <p>
21
+ <strong><em>Combination:&nbsp;</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:&nbsp;**" }
14
+ it { should include "**_Combination:&nbsp;_**" }
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&nbsp;bar &nbsp;"
29
+ end
30
+
25
31
  end
@@ -15,6 +15,6 @@ require 'reverse_markdown'
15
15
 
16
16
  RSpec.configure do |config|
17
17
  config.after(:each) do
18
- ReverseMarkdown.config.reset
18
+ ReverseMarkdown.instance_variable_set(:@config, nil)
19
19
  end
20
20
  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.6.0
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: 2014-09-14 00:00:00.000000000 Z
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
- - xijo@gmx.de
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