markdown_views 2.1.5 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c82ec3234bbe6ced6805a71e2fc6599a07e62a888cabd008d138adf2f4468af
4
- data.tar.gz: c000f602b7d9cfcfd1a1464ef87cf41dbce160fa183a770ba9411e8e9b74a354
3
+ metadata.gz: 563ffc66a2741675ca0d8579174a3701e36237ab3d39fd73f5fccd4104706512
4
+ data.tar.gz: 9730b4130817235c0a52faade6b4df34153ceef1bec554f3da7e4d261a583d17
5
5
  SHA512:
6
- metadata.gz: 721420b13bee7bc80d6d8aed3534774fac8d5fe8db2184b4ba579e366a7fc90260614607046bd716a80a410ee75844945d0e3b76167a8d8e6b1f63bd164be5d7
7
- data.tar.gz: 2979d488ae36e653e8f32b1f11fb19b0d7a5e1ba5d529a912c1de37e0df09081121e53ae9f9d1cd062d1ed38221bd5a4b4c0ac0c37643c6257fe5fa07beff752
6
+ metadata.gz: 3bac100dcce357cfc2faac72924a10df250cccce481ebfde0e78ddcd3df17fa1ab9f49123b73ef3b94968853aaad4012984c2a6d2a2d7b02e250c9c95a2615f7
7
+ data.tar.gz: 3d40e4f3a5789467ff6e978bdc2bc003765d5e52062049859780a7d4a885b19808735a22ba9ee80dd79f872065e06a5e47b62bdb4cc908add6b0378e2aa1df7d
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|
@@ -24,16 +24,31 @@ module MarkdownViews
24
24
  MarkdownViews.rouge_opts[:formatter] || Rouge::Formatters::HTML.new
25
25
  end
26
26
 
27
- # when removing comments, also cleans up leading whitespace.
28
- # if whitespace includes line feeds, leaves 1 behind to
29
- # avoid breaking markdown adjacent to comment.
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
30
  def strip_comments(input)
31
- # (\s*) leading whitespace
32
- # <!-- start of html comment
33
- # .*? any char, incl linefeed (for multi-line comments)
34
- # lazy (non-greedy): *?
35
- # --> end of html comment
36
- input.gsub(/(\s*)<!--.*?-->/m, '')
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, '')
37
52
  end
38
53
 
39
54
  def transform_code_blocks(doc)
@@ -1,3 +1,3 @@
1
1
  module MarkdownViews
2
- VERSION = '2.1.5'
2
+ VERSION = '2.2.0'
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.1'
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,62 @@
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
+ assert_equal "a\n c", strip_comments("a\n<!-- b --> c"), 'leading comment'
20
+ end
21
+
22
+ # only comment should vanish, without absorbing outside whitespace
23
+ def test_shared_line_multi_line_comments
24
+ assert_equal "14", strip_comments("1<!-- 2\n3 -->4"), 'no whitespace'
25
+ assert_equal "1 4", strip_comments("1 <!-- 2\n3 --> 4"), 'with whitespace'
26
+ assert_equal "1\n 4", strip_comments("1\n <!-- 2\n3 --> 4"), 'leading whitespace on comment'
27
+ assert_equal "1 \n4", strip_comments("1 <!-- 2\n3 --> \n4"), 'trailing whitespace on comment'
28
+ assert_equal "1 \n 4", strip_comments("1 \n<!-- 2\n3 --> 4"), 'trailing whitespace on line'
29
+ assert_equal "1 \n 4", strip_comments("1 <!-- 2\n3 -->\n 4"), 'leading whitespace on line'
30
+ end
31
+
32
+ # should make line vanish, including outside whitespace
33
+ def test_whole_line_single_line_comments
34
+ assert_equal "1\n3\n", strip_comments("1\n<!-- 2 -->\n3\n"), 'adjacent lines'
35
+ assert_equal "1\r\n3\r\n", strip_comments("1\r\n<!-- 2 -->\r\n3\r\n"), 'adjacent lines w/windows LF'
36
+ assert_equal "1\n\n\n3\n", strip_comments("1\n\n<!-- 2 -->\n\n3\n"), 'spaced lines'
37
+ assert_equal " 1\n 3\n", strip_comments(" 1\n <!-- 2 -->\n 3\n"), 'adjacent lines indented w/spaces'
38
+ assert_equal "\t1\n\t3\n", strip_comments("\t1\n\t<!-- 2 -->\n\t3\n"), 'adjacent lines indented w/tabs'
39
+ assert_equal " 1\n\n\n 3\n", strip_comments(" 1\n\n <!-- 2 -->\n\n 3\n"), 'spaced lines indented w/spaces'
40
+ assert_equal "1 \n \n4\t\n", strip_comments("1 \n \n<!-- 2 --> \n<!--3-->\t\n4\t\n"), 'spaced lines w/trailing whitespace'
41
+ end
42
+
43
+ # should make all lines vanish, including outside whitespace on same lines
44
+ def test_whole_line_multi_line_comments
45
+ assert_equal "1\n4\n", strip_comments("1\n<!-- 2\n3 -->\n4\n"), 'adjacent lines'
46
+ assert_equal "1\n\n\n4\n", strip_comments("1\n\n<!-- 2\n3 -->\n\n4\n"), 'spaced lines'
47
+ assert_equal " 1\n 4\n", strip_comments(" 1\n <!-- 2\n 3 -->\n 4\n"), 'adjacent lines indented w/spaces'
48
+ assert_equal "1 \n \n4\t\n", strip_comments("1 \n \n<!-- 2 \n3 -->\t\n4\t\n"), 'spaced lines w/trailing whitespace'
49
+ end
50
+
51
+
52
+ def strip_comments(*args)
53
+ MarkdownViews::Renderer.strip_comments(*args)
54
+ end
55
+
56
+ # hack to make diffs more understandable
57
+ # otherwise minitest sometimes truncates multi-lines diffs, making them unusable
58
+ def mu_pp(obj)
59
+ super obj.gsub("\n", '\n').gsub("\t", '\t')
60
+ end
61
+
62
+ 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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_views
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
@@ -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,23 +29,9 @@ 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
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '3.3'
40
- type: :runtime
41
- prerelease: false
42
- 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
34
+ name: rails
49
35
  requirement: !ruby/object:Gem::Requirement
50
36
  requirements:
51
37
  - - ">="
@@ -64,6 +50,20 @@ dependencies:
64
50
  - - "<"
65
51
  - !ruby/object:Gem::Version
66
52
  version: '6.1'
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'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
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,6 +144,8 @@ 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
@@ -153,4 +169,6 @@ rubygems_version: 3.0.6
153
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