reverse_markdown 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8263de44d8eac3a94972aea1e17323f1c51a44055a2953a4fa4ba2202585aeee
4
- data.tar.gz: 8f21ecda53dd5edfc9e5faaebf8105bb98033c43a1480dd4d56b885602933bc6
3
+ metadata.gz: 1945214c22af9c763471e6bf9375fe94f1618fd67af1de2a28a0c88cdc59c07a
4
+ data.tar.gz: 26352feda47de16934757ade063ec14d55a9a6c8364570a9b3b72c656deb803b
5
5
  SHA512:
6
- metadata.gz: b05f33ea93fb3c751534166c1e8fe4baefd3dfa3d9546db1b8535a4e70ed9f25a92fafac167640ef10e6ed44a0cf5b0366dac9ce6d6a9d64ffe8d7642d8f3d1f
7
- data.tar.gz: 0b37d09c0949a521c3ae7c09a27283165fbab621ab87377fb1b5f8b532d171abf6bb0d221dc810da3ffb2c34b2afe922463dadcf097a0810473781c0664f7978
6
+ metadata.gz: 959cc8dff7496eec2b8828f6f059ababa4d008fe6b5aebc05d442b6c746b4d863b1f860f29c5620738273ed808a21b9a19182283d2c177e8b86d0553e53f01ad
7
+ data.tar.gz: 2580ead64498f94190f4e20cb3a475e1e8e5dc7f3343fe8d7ea4fcb4a7d9a163628facdb0eb00ad2b335edc3b9758dc83389c7dfd611e1325586d9a75e4e9a33
@@ -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
@@ -10,5 +10,5 @@ task :default => :spec
10
10
 
11
11
  desc 'Open an irb session preloaded with this library'
12
12
  task :console do
13
- sh 'irb -rubygems -I lib -r reverse_markdown.rb'
13
+ sh 'irb -I lib -r reverse_markdown.rb'
14
14
  end
@@ -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
- root = case input
37
- when String then Nokogiri::HTML(input).root
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
- root or return ''
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
- attr_accessor :unknown_tags, :github_flavored, :tag_border
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
@@ -6,7 +6,7 @@ module ReverseMarkdown
6
6
  href = node['href']
7
7
  title = extract_title(node)
8
8
 
9
- if href.to_s.start_with?('#') || href.to_s.empty? || name.empty?
9
+ if href.to_s.empty? || name.empty?
10
10
  name
11
11
  else
12
12
  link = "[#{name}](#{href}#{title})"
@@ -1,3 +1,3 @@
1
1
  module ReverseMarkdown
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -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
@@ -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.3.0
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: 2019-09-09 00:00:00.000000000 Z
11
+ date: 2020-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri