unmarkdown 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/unmarkdown/parser.rb +12 -4
- data/lib/unmarkdown/version.rb +1 -1
- data/test/parser_test.rb +22 -0
- data/unmarkdown.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68e58ef7f5ad3f18f2f4aee2d450ff433cfdb927ee9564836bb9be4faac80370
|
4
|
+
data.tar.gz: e120e545f74052e2ea8362c242632de139876f1aaa95b54b5ee77e2956a22e50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eda7204e94c3f8865bf219af0de252121a891021cf608d429cc1c4bddec8dcb049a201151cb4e5176e40632812e692a464a47c73d24658a4f07adb9b51934fd5
|
7
|
+
data.tar.gz: 1e253bae1d7dc7e4301add86543bfaf2b37c0c936eeb25c4afc36ce0a59346ea3c16f2489b0fd55a7f60c26b34286fabd68c4c623638b1ba821f2b75ad0ea129
|
data/lib/unmarkdown/parser.rb
CHANGED
@@ -12,8 +12,15 @@ module Unmarkdown
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def parse
|
15
|
+
# If the HTML fragment starts with a comment, it is ignored. Add an
|
16
|
+
# enclosing body tag to ensure everything is included.
|
17
|
+
html = @html
|
18
|
+
unless html.include?('<body')
|
19
|
+
html = "<body>#{@html}</body>"
|
20
|
+
end
|
21
|
+
|
15
22
|
# Setup document
|
16
|
-
doc = Nokogiri::HTML(
|
23
|
+
doc = Nokogiri::HTML(html)
|
17
24
|
doc.encoding = 'UTF-8'
|
18
25
|
|
19
26
|
# Reset bookkeeping
|
@@ -117,10 +124,11 @@ module Unmarkdown
|
|
117
124
|
when 'script'
|
118
125
|
next unless @options[:allow_scripts]
|
119
126
|
output << node.to_html
|
120
|
-
|
121
|
-
# If it's an supported node or a node that just contains text, just get
|
122
|
-
# its content
|
127
|
+
when 'p'
|
123
128
|
output << parse_content(node)
|
129
|
+
else
|
130
|
+
# If it's an supported node or a node that just contains text, just append it
|
131
|
+
output << node.to_html
|
124
132
|
end
|
125
133
|
|
126
134
|
output << "\n\n" if BLOCK_ELEMENT_NAMES.include?(node.name)
|
data/lib/unmarkdown/version.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -153,4 +153,26 @@ class ParserTest < Unmarkdown::Test
|
|
153
153
|
markdown = 'Head to <http://soff.es> and email <sam@soff.es>'
|
154
154
|
assert_equal markdown, parse(html, autolink: true)
|
155
155
|
end
|
156
|
+
|
157
|
+
def test_unknown
|
158
|
+
html = %Q{Some custom tag: <expand-note>hello</expand-note>. <span class="spoiler">a secret</span>}
|
159
|
+
assert_equal html, parse(html)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_comments
|
163
|
+
html = %Q{<!--One-line comment by itself-->
|
164
|
+
|
165
|
+
Line with an <!--inline comment--> inside
|
166
|
+
|
167
|
+
<!--
|
168
|
+
Block comment
|
169
|
+
-->
|
170
|
+
|
171
|
+
surrounding stuff
|
172
|
+
<!--
|
173
|
+
Block comment
|
174
|
+
-->
|
175
|
+
surrounding stuff}
|
176
|
+
assert_equal html, parse(html)
|
177
|
+
end
|
156
178
|
end
|
data/unmarkdown.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unmarkdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Soffes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.1.2
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Convert HTML to Markdown
|