reverse_markdown 0.8.2 → 1.0.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +7 -0
- data/bin/reverse_markdown +10 -0
- data/lib/reverse_markdown/cleaner.rb +3 -3
- data/lib/reverse_markdown/config.rb +8 -3
- data/lib/reverse_markdown/converters/a.rb +2 -2
- data/lib/reverse_markdown/converters/base.rb +4 -4
- data/lib/reverse_markdown/converters/blockquote.rb +2 -2
- data/lib/reverse_markdown/converters/br.rb +1 -1
- data/lib/reverse_markdown/converters/bypass.rb +2 -2
- data/lib/reverse_markdown/converters/code.rb +1 -1
- data/lib/reverse_markdown/converters/del.rb +3 -7
- data/lib/reverse_markdown/converters/div.rb +2 -2
- data/lib/reverse_markdown/converters/drop.rb +1 -1
- data/lib/reverse_markdown/converters/em.rb +3 -7
- data/lib/reverse_markdown/converters/h.rb +2 -2
- data/lib/reverse_markdown/converters/hr.rb +1 -1
- data/lib/reverse_markdown/converters/ignore.rb +1 -1
- data/lib/reverse_markdown/converters/img.rb +1 -1
- data/lib/reverse_markdown/converters/li.rb +5 -5
- data/lib/reverse_markdown/converters/ol.rb +3 -2
- data/lib/reverse_markdown/converters/p.rb +2 -2
- data/lib/reverse_markdown/converters/pass_through.rb +1 -1
- data/lib/reverse_markdown/converters/pre.rb +1 -1
- data/lib/reverse_markdown/converters/strong.rb +3 -7
- data/lib/reverse_markdown/converters/table.rb +2 -2
- data/lib/reverse_markdown/converters/td.rb +2 -2
- data/lib/reverse_markdown/converters/text.rb +8 -1
- data/lib/reverse_markdown/converters/tr.rb +2 -2
- data/lib/reverse_markdown/version.rb +1 -1
- data/spec/assets/basic.html +4 -4
- data/spec/components/basic_spec.rb +4 -4
- data/spec/lib/reverse_markdown/cleaner_spec.rb +90 -40
- data/spec/lib/reverse_markdown/converters/strong_spec.rb +1 -1
- data/spec/lib/reverse_markdown/converters/text_spec.rb +6 -0
- data/spec/lib/reverse_markdown/converters_spec.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 950a3b8b3c2243b54c3d30a202e97c8084245a7e
|
4
|
+
data.tar.gz: 4c1c739b0e2b0aa7979e37d229697ac34eb98319
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc484226804f23f87509417538b7cdfa3b74a862f02ab4a7846f8cec9ab0c33f808b7d4ae206ce02710f7a81f861e8c00e2acc141ff73c974a4d8fbbf6fa5be2
|
7
|
+
data.tar.gz: 5facbab6c8082d32ac0928d56d940f0153a7e0fae26b90f55aa1c0ae4ee0d35f789f436015a33ed6360e496ebf2b125676ce874b850e2dfefeadf8c571f8ffc4
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 1.0.0 - Nov 2015
|
5
|
+
### Changes
|
6
|
+
- BREAKING: Parsing was significantly improved, thanks @craig-day (#60)
|
7
|
+
Please update your custom converters to accept and use the state hash, for
|
8
|
+
examples look into exisiting standard converters.
|
9
|
+
- Use OptionParser for command line options, thanks @grmartin (#55)
|
10
|
+
- Tag border behavior is now configurable with the `tag_border` option, thanks @faheemmughal (#59)
|
11
|
+
- Preserve > and < from original markup, thanks @willglynn (#58)
|
12
|
+
|
4
13
|
## 0.8.2 - May 2015
|
5
14
|
### Changes
|
6
15
|
- Don't add whitespaces in links and images if they contain underscores
|
data/README.md
CHANGED
@@ -67,6 +67,9 @@ The following options are available:
|
|
67
67
|
- `bypass` - Ignore the unknown tag but try to convert its content
|
68
68
|
- `raise` - Raise an error to let you know
|
69
69
|
- `github_flavored` (default `false`) - use [github flavored markdown](https://help.github.com/articles/github-flavored-markdown) (yet only code blocks are supported)
|
70
|
+
- `tag_border` (default `' '`) - how to handle tag borders. valid options are:
|
71
|
+
- `' '` - Add whitespace if there is none at tag borders.
|
72
|
+
- `''` - Do not not add whitespace.
|
70
73
|
|
71
74
|
### As options
|
72
75
|
|
@@ -84,6 +87,7 @@ Or configure it block style on a initializer level. These configurations will la
|
|
84
87
|
ReverseMarkdown.config do |config|
|
85
88
|
config.unknown_tags = :bypass
|
86
89
|
config.github_flavored = true
|
90
|
+
config.tag_border = ''
|
87
91
|
end
|
88
92
|
```
|
89
93
|
|
@@ -108,3 +112,6 @@ Thanks to all [contributors](https://github.com/xijo/reverse_markdown/graphs/con
|
|
108
112
|
- [danschultzer](https://github.com/danschultzer) Dan Schultzer
|
109
113
|
- [Benjamin-Dobell](https://github.com/Benjamin-Dobell) Benjamin Dobell
|
110
114
|
- [schkovich](https://github.com/schkovich) Goran Miskovic
|
115
|
+
- [craig-day](https://github.com/craig-day) Craig Day
|
116
|
+
- [grmartin](https://github.com/grmartin) Glenn R. Martin
|
117
|
+
- [willglynn](https://github.com/willglynn) Will Glynn
|
data/bin/reverse_markdown
CHANGED
@@ -2,4 +2,14 @@
|
|
2
2
|
# Usage: reverse_markdown [FILE]...
|
3
3
|
# Usage: cat FILE | reverse_markdown
|
4
4
|
require 'reverse_markdown'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: reverse_markdown [options] <file>"
|
10
|
+
|
11
|
+
opts.on('-u', '--unknown_tags [pass_through, drop, bypass, raise]', 'Unknown tag handling (default: pass_through)') { |v| ReverseMarkdown.config.unknown_tags = v }
|
12
|
+
opts.on('-g', '--github_flavored bool', 'use github flavored markdown (default: false)') { |v| ReverseMarkdown.config.github_flavored = v }
|
13
|
+
end.parse!
|
14
|
+
|
5
15
|
puts ReverseMarkdown.convert(ARGF.read)
|
@@ -31,19 +31,19 @@ module ReverseMarkdown
|
|
31
31
|
# Same for underscores and brackets.
|
32
32
|
def clean_tag_borders(string)
|
33
33
|
result = string.gsub(/\s?\*{2,}.*?\*{2,}\s?/) do |match|
|
34
|
-
preserve_border_whitespaces(match, default_border:
|
34
|
+
preserve_border_whitespaces(match, default_border: ReverseMarkdown.config.tag_border) do
|
35
35
|
match.strip.sub('** ', '**').sub(' **', '**')
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
result = result.gsub(/\s?\_{2,}.*?\_{2,}\s?/) do |match|
|
40
|
-
preserve_border_whitespaces(match, default_border:
|
40
|
+
preserve_border_whitespaces(match, default_border: ReverseMarkdown.config.tag_border) do
|
41
41
|
match.strip.sub('__ ', '__').sub(' __', '__')
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
result = result.gsub(/\s?~{2,}.*?~{2,}\s?/) do |match|
|
46
|
-
preserve_border_whitespaces(match, default_border:
|
46
|
+
preserve_border_whitespaces(match, default_border: ReverseMarkdown.config.tag_border) do
|
47
47
|
match.strip.sub('~~ ', '~~').sub(' ~~', '~~')
|
48
48
|
end
|
49
49
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
class Config
|
3
|
-
attr_accessor :unknown_tags, :github_flavored
|
3
|
+
attr_accessor :unknown_tags, :github_flavored, :tag_border
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@unknown_tags = :pass_through
|
7
7
|
@github_flavored = false
|
8
|
-
@em_delimiter = '_'
|
9
|
-
@strong_delimiter = '**'
|
8
|
+
@em_delimiter = '_'.freeze
|
9
|
+
@strong_delimiter = '**'.freeze
|
10
10
|
@inline_options = {}
|
11
|
+
@tag_border = ' '.freeze
|
11
12
|
end
|
12
13
|
|
13
14
|
def with(options = {})
|
@@ -24,5 +25,9 @@ module ReverseMarkdown
|
|
24
25
|
def github_flavored
|
25
26
|
@inline_options[:github_flavored] || @github_flavored
|
26
27
|
end
|
28
|
+
|
29
|
+
def tag_border
|
30
|
+
@inline_options[:tag_border] || @tag_border
|
31
|
+
end
|
27
32
|
end
|
28
33
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
module Converters
|
3
3
|
class Base
|
4
|
-
def treat_children(node)
|
4
|
+
def treat_children(node, state)
|
5
5
|
node.children.inject('') do |memo, child|
|
6
|
-
memo << treat(child)
|
6
|
+
memo << treat(child, state)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def treat(node)
|
11
|
-
ReverseMarkdown::Converters.lookup(node.name).convert(node)
|
10
|
+
def treat(node, state)
|
11
|
+
ReverseMarkdown::Converters.lookup(node.name).convert(node, state)
|
12
12
|
end
|
13
13
|
|
14
14
|
def escape_keychars(string)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
module Converters
|
3
3
|
class Blockquote < Base
|
4
|
-
def convert(node)
|
5
|
-
content = treat_children(node).strip
|
4
|
+
def convert(node, state = {})
|
5
|
+
content = treat_children(node, state).strip
|
6
6
|
content = ReverseMarkdown.cleaner.remove_newlines(content)
|
7
7
|
'> ' << content.lines.to_a.join('> ')
|
8
8
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
module Converters
|
3
3
|
class Del < Base
|
4
|
-
def convert(node)
|
5
|
-
content = treat_children(node)
|
6
|
-
if disabled? || content.strip.empty? || already_crossed_out
|
4
|
+
def convert(node, state = {})
|
5
|
+
content = treat_children(node, state.merge(already_crossed_out: true))
|
6
|
+
if disabled? || content.strip.empty? || state[:already_crossed_out]
|
7
7
|
content
|
8
8
|
else
|
9
9
|
"~~#{content}~~"
|
@@ -17,10 +17,6 @@ module ReverseMarkdown
|
|
17
17
|
def disabled?
|
18
18
|
!enabled?
|
19
19
|
end
|
20
|
-
|
21
|
-
def already_crossed_out?(node)
|
22
|
-
node.ancestors('del').size > 0 || node.ancestors('strike').size > 0
|
23
|
-
end
|
24
20
|
end
|
25
21
|
|
26
22
|
register :strike, Del.new
|
@@ -1,18 +1,14 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
module Converters
|
3
3
|
class Em < Base
|
4
|
-
def convert(node)
|
5
|
-
content = treat_children(node)
|
6
|
-
if content.strip.empty? || already_italic
|
4
|
+
def convert(node, state = {})
|
5
|
+
content = treat_children(node, state.merge(already_italic: true))
|
6
|
+
if content.strip.empty? || state[:already_italic]
|
7
7
|
content
|
8
8
|
else
|
9
9
|
"#{content[/^\s*/]}_#{content.strip}_#{content[/\s*$/]}"
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
13
|
-
def already_italic?(node)
|
14
|
-
node.ancestors('italic').size > 0 || node.ancestors('em').size > 0
|
15
|
-
end
|
16
12
|
end
|
17
13
|
|
18
14
|
register :em, Em.new
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
module Converters
|
3
3
|
class H < Base
|
4
|
-
def convert(node)
|
4
|
+
def convert(node, state = {})
|
5
5
|
prefix = '#' * node.name[/\d/].to_i
|
6
|
-
["\n", prefix, ' ', treat_children(node), "\n"].join
|
6
|
+
["\n", prefix, ' ', treat_children(node, state), "\n"].join
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
module Converters
|
3
3
|
class Li < Base
|
4
|
-
def convert(node)
|
5
|
-
content = treat_children(node)
|
6
|
-
indentation =
|
4
|
+
def convert(node, state = {})
|
5
|
+
content = treat_children(node, state)
|
6
|
+
indentation = indentation_from(state)
|
7
7
|
prefix = prefix_for(node)
|
8
8
|
"#{indentation}#{prefix}#{content.chomp}\n"
|
9
9
|
end
|
@@ -17,8 +17,8 @@ module ReverseMarkdown
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
length =
|
20
|
+
def indentation_from(state)
|
21
|
+
length = state.fetch(:ol_count, 0)
|
22
22
|
' ' * [length - 1, 0].max
|
23
23
|
end
|
24
24
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
module Converters
|
3
3
|
class Ol < Base
|
4
|
-
def convert(node)
|
5
|
-
|
4
|
+
def convert(node, state = {})
|
5
|
+
ol_count = state.fetch(:ol_count, 0) + 1
|
6
|
+
"\n" << treat_children(node, state.merge(ol_count: ol_count))
|
6
7
|
end
|
7
8
|
end
|
8
9
|
|
@@ -1,18 +1,14 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
module Converters
|
3
3
|
class Strong < Base
|
4
|
-
def convert(node)
|
5
|
-
content = treat_children(node)
|
6
|
-
if content.strip.empty? || already_strong
|
4
|
+
def convert(node, state = {})
|
5
|
+
content = treat_children(node, state.merge(already_strong: true))
|
6
|
+
if content.strip.empty? || state[:already_strong]
|
7
7
|
content
|
8
8
|
else
|
9
9
|
"#{content[/^\s*/]}**#{content.strip}**#{content[/\s*$/]}"
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
13
|
-
def already_strong?(node)
|
14
|
-
node.ancestors('strong').size > 0 || node.ancestors('b').size > 0
|
15
|
-
end
|
16
12
|
end
|
17
13
|
|
18
14
|
register :strong, Strong.new
|
@@ -29,12 +29,19 @@ module ReverseMarkdown
|
|
29
29
|
text = remove_inner_newlines(text)
|
30
30
|
text = escape_keychars(text)
|
31
31
|
|
32
|
-
preserve_keychars_within_backticks(text)
|
32
|
+
text = preserve_keychars_within_backticks(text)
|
33
|
+
text = preserve_tags(text)
|
34
|
+
|
35
|
+
text
|
33
36
|
end
|
34
37
|
|
35
38
|
def preserve_nbsp(text)
|
36
39
|
text.gsub(/\u00A0/, " ")
|
37
40
|
end
|
41
|
+
|
42
|
+
def preserve_tags(text)
|
43
|
+
text.gsub(/[<>]/, '>' => '\>', '<' => '\<')
|
44
|
+
end
|
38
45
|
|
39
46
|
def remove_border_newlines(text)
|
40
47
|
text.gsub(/\A\n+/, '').gsub(/\n+\z/, '')
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module ReverseMarkdown
|
2
2
|
module Converters
|
3
3
|
class Tr < Base
|
4
|
-
def convert(node)
|
5
|
-
content = treat_children(node).rstrip
|
4
|
+
def convert(node, state = {})
|
5
|
+
content = treat_children(node, state).rstrip
|
6
6
|
result = "|#{content}\n"
|
7
7
|
table_header_row?(node) ? result + underline_for(node) : result
|
8
8
|
end
|
data/spec/assets/basic.html
CHANGED
@@ -14,8 +14,8 @@
|
|
14
14
|
before <em> <em> <br /> </em> </em> and after em tags containing whitespace
|
15
15
|
<em><em>double em tags</em></em>
|
16
16
|
<p><em><em>double em tags in p tag</em></em></p>
|
17
|
-
<em> em with leading and trailing </em>whitespace
|
18
|
-
<em>
|
17
|
+
a<em> em with leading and trailing </em>whitespace
|
18
|
+
a<em>
|
19
19
|
em with extra leading and trailing
|
20
20
|
</em>whitespace
|
21
21
|
|
@@ -31,8 +31,8 @@
|
|
31
31
|
double strong tags containing whitespace
|
32
32
|
</strong>
|
33
33
|
</strong> after
|
34
|
-
<strong> strong with leading and trailing </strong>whitespace
|
35
|
-
<strong>
|
34
|
+
a<strong> strong with leading and trailing </strong>whitespace
|
35
|
+
a<strong>
|
36
36
|
strong with extra leading and trailing
|
37
37
|
</strong>whitespace
|
38
38
|
|
@@ -19,8 +19,8 @@ describe ReverseMarkdown do
|
|
19
19
|
it { is_expected.to match /before and after em tags containing whitespace/ }
|
20
20
|
it { is_expected.to match /_double em tags_/ }
|
21
21
|
it { is_expected.to match /_double em tags in p tag_/ }
|
22
|
-
it { is_expected.to match /_em with leading and trailing_ whitespace/ }
|
23
|
-
it { is_expected.to match /_em with extra leading and trailing_ whitespace/ }
|
22
|
+
it { is_expected.to match /a _em with leading and trailing_ whitespace/ }
|
23
|
+
it { is_expected.to match /a _em with extra leading and trailing_ whitespace/ }
|
24
24
|
|
25
25
|
it { is_expected.to match /\*\*strong tag content\*\*/ }
|
26
26
|
it { is_expected.to match /before and after empty strong tags/ }
|
@@ -28,8 +28,8 @@ describe ReverseMarkdown do
|
|
28
28
|
it { is_expected.to match /\*\*double strong tags\*\*/ }
|
29
29
|
it { is_expected.to match /\*\*double strong tags in p tag\*\*/ }
|
30
30
|
it { is_expected.to match /before \*\*double strong tags containing whitespace\*\* after/ }
|
31
|
-
it { is_expected.to match
|
32
|
-
it { is_expected.to match
|
31
|
+
it { is_expected.to match /a \*\*strong with leading and trailing\*\* whitespace/ }
|
32
|
+
it { is_expected.to match /a \*\*strong with extra leading and trailing\*\* whitespace/ }
|
33
33
|
|
34
34
|
it { is_expected.to match /_i tag content_/ }
|
35
35
|
it { is_expected.to match /\*\*b tag content\*\*/ }
|
@@ -61,46 +61,96 @@ describe ReverseMarkdown::Cleaner do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe '#clean_tag_borders' do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
64
|
+
context 'with default_border is set to space' do
|
65
|
+
before { ReverseMarkdown.config.tag_border = ' ' }
|
66
|
+
|
67
|
+
it 'removes not needed whitespaces from strong tags' do
|
68
|
+
input = "foo ** foobar ** bar"
|
69
|
+
result = cleaner.clean_tag_borders(input)
|
70
|
+
expect(result).to eq "foo **foobar** bar"
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'remotes leading or trailing whitespaces independently' do
|
74
|
+
input = "1 **fat ** 2 ** fat** 3"
|
75
|
+
result = cleaner.clean_tag_borders(input)
|
76
|
+
expect(result).to eq "1 **fat** 2 **fat** 3"
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'adds whitespaces if there are none' do
|
80
|
+
input = "1**fat**2"
|
81
|
+
result = cleaner.clean_tag_borders(input)
|
82
|
+
expect(result).to eq "1 **fat** 2"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "doesn't add whitespaces to underscore'ed elements if they are part of links" do
|
86
|
+
input = ""
|
87
|
+
result = cleaner.clean_tag_borders(input)
|
88
|
+
expect(result).to eq ""
|
89
|
+
end
|
90
|
+
|
91
|
+
it "still cleans up whitespaces that aren't inside a link" do
|
92
|
+
input = "now __italic __with following [under__scored](link)"
|
93
|
+
result = cleaner.clean_tag_borders(input)
|
94
|
+
expect(result).to eq "now __italic__ with following [under__scored](link)"
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'cleans italic stuff as well' do
|
98
|
+
input = "1 __italic __ 2 __ italic__ 3__italic __4"
|
99
|
+
result = cleaner.clean_tag_borders(input)
|
100
|
+
expect(result).to eq "1 __italic__ 2 __italic__ 3 __italic__ 4"
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'cleans strikethrough stuff as well' do
|
104
|
+
input = "1 ~~italic ~~ 2 ~~ italic~~ 3~~italic ~~4"
|
105
|
+
result = cleaner.clean_tag_borders(input)
|
106
|
+
expect(result).to eq "1 ~~italic~~ 2 ~~italic~~ 3 ~~italic~~ 4"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with default_border set to no space' do
|
111
|
+
before { ReverseMarkdown.config.tag_border = '' }
|
112
|
+
|
113
|
+
it 'removes not needed whitespaces from strong tags' do
|
114
|
+
input = "foo ** foobar ** bar"
|
115
|
+
result = cleaner.clean_tag_borders(input)
|
116
|
+
expect(result).to eq "foo **foobar** bar"
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'remotes leading or trailing whitespaces independently' do
|
120
|
+
input = "1 **fat ** 2 ** fat** 3"
|
121
|
+
result = cleaner.clean_tag_borders(input)
|
122
|
+
expect(result).to eq "1 **fat** 2 **fat** 3"
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'adds whitespaces if there are none' do
|
126
|
+
input = "1**fat**2"
|
127
|
+
result = cleaner.clean_tag_borders(input)
|
128
|
+
expect(result).to eq "1**fat**2"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "doesn't add whitespaces to underscore'ed elements if they are part of links" do
|
132
|
+
input = ""
|
133
|
+
result = cleaner.clean_tag_borders(input)
|
134
|
+
expect(result).to eq ""
|
135
|
+
end
|
136
|
+
|
137
|
+
it "still cleans up whitespaces that aren't inside a link" do
|
138
|
+
input = "now __italic __with following [under__scored](link)"
|
139
|
+
result = cleaner.clean_tag_borders(input)
|
140
|
+
expect(result).to eq "now __italic__with following [under__scored](link)"
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'cleans italic stuff as well' do
|
144
|
+
input = "1 __italic __ 2 __ italic__ 3__italic __4"
|
145
|
+
result = cleaner.clean_tag_borders(input)
|
146
|
+
expect(result).to eq "1 __italic__ 2 __italic__ 3__italic__4"
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'cleans strikethrough stuff as well' do
|
150
|
+
input = "1 ~~italic ~~ 2 ~~ italic~~ 3~~italic ~~4"
|
151
|
+
result = cleaner.clean_tag_borders(input)
|
152
|
+
expect(result).to eq "1 ~~italic~~ 2 ~~italic~~ 3~~italic~~4"
|
153
|
+
end
|
104
154
|
end
|
105
155
|
end
|
106
156
|
|
@@ -10,7 +10,7 @@ describe ReverseMarkdown::Converters::Strong do
|
|
10
10
|
|
11
11
|
it 'returns just the content if the strong tag is nested in another strong' do
|
12
12
|
input = node_for('<strong><strong>foo</strong></strong>')
|
13
|
-
expect(converter.convert(input.children.first)).to eq 'foo'
|
13
|
+
expect(converter.convert(input.children.first, already_strong: true)).to eq 'foo'
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'moves border whitespaces outside of the delimiters tag' do
|
@@ -28,6 +28,12 @@ describe ReverseMarkdown::Converters::Text do
|
|
28
28
|
expect(result).to eq "foo bar "
|
29
29
|
end
|
30
30
|
|
31
|
+
it 'keeps escaped HTML-ish characters' do
|
32
|
+
input = node_for("<p><foo></p>")
|
33
|
+
result = converter.convert(input)
|
34
|
+
expect(result).to eq '\<foo\>'
|
35
|
+
end
|
36
|
+
|
31
37
|
context 'within backticks' do
|
32
38
|
it "preserves single underscores" do
|
33
39
|
input = node_for("<p>`foo_bar`</p>")
|
@@ -6,13 +6,13 @@ describe ReverseMarkdown::Converters do
|
|
6
6
|
|
7
7
|
describe '.register and .unregister' do
|
8
8
|
it 'adds a converter mapping to the list' do
|
9
|
-
expect { converters.lookup(:foo) }.to raise_error
|
9
|
+
expect { converters.lookup(:foo) }.to raise_error ReverseMarkdown::UnknownTagError
|
10
10
|
|
11
11
|
converters.register :foo, :foobar
|
12
12
|
expect(converters.lookup(:foo)).to eq :foobar
|
13
13
|
|
14
14
|
converters.unregister :foo
|
15
|
-
expect { converters.lookup(:foo) }.to raise_error
|
15
|
+
expect { converters.lookup(:foo) }.to raise_error ReverseMarkdown::UnknownTagError
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
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.
|
4
|
+
version: 1.0.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: 2015-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
version: '0'
|
200
200
|
requirements: []
|
201
201
|
rubyforge_project: reverse_markdown
|
202
|
-
rubygems_version: 2.
|
202
|
+
rubygems_version: 2.4.8
|
203
203
|
signing_key:
|
204
204
|
specification_version: 4
|
205
205
|
summary: Convert html code into markdown.
|
@@ -241,3 +241,4 @@ test_files:
|
|
241
241
|
- spec/lib/reverse_markdown/converters_spec.rb
|
242
242
|
- spec/lib/reverse_markdown_spec.rb
|
243
243
|
- spec/spec_helper.rb
|
244
|
+
has_rdoc:
|