reverse_markdown 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Rakefile +1 -1
- data/lib/reverse_markdown.rb +9 -8
- data/lib/reverse_markdown/cleaner.rb +5 -0
- data/lib/reverse_markdown/config.rb +6 -1
- data/lib/reverse_markdown/converters/a.rb +1 -1
- data/lib/reverse_markdown/version.rb +1 -1
- data/reverse_markdown.gemspec +0 -1
- data/spec/components/anchors_spec.rb +1 -1
- data/spec/lib/reverse_markdown_spec.rb +10 -0
- data/spec/spec_helper.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1945214c22af9c763471e6bf9375fe94f1618fd67af1de2a28a0c88cdc59c07a
|
4
|
+
data.tar.gz: 26352feda47de16934757ade063ec14d55a9a6c8364570a9b3b72c656deb803b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 959cc8dff7496eec2b8828f6f059ababa4d008fe6b5aebc05d442b6c746b4d863b1f860f29c5620738273ed808a21b9a19182283d2c177e8b86d0553e53f01ad
|
7
|
+
data.tar.gz: 2580ead64498f94190f4e20cb3a475e1e8e5dc7f3343fe8d7ea4fcb4a7d9a163628facdb0eb00ad2b335edc3b9758dc83389c7dfd611e1325586d9a75e4e9a33
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 1.4.0 – January 2020
|
5
|
+
- BREAKING: jump links will no longer be ignored but treated as links, see #82
|
6
|
+
|
4
7
|
## 1.3.0 - September 2019
|
5
8
|
- Add support for `s` HTML tag, thanks @fauno
|
6
9
|
|
data/Rakefile
CHANGED
data/lib/reverse_markdown.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'digest'
|
2
1
|
require 'nokogiri'
|
3
2
|
require 'reverse_markdown/version'
|
4
3
|
require 'reverse_markdown/errors'
|
@@ -33,15 +32,17 @@ require 'reverse_markdown/converters/tr'
|
|
33
32
|
module ReverseMarkdown
|
34
33
|
|
35
34
|
def self.convert(input, options = {})
|
36
|
-
|
37
|
-
|
38
|
-
when Nokogiri::XML::Document then input.root
|
39
|
-
when Nokogiri::XML::Node then input
|
40
|
-
end
|
35
|
+
config.with(options) do
|
36
|
+
input = cleaner.force_encoding(input.to_s)
|
41
37
|
|
42
|
-
|
38
|
+
root = case input
|
39
|
+
when String then Nokogiri::HTML(input).root
|
40
|
+
when Nokogiri::XML::Document then input.root
|
41
|
+
when Nokogiri::XML::Node then input
|
42
|
+
end
|
43
|
+
|
44
|
+
root or return ''
|
43
45
|
|
44
|
-
config.with(options) do
|
45
46
|
result = ReverseMarkdown::Converters.lookup(root.name).convert(root)
|
46
47
|
cleaner.tidy(result)
|
47
48
|
end
|
@@ -59,6 +59,11 @@ module ReverseMarkdown
|
|
59
59
|
string.gsub(/(\*\*|~~|__)\s([\.!\?'"])/, "\\1".strip + "\\2")
|
60
60
|
end
|
61
61
|
|
62
|
+
def force_encoding(string)
|
63
|
+
ReverseMarkdown.config.force_encoding or return string
|
64
|
+
string.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
65
|
+
end
|
66
|
+
|
62
67
|
private
|
63
68
|
|
64
69
|
def preserve_border_whitespaces(string, options = {}, &block)
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
class Config
|
3
|
-
|
3
|
+
attr_writer :unknown_tags, :github_flavored, :tag_border, :force_encoding
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@unknown_tags = :pass_through
|
7
7
|
@github_flavored = false
|
8
|
+
@force_encoding = false
|
8
9
|
@em_delimiter = '_'.freeze
|
9
10
|
@strong_delimiter = '**'.freeze
|
10
11
|
@inline_options = {}
|
@@ -29,5 +30,9 @@ module ReverseMarkdown
|
|
29
30
|
def tag_border
|
30
31
|
@inline_options[:tag_border] || @tag_border
|
31
32
|
end
|
33
|
+
|
34
|
+
def force_encoding
|
35
|
+
@inline_options[:force_encoding] || @force_encoding
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
data/reverse_markdown.gemspec
CHANGED
@@ -11,7 +11,6 @@ Gem::Specification.new do |s|
|
|
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.}
|
13
13
|
s.licenses = ["WTFPL"]
|
14
|
-
s.rubyforge_project = "reverse_markdown"
|
15
14
|
|
16
15
|
s.files = `git ls-files`.split("\n")
|
17
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -20,7 +20,7 @@ describe ReverseMarkdown do
|
|
20
20
|
context "links to ignore" do
|
21
21
|
it { is_expected.to include ' ignore anchor tags with no link text ' }
|
22
22
|
it { is_expected.to include ' not ignore [![An Image](image.png)](foo.html) anchor tags with images' }
|
23
|
-
it { is_expected.to include ' pass through the text of internal jumplinks without treating them as links ' }
|
23
|
+
it { is_expected.to include ' pass through the text of [internal jumplinks](#content) without treating them as links ' }
|
24
24
|
it { is_expected.to include ' pass through the text of anchor tags with no href without treating them as links ' }
|
25
25
|
end
|
26
26
|
|
@@ -33,5 +33,15 @@ describe ReverseMarkdown do
|
|
33
33
|
end
|
34
34
|
expect(ReverseMarkdown.config.github_flavored).to eq true
|
35
35
|
end
|
36
|
+
|
37
|
+
describe 'force_encoding option', jruby: :exclude do
|
38
|
+
it 'raises invalid byte sequence in UTF-8 exception' do
|
39
|
+
expect { ReverseMarkdown.convert("hi \255") }.to raise_error(ArgumentError)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'handles invalid byte sequence if option is set' do
|
43
|
+
expect(ReverseMarkdown.convert("hi \255", force_encoding: true)).to eq "hi\n\n"
|
44
|
+
end
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,6 +14,14 @@ RSpec.configure do |config|
|
|
14
14
|
config.after(:each) do
|
15
15
|
ReverseMarkdown.instance_variable_set(:@config, nil)
|
16
16
|
end
|
17
|
+
|
18
|
+
config.around(jruby: :exclude) do |example|
|
19
|
+
if RUBY_ENGINE == 'jruby'
|
20
|
+
example.metadata[:skip] = true
|
21
|
+
else
|
22
|
+
example.call
|
23
|
+
end
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
def node_for(html)
|
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: 1.
|
4
|
+
version: 1.4.0
|
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: 2020-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|