reverse_markdown 1.4.0 → 2.1.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 +10 -16
- data/CHANGELOG.md +11 -0
- data/README.md +3 -3
- data/lib/reverse_markdown/converters/details.rb +25 -0
- data/lib/reverse_markdown/converters/figcaption.rb +15 -0
- data/lib/reverse_markdown/converters/figure.rb +12 -0
- data/lib/reverse_markdown/converters/li.rb +2 -2
- data/lib/reverse_markdown/converters/pre.rb +2 -2
- data/lib/reverse_markdown/version.rb +1 -1
- data/lib/reverse_markdown.rb +3 -0
- data/reverse_markdown.gemspec +1 -1
- data/spec/assets/lists.html +2 -0
- data/spec/components/lists_spec.rb +2 -1
- data/spec/components/paragraphs_spec.rb +0 -1
- data/spec/components/quotation_spec.rb +0 -2
- data/spec/lib/reverse_markdown/converters/details_spec.rb +23 -0
- data/spec/lib/reverse_markdown/converters/figure_spec.rb +17 -0
- data/spec/lib/reverse_markdown/converters/pre_spec.rb +11 -1
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cffa2a16f5ad4187cb23a2e6a1015121b943f1c83a688308cf0a480ec15d3c49
|
4
|
+
data.tar.gz: 6941ad7c07005ff4d5c115fd894ee2a0cf40a09367833268f4c55c018f30263a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 620ce03beae7238accdc6836e025dc7b19fe308a7bcbcd7143dc7472d09e7d25758a3f6c2080d5d75e60fee662bc87ab200f177b5b6f41fa5958bde4b569a49e
|
7
|
+
data.tar.gz: ea69f20a1e70e4f41d6024502af362351ccaf6ec8936b4dcadc2414202e994cdf8ddf08ebbd829c0722c373bbe7e87a223c3c913bf6d845be9308ef418f3be75
|
data/.travis.yml
CHANGED
@@ -1,23 +1,17 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
3
|
|
4
4
|
rvm:
|
5
|
-
-
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.
|
9
|
-
- 2.
|
10
|
-
- 2.
|
11
|
-
- 2.
|
12
|
-
- 2.
|
13
|
-
- 2.3.1
|
14
|
-
- 2.4.2
|
15
|
-
- 2.5.3
|
16
|
-
- 2.6.2
|
5
|
+
- 2.0
|
6
|
+
- 2.1
|
7
|
+
- 2.2
|
8
|
+
- 2.3
|
9
|
+
- 2.4
|
10
|
+
- 2.5
|
11
|
+
- 2.6
|
12
|
+
- 2.7
|
17
13
|
- jruby-9.2.8.0
|
18
14
|
|
19
|
-
script: "bundle exec rake spec"
|
20
|
-
|
21
15
|
notifications:
|
22
16
|
disabled: false
|
23
17
|
recipients:
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 2.1.1 - October 2021
|
5
|
+
- Fixes unintentional newline characters within lists with paragraphs, thanks @diogoosorio, see #93
|
6
|
+
- Lets \n to be present in <pre> tag. solves #77 #78, thanks @shivabhusal
|
7
|
+
|
8
|
+
## 2.1.0 - May 2020
|
9
|
+
- Add support for `figure` tags, see #86, thanks @anshul78
|
10
|
+
|
11
|
+
## 2.0.0 - March 2020
|
12
|
+
- BREAKING: Dropped support for ruby 1.9.3
|
13
|
+
- Add support for `details` and `summary` tags, see #85
|
14
|
+
|
4
15
|
## 1.4.0 – January 2020
|
5
16
|
- BREAKING: jump links will no longer be ignored but treated as links, see #82
|
6
17
|
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Transform html into markdown. Useful for example if you want to import html into your markdown based application.
|
4
4
|
|
5
|
-
[![Build Status](https://secure.travis-ci.org/xijo/reverse_markdown.
|
5
|
+
[![Build Status](https://secure.travis-ci.org/xijo/reverse_markdown.svg?branch=master)](https://travis-ci.org/xijo/reverse_markdown) [![Gem Version](https://badge.fury.io/rb/reverse_markdown.svg)](http://badge.fury.io/rb/reverse_markdown) [![Code Climate](https://codeclimate.com/github/xijo/reverse_markdown.svg)](https://codeclimate.com/github/xijo/reverse_markdown) [![Code Climate](https://codeclimate.com/github/xijo/reverse_markdown/coverage.png)](https://codeclimate.com/github/xijo/reverse_markdown)
|
6
6
|
|
7
7
|
## Changelog
|
8
8
|
|
@@ -11,7 +11,7 @@ See [Change Log](CHANGELOG.md)
|
|
11
11
|
## Requirements
|
12
12
|
|
13
13
|
1. [Nokogiri](http://nokogiri.org/)
|
14
|
-
2. Ruby
|
14
|
+
2. Ruby 2.0.0 or higher
|
15
15
|
|
16
16
|
## Installation
|
17
17
|
|
@@ -29,7 +29,7 @@ gem 'reverse_markdown'
|
|
29
29
|
|
30
30
|
## Features
|
31
31
|
|
32
|
-
- Supports all the established html tags like `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `p`, `em`, `strong`, `i`, `b`, `blockquote`, `code`, `img`, `a`, `hr`, `li`, `ol`, `ul`, `table`, `tr`, `th`, `td`, `br`
|
32
|
+
- Supports all the established html tags like `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `p`, `em`, `strong`, `i`, `b`, `blockquote`, `code`, `img`, `a`, `hr`, `li`, `ol`, `ul`, `table`, `tr`, `th`, `td`, `br`, `figure`
|
33
33
|
- Module based - if you miss a tag, just add it
|
34
34
|
- Can deal with nested lists
|
35
35
|
- Inline and block code is supported
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ReverseMarkdown
|
2
|
+
module Converters
|
3
|
+
class Details < Base
|
4
|
+
def convert(node, state = {})
|
5
|
+
content = treat_children(node, state.merge(already_processed: true))
|
6
|
+
if disabled? || content.strip.empty? || state[:already_processed]
|
7
|
+
content
|
8
|
+
else
|
9
|
+
"##{content}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def enabled?
|
14
|
+
ReverseMarkdown.config.github_flavored
|
15
|
+
end
|
16
|
+
|
17
|
+
def disabled?
|
18
|
+
!enabled?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
register :details, Details.new
|
23
|
+
register :summary, Details.new
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ReverseMarkdown
|
2
|
+
module Converters
|
3
|
+
class FigCaption < Base
|
4
|
+
def convert(node, state = {})
|
5
|
+
if node.text.strip.empty?
|
6
|
+
""
|
7
|
+
else
|
8
|
+
"\n" << "_#{node.text.strip}_" << "\n"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
register :figcaption, FigCaption.new
|
14
|
+
end
|
15
|
+
end
|
@@ -2,8 +2,8 @@ module ReverseMarkdown
|
|
2
2
|
module Converters
|
3
3
|
class Li < Base
|
4
4
|
def convert(node, state = {})
|
5
|
-
contains_child_paragraph = node.
|
6
|
-
content_node = contains_child_paragraph ? node.
|
5
|
+
contains_child_paragraph = node.first_element_child ? node.first_element_child.name == 'p' : false
|
6
|
+
content_node = contains_child_paragraph ? node.first_element_child : node
|
7
7
|
content = treat_children(content_node, state)
|
8
8
|
indentation = indentation_from(state)
|
9
9
|
prefix = prefix_for(node)
|
data/lib/reverse_markdown.rb
CHANGED
@@ -13,7 +13,10 @@ require 'reverse_markdown/converters/code'
|
|
13
13
|
require 'reverse_markdown/converters/del'
|
14
14
|
require 'reverse_markdown/converters/div'
|
15
15
|
require 'reverse_markdown/converters/drop'
|
16
|
+
require 'reverse_markdown/converters/details'
|
16
17
|
require 'reverse_markdown/converters/em'
|
18
|
+
require 'reverse_markdown/converters/figcaption'
|
19
|
+
require 'reverse_markdown/converters/figure'
|
17
20
|
require 'reverse_markdown/converters/h'
|
18
21
|
require 'reverse_markdown/converters/hr'
|
19
22
|
require 'reverse_markdown/converters/ignore'
|
data/reverse_markdown.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency 'simplecov'
|
24
24
|
s.add_development_dependency 'rake'
|
25
25
|
s.add_development_dependency 'kramdown'
|
26
|
-
|
26
|
+
s.add_development_dependency 'byebug'
|
27
27
|
s.add_development_dependency 'codeclimate-test-reporter'
|
28
28
|
end
|
data/spec/assets/lists.html
CHANGED
@@ -35,7 +35,8 @@ describe ReverseMarkdown do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
context "lists containing embedded <p> tags" do
|
38
|
-
|
38
|
+
it { is_expected.to match /\n- I want to have a party at my house!\n/ }
|
39
|
+
it { is_expected.to match /\n- I don't want to cleanup after the party!\n/ }
|
39
40
|
end
|
40
41
|
|
41
42
|
context "list item containing multiple <p> tags" do
|
@@ -1,12 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ReverseMarkdown do
|
4
|
-
|
5
4
|
let(:input) { File.read('spec/assets/quotation.html') }
|
6
5
|
let(:document) { Nokogiri::HTML(input) }
|
7
6
|
subject { ReverseMarkdown.convert(input) }
|
8
7
|
|
9
8
|
it { is_expected.to match /^ Block of code$/ }
|
10
9
|
it { is_expected.to include "\n> First quoted paragraph\n> \n> Second quoted paragraph" }
|
11
|
-
|
12
10
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ReverseMarkdown::Converters::Details do
|
4
|
+
let(:converter) { ReverseMarkdown::Converters::Details.new }
|
5
|
+
|
6
|
+
context 'for standard markdown' do
|
7
|
+
before { ReverseMarkdown.config.github_flavored = false }
|
8
|
+
|
9
|
+
it 'handles details tags correctly' do
|
10
|
+
node = node_for("<details>foo</details>")
|
11
|
+
expect(converter.convert(node)).to include "foo"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'for github_flavored markdown' do
|
16
|
+
before { ReverseMarkdown.config.github_flavored = true }
|
17
|
+
|
18
|
+
it 'handles details tags correctly' do
|
19
|
+
node = node_for("<details>foo</details>")
|
20
|
+
expect(converter.convert(node)).to include "#foo"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ReverseMarkdown::Converters::Figure do
|
4
|
+
|
5
|
+
let(:converter) { ReverseMarkdown::Converters::Figure.new }
|
6
|
+
|
7
|
+
it 'handles figure tags with figcaption correctly' do
|
8
|
+
node = node_for("<figure><img src='image.jpg' alt='img_alt'><figcaption>Figure Caption</figcaption></figure>")
|
9
|
+
expect(converter.convert(node)).to eq "\n![img_alt](image.jpg)\n_Figure Caption_\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'handles figure tags without figcaption correctly' do
|
13
|
+
node = node_for("<figure><img src='image.jpg' alt='img_alt'></figure>")
|
14
|
+
expect(converter.convert(node)).to eq "\n![img_alt](image.jpg)\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -12,10 +12,15 @@ describe ReverseMarkdown::Converters::Pre do
|
|
12
12
|
expect(converter.convert(node)).to include " puts foo\n"
|
13
13
|
end
|
14
14
|
|
15
|
-
it 'preserves new lines' do
|
15
|
+
it 'preserves new lines as <br>' do
|
16
16
|
node = node_for("<pre>one<br>two<br>three</pre>")
|
17
17
|
expect(converter.convert(node)).to include "\n\n one\n two\n three\n\n"
|
18
18
|
end
|
19
|
+
|
20
|
+
it 'preserves new lines as <br> and \n' do
|
21
|
+
node = node_for("<pre>one\ntwo\nthree<br>four</pre>")
|
22
|
+
expect(converter.convert(node)).to include "\n\n one\n two\n three\n four\n\n"
|
23
|
+
end
|
19
24
|
|
20
25
|
it 'handles code tags correctly' do
|
21
26
|
node = node_for("<pre><code>foobar</code></pre>")
|
@@ -41,6 +46,11 @@ describe ReverseMarkdown::Converters::Pre do
|
|
41
46
|
expect(converter.convert(node)).to include "```\nfoo\nbar\n```"
|
42
47
|
end
|
43
48
|
|
49
|
+
it 'preserves new lines as <br> and \n' do
|
50
|
+
node = node_for("<pre>one\ntwo\nthree<br>four</pre>")
|
51
|
+
expect(converter.convert(node)).to include "```\none\ntwo\nthree\nfour\n```"
|
52
|
+
end
|
53
|
+
|
44
54
|
it 'handles code tags correctly' do
|
45
55
|
node = node_for("<pre><code>foobar</code></pre>")
|
46
56
|
expect(converter.convert(node)).to include "```\nfoobar\n```"
|
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: 2.1.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: 2021-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: codeclimate-test-reporter
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,9 +137,12 @@ files:
|
|
123
137
|
- lib/reverse_markdown/converters/bypass.rb
|
124
138
|
- lib/reverse_markdown/converters/code.rb
|
125
139
|
- lib/reverse_markdown/converters/del.rb
|
140
|
+
- lib/reverse_markdown/converters/details.rb
|
126
141
|
- lib/reverse_markdown/converters/div.rb
|
127
142
|
- lib/reverse_markdown/converters/drop.rb
|
128
143
|
- lib/reverse_markdown/converters/em.rb
|
144
|
+
- lib/reverse_markdown/converters/figcaption.rb
|
145
|
+
- lib/reverse_markdown/converters/figure.rb
|
129
146
|
- lib/reverse_markdown/converters/h.rb
|
130
147
|
- lib/reverse_markdown/converters/hr.rb
|
131
148
|
- lib/reverse_markdown/converters/ignore.rb
|
@@ -173,6 +190,8 @@ files:
|
|
173
190
|
- spec/lib/reverse_markdown/converters/blockquote_spec.rb
|
174
191
|
- spec/lib/reverse_markdown/converters/br_spec.rb
|
175
192
|
- spec/lib/reverse_markdown/converters/del_spec.rb
|
193
|
+
- spec/lib/reverse_markdown/converters/details_spec.rb
|
194
|
+
- spec/lib/reverse_markdown/converters/figure_spec.rb
|
176
195
|
- spec/lib/reverse_markdown/converters/li_spec.rb
|
177
196
|
- spec/lib/reverse_markdown/converters/pre_spec.rb
|
178
197
|
- spec/lib/reverse_markdown/converters/strong_spec.rb
|
@@ -199,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
218
|
- !ruby/object:Gem::Version
|
200
219
|
version: '0'
|
201
220
|
requirements: []
|
202
|
-
rubygems_version: 3.
|
221
|
+
rubygems_version: 3.1.4
|
203
222
|
signing_key:
|
204
223
|
specification_version: 4
|
205
224
|
summary: Convert html code into markdown.
|
@@ -234,6 +253,8 @@ test_files:
|
|
234
253
|
- spec/lib/reverse_markdown/converters/blockquote_spec.rb
|
235
254
|
- spec/lib/reverse_markdown/converters/br_spec.rb
|
236
255
|
- spec/lib/reverse_markdown/converters/del_spec.rb
|
256
|
+
- spec/lib/reverse_markdown/converters/details_spec.rb
|
257
|
+
- spec/lib/reverse_markdown/converters/figure_spec.rb
|
237
258
|
- spec/lib/reverse_markdown/converters/li_spec.rb
|
238
259
|
- spec/lib/reverse_markdown/converters/pre_spec.rb
|
239
260
|
- spec/lib/reverse_markdown/converters/strong_spec.rb
|