markdown_views 2.1.2 → 2.2.1

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: 28a2126be795fb88f32731b85c5fbdede07be1f7599497a8b9dead6d1c777050
4
- data.tar.gz: 764aa9f22d74e6bccaeabbbd091821d9bdf17ec9bb94e495fa8acf8eb233ac20
3
+ metadata.gz: 25a0fb5b00066a055d0b4c233759673fcd610526e49f2032895fe2fddc3eaf28
4
+ data.tar.gz: 151a7d490fef3d447bf5e696974fbd3f74bb53264a908bf778636a2aafb877ce
5
5
  SHA512:
6
- metadata.gz: 2ba620b6720c78b88c368952af15fd7fca3b04ef0c653646e803c339b9a30be5d2bc3b6b15d46496250edcd09f05a792e9ff3c994dd8b31b45116120d320858f
7
- data.tar.gz: 95a238c3c16111c483b49f7e8f7651600c326626d62266b9a903adf8d2dbe3c2daa9b8f5961a42d583f2b324cee1fa790a0b7fdff57ebdb0704b8c126f8cdb68
6
+ metadata.gz: '009af435d553af463e18ecf712701e90bdd061658640606fa0243d9bd6207235eef7dffeacb5519730416bafc2f34272478919efb2965bfc63950686af43e9e7'
7
+ data.tar.gz: b7a7393c0a961f4ecb5ac4caf490209aff862cae5e7ceb2876a847394ed3b2cb905f380fbaaaf505b5e6a964949fa97ab61efd178046ade2304541e6f784668c
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2019 thomas morgan
1
+ Copyright (c) 2014-2020 thomas morgan
2
2
 
3
3
  MIT License
4
4
 
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
2
3
 
3
4
  task :generate_stylesheet do
4
5
  %w( base16.light base16.dark base16.solarized.light base16.solarized.dark
@@ -9,3 +10,12 @@ task :generate_stylesheet do
9
10
  `rougify style #{theme} --scope .rouge-highlight > app/assets/stylesheets/rouge.#{theme}.css`
10
11
  end
11
12
  end
13
+
14
+
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << "test"
17
+ t.libs << "lib"
18
+ t.test_files = FileList["test/**/*_test.rb"]
19
+ end
20
+
21
+ task :default => :test
@@ -1,5 +1,6 @@
1
1
  require 'action_view'
2
2
  require 'commonmarker'
3
+ require 'rails'
3
4
  require 'rouge'
4
5
 
5
6
  %w(config engine handler renderer version).each do |f|
@@ -4,9 +4,9 @@ module MarkdownViews
4
4
 
5
5
  def render(template)
6
6
  out = template.to_s
7
- strip_comments!(out) if MarkdownViews.strip_comments
7
+ out = strip_comments(out) if MarkdownViews.strip_comments
8
8
  out = render_md(out)
9
- strip_comments!(out) if MarkdownViews.strip_comments
9
+ out = strip_comments(out) if MarkdownViews.strip_comments
10
10
  out.html_safe
11
11
  end
12
12
 
@@ -24,8 +24,31 @@ module MarkdownViews
24
24
  MarkdownViews.rouge_opts[:formatter] || Rouge::Formatters::HTML.new
25
25
  end
26
26
 
27
- def strip_comments!(input)
28
- input.gsub!(/[ \t\r\n\f]*<!--(.*?)-->*/m, '')
27
+ # removes single & multi-line comments
28
+ # if any content besides comment & whitespace is on same line(s), strips just the comment.
29
+ # if no other content, strips the lines & whitespace too.
30
+ def strip_comments(input)
31
+ # ^[ \t]*(<!--.*?-->)++[ \t]*\r?\n lines with just comments
32
+ # | or
33
+ # <!--.*?--> comments on lines with other content
34
+ #
35
+ # ^ start of line
36
+ # [ \t]* optional spaces or tabs
37
+ # (<!--.*?-->)++
38
+ # <!-- start of html comment
39
+ # .*? any char, incl linefeed (for multi-line comments)
40
+ # lazy (non-greedy): *?
41
+ # --> end of html comment
42
+ # ++ possessive match - prevents a match across comment boundaries
43
+ # ie: prevent matching this: <!-- a --> keep <!-- b -->
44
+ # explanation: initially .*? will refuse to match --> because it's
45
+ # non-greedy. but, in search of pre/post whitespace, the regex engine
46
+ # could backtrack and ask .*? to match an --> as long as there's
47
+ # another --> later. possessive disables the backtracking.
48
+ # can combine <!-- a --><!-- b --> into one match, which is of no harm.
49
+ # [ \t]* optional spaces or tabs
50
+ # \r?\n end of line (either unix or windows style)
51
+ input.gsub(/^[ \t]*(<!--.*?-->)++[ \t]*\r?\n|<!--.*?-->/m, '')
29
52
  end
30
53
 
31
54
  def transform_code_blocks(doc)
@@ -1,3 +1,3 @@
1
1
  module MarkdownViews
2
- VERSION = '2.1.2'
2
+ VERSION = '2.2.1'
3
3
  end
@@ -18,10 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'commonmarker', '>= 0.18.2', '< 0.21'
21
+ spec.add_dependency 'commonmarker', '>= 0.18.2', '< 0.22'
22
+ spec.add_dependency 'rails', '>= 5.0', '< 6.2'
22
23
  spec.add_dependency 'rouge', '~> 3.3'
23
- spec.add_dependency 'actionpack', '>= 5.0', '< 6.1'
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "minitest-reporters"
26
27
  spec.add_development_dependency "rake"
27
28
  end
@@ -0,0 +1,67 @@
1
+ require "test_helper"
2
+
3
+ class StripCommentsTest < Minitest::Test
4
+
5
+ def test_not_greedy
6
+ assert_equal "ace", strip_comments("a<!-- b -->c<!-- d -->e")
7
+ assert_equal "a\nc\nd\nf", strip_comments("a\n<!-- b -->c\nd<!-- e -->\nf")
8
+ end
9
+
10
+ # only comment should vanish, without absorbing any outside whitespace
11
+ def test_intra_line_comments
12
+ assert_equal "ac", strip_comments("a<!-- b -->c"), 'no whitespace'
13
+ assert_equal "\nac\n", strip_comments("\na<!-- b -->c\n"), 'no whitespace, with linefeeds'
14
+ assert_equal "a c", strip_comments("a <!-- b -->c"), 'left whitespace'
15
+ assert_equal "a c", strip_comments("a<!-- b --> c"), 'right whitespace'
16
+ assert_equal "a c", strip_comments("a <!-- b --> c"), 'double whitespace'
17
+ assert_equal "ac", strip_comments("a<!--b-->c"), 'comment w/o whitespace'
18
+ assert_equal "a \nc", strip_comments("a <!-- b -->\nc"), 'trailing comment'
19
+ # could drop trailing space, but is unnecessary
20
+ assert_equal "a\n c", strip_comments("a\n<!-- b --> c"), 'leading comment'
21
+ end
22
+
23
+ # only comment should vanish, without absorbing outside whitespace
24
+ def test_shared_line_multi_line_comments
25
+ assert_equal "14", strip_comments("1<!-- 2\n3 -->4"), 'no whitespace'
26
+ assert_equal "1 4", strip_comments("1 <!-- 2\n3 --> 4"), 'with whitespace'
27
+ assert_equal "1\n 4", strip_comments("1\n <!-- 2\n3 --> 4"), 'leading whitespace on comment'
28
+ # ^
29
+ # should this absorb whitespace (preceeding line 2) on an otherwise empty line? ... debatable
30
+ assert_equal "1 \n4", strip_comments("1 <!-- 2\n3 --> \n4"), 'trailing whitespace on comment'
31
+ # ^
32
+ # this one too (the space following 3)?
33
+ assert_equal "1 \n 4", strip_comments("1 \n<!-- 2\n3 --> 4"), 'trailing whitespace on line'
34
+ assert_equal "1 \n 4", strip_comments("1 <!-- 2\n3 -->\n 4"), 'leading whitespace on line'
35
+ end
36
+
37
+ # should make line vanish, including outside whitespace
38
+ def test_whole_line_single_line_comments
39
+ assert_equal "1\n3\n", strip_comments("1\n<!-- 2 -->\n3\n"), 'adjacent lines'
40
+ assert_equal "1\r\n3\r\n", strip_comments("1\r\n<!-- 2 -->\r\n3\r\n"), 'adjacent lines w/windows LF'
41
+ assert_equal "1\n\n\n3\n", strip_comments("1\n\n<!-- 2 -->\n\n3\n"), 'spaced lines'
42
+ assert_equal " 1\n 3\n", strip_comments(" 1\n <!-- 2 -->\n 3\n"), 'adjacent lines indented w/spaces'
43
+ assert_equal "\t1\n\t3\n", strip_comments("\t1\n\t<!-- 2 -->\n\t3\n"), 'adjacent lines indented w/tabs'
44
+ assert_equal " 1\n\n\n 3\n", strip_comments(" 1\n\n <!-- 2 -->\n\n 3\n"), 'spaced lines indented w/spaces'
45
+ assert_equal "1 \n \n4\t\n", strip_comments("1 \n \n<!-- 2 --> \n<!--3-->\t\n4\t\n"), 'spaced lines w/trailing whitespace'
46
+ end
47
+
48
+ # should make all lines vanish, including outside whitespace on same lines
49
+ def test_whole_line_multi_line_comments
50
+ assert_equal "1\n4\n", strip_comments("1\n<!-- 2\n3 -->\n4\n"), 'adjacent lines'
51
+ assert_equal "1\n\n\n4\n", strip_comments("1\n\n<!-- 2\n3 -->\n\n4\n"), 'spaced lines'
52
+ assert_equal " 1\n 4\n", strip_comments(" 1\n <!-- 2\n 3 -->\n 4\n"), 'adjacent lines indented w/spaces'
53
+ assert_equal "1 \n \n4\t\n", strip_comments("1 \n \n<!-- 2 \n3 -->\t\n4\t\n"), 'spaced lines w/trailing whitespace'
54
+ end
55
+
56
+
57
+ def strip_comments(*args)
58
+ MarkdownViews::Renderer.strip_comments(*args)
59
+ end
60
+
61
+ # hack to make diffs more understandable
62
+ # otherwise minitest sometimes truncates multi-lines diffs, making them unusable
63
+ def mu_pp(obj)
64
+ super obj.gsub("\n", '\n').gsub("\t", '\t')
65
+ end
66
+
67
+ end
@@ -0,0 +1,7 @@
1
+ require 'minitest/reporters'
2
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
3
+
4
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
+ require "markdown_views"
6
+
7
+ require "minitest/autorun"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_views
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-08 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commonmarker
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 0.18.2
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '0.21'
22
+ version: '0.22'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,41 +29,41 @@ dependencies:
29
29
  version: 0.18.2
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '0.21'
32
+ version: '0.22'
33
33
  - !ruby/object:Gem::Dependency
34
- name: rouge
34
+ name: rails
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '3.3'
39
+ version: '5.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6.2'
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '3.3'
47
- - !ruby/object:Gem::Dependency
48
- name: actionpack
49
- requirement: !ruby/object:Gem::Requirement
50
46
  requirements:
51
47
  - - ">="
52
48
  - !ruby/object:Gem::Version
53
49
  version: '5.0'
54
50
  - - "<"
55
51
  - !ruby/object:Gem::Version
56
- version: '6.1'
52
+ version: '6.2'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rouge
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.3'
57
60
  type: :runtime
58
61
  prerelease: false
59
62
  version_requirements: !ruby/object:Gem::Requirement
60
63
  requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: '5.0'
64
- - - "<"
64
+ - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: '6.1'
66
+ version: '3.3'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: bundler
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -78,6 +78,20 @@ dependencies:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
80
  version: '1.5'
81
+ - !ruby/object:Gem::Dependency
82
+ name: minitest-reporters
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
81
95
  - !ruby/object:Gem::Dependency
82
96
  name: rake
83
97
  requirement: !ruby/object:Gem::Requirement
@@ -130,11 +144,13 @@ files:
130
144
  - lib/markdown_views/renderer.rb
131
145
  - lib/markdown_views/version.rb
132
146
  - markdown_views.gemspec
147
+ - test/strip_comments_test.rb
148
+ - test/test_helper.rb
133
149
  homepage: https://github.com/zarqman/markdown_views
134
150
  licenses:
135
151
  - MIT
136
152
  metadata: {}
137
- post_install_message:
153
+ post_install_message:
138
154
  rdoc_options: []
139
155
  require_paths:
140
156
  - lib
@@ -149,8 +165,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
165
  - !ruby/object:Gem::Version
150
166
  version: '0'
151
167
  requirements: []
152
- rubygems_version: 3.0.3
153
- signing_key:
168
+ rubygems_version: 3.0.8
169
+ signing_key:
154
170
  specification_version: 4
155
171
  summary: Add .md template handler to Rails.
156
- test_files: []
172
+ test_files:
173
+ - test/strip_comments_test.rb
174
+ - test/test_helper.rb