devcenter-parser 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/devcenter-parser.rb +17 -17
- data/test/devcenter-parser_test.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3431e9dabf9d7ca6f57b68cdfdcc3072cb78f6ef
|
4
|
+
data.tar.gz: f598db39a54c8a0d2dc1790a9e892251bc39a474
|
5
5
|
!binary "U0hBNTEy":
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c8a1f16903ec6d5c0028e61f28bcdd0953366fc7e549f8b330d4bd027c9687be2bf14a18a0a08b395ee232b4f4e4566c245a6fdb85f3cc98dfd1af2161ae941
|
7
|
+
data.tar.gz: 63cf77e86c96ce0f00bd8d3db171826e04bbf6b6cb62797dbc32ee4dd17efa8f155bb3b0a46da83ba675e3c99681f9918d88f5df844e7d6654f83d42ac1ffb13
|
data/lib/devcenter-parser.rb
CHANGED
@@ -6,7 +6,7 @@ require 'sanitize'
|
|
6
6
|
|
7
7
|
module DevcenterParser
|
8
8
|
|
9
|
-
VERSION = '1.3.
|
9
|
+
VERSION = '1.3.5'
|
10
10
|
|
11
11
|
AVAILABLE_FLAVOURS = [:github, :maruku]
|
12
12
|
|
@@ -23,23 +23,8 @@ module DevcenterParser
|
|
23
23
|
sanitize(html)
|
24
24
|
end
|
25
25
|
|
26
|
-
# The current parsers consider something like:
|
27
|
-
# > foo
|
28
|
-
#
|
29
|
-
# > bar
|
30
|
-
# as a single blockquote, while we want it to be two different ones.
|
31
|
-
# This method adds an empty paragraph between consecutive blocks so parsers process them separately
|
32
|
-
def self.separate_consecutive_blockquote_blocks(markdown)
|
33
|
-
separator = '<p class="devcenter-parser-special-block-separator" style="display:none"> </p>'
|
34
|
-
markdown.gsub(/^>(.*)?\s\s>/, '>\1' + "\n\n#{separator}\n\n>")
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.normalize_newlines(markdown)
|
38
|
-
markdown.lines.map{ |l| l.chomp }.join("\n")
|
39
|
-
end
|
40
|
-
|
41
26
|
def self.to_unsanitized_html(markdown, flavour)
|
42
|
-
markdown = normalize_newlines(markdown)
|
27
|
+
markdown = normalize_newlines(markdown.to_s)
|
43
28
|
markdown = separate_consecutive_blockquote_blocks(markdown)
|
44
29
|
doc = case flavour.to_sym
|
45
30
|
when :maruku
|
@@ -71,6 +56,21 @@ module DevcenterParser
|
|
71
56
|
|
72
57
|
private
|
73
58
|
|
59
|
+
# The current parsers consider something like:
|
60
|
+
# > foo
|
61
|
+
#
|
62
|
+
# > bar
|
63
|
+
# as a single blockquote, while we want it to be two different ones.
|
64
|
+
# This method adds an empty paragraph between consecutive blocks so parsers process them separately
|
65
|
+
def self.separate_consecutive_blockquote_blocks(markdown)
|
66
|
+
separator = '<p class="devcenter-parser-special-block-separator" style="display:none"> </p>'
|
67
|
+
markdown.gsub(/^>(.*)?\s\s>/, '>\1' + "\n\n#{separator}\n\n>")
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.normalize_newlines(markdown)
|
71
|
+
markdown.lines.map{ |l| l.chomp }.join("\n")
|
72
|
+
end
|
73
|
+
|
74
74
|
def self.github_parser
|
75
75
|
@@github_parser ||= Redcarpet::Markdown.new(HTMLWithPantsRenderer, fenced_code_blocks: true, tables: true)
|
76
76
|
end
|
@@ -5,15 +5,27 @@ require_relative '../lib/devcenter-parser'
|
|
5
5
|
describe 'DevcenterParser' do
|
6
6
|
|
7
7
|
describe '.to_unsanitized_html' do
|
8
|
+
|
9
|
+
it 'returns empty string for nil input' do
|
10
|
+
assert_parsing_unsanitized_result nil, :maruku, ''
|
11
|
+
assert_parsing_unsanitized_result nil, :maruku, ''
|
12
|
+
end
|
13
|
+
|
8
14
|
it 'maintains script tags' do
|
9
15
|
md = '<script>alert("hi")</script>'
|
10
16
|
assert_parsing_unsanitized_result md, :maruku, md
|
11
17
|
assert_parsing_unsanitized_result md, :github, '<script>alert("hi")</script>'
|
12
18
|
end
|
19
|
+
|
13
20
|
end
|
14
21
|
|
15
22
|
describe '.to_html' do
|
16
23
|
|
24
|
+
it 'returns empty string for nil input' do
|
25
|
+
assert_maruku_result nil, ''
|
26
|
+
assert_github_result nil, ''
|
27
|
+
end
|
28
|
+
|
17
29
|
it 'raises InvalidMarkdownError when parsing invalid markdown' do
|
18
30
|
md = '[foo](bar'
|
19
31
|
assert_raises DevcenterParser::InvalidMarkdownError do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devcenter-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heroku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: maruku
|