markdown_views 2.1.3 → 2.2.2

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: 5df0161956a6cf0a692de3844b8eaabd3839c63a3efeb00e4b5253f4003f0339
4
- data.tar.gz: 1a297c19d39d6a69d5111dae58fe7625117a9c2615d52a928a9b68e93d73ddf2
3
+ metadata.gz: b8226d152dfa2b2d6b58d36ca7166f3b054c2d7ae9e464225d2ce667f53a4c36
4
+ data.tar.gz: 4f5f16391b55c1f6690f6a24f15e7cc093fcf2eda47c089673b3087e47bd8a10
5
5
  SHA512:
6
- metadata.gz: f51a26f78fa1e5c559cf7e84e13106bdbbb42e9fc9faa70a29de76bb69a9af277fd0f658b2a4301831c1e619803d05c8bc824e5f1a138d721677a4868e4cc035
7
- data.tar.gz: 33f92ccec6e6c8c3d4134c77fd2fe162b5216703cd797e3d188080a1a989a844abacd22ba865a2d345a577d3df7b94b81725f121ad8e8fdf1159d29247ca68ef
6
+ metadata.gz: e99cc7b66a92d4d99da9d516b78d0302f0c7f30313168bc732a15201f64c1be56a3f2e7e0fee355ccf63321b805317b81519065e268f56a65c4c63079657c3b9
7
+ data.tar.gz: 89c8f06becaa43ed2449ac8a822fb41ff96e45426a9d9d470a85014e07535c40cd126a53940513ed144f584d02eeeb928862af6b932c0a13beea1a443ff69efd
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2019 thomas morgan
1
+ Copyright (c) 2014-2021 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|
@@ -24,8 +24,31 @@ module MarkdownViews
24
24
  MarkdownViews.rouge_opts[:formatter] || Rouge::Formatters::HTML.new
25
25
  end
26
26
 
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.
27
30
  def strip_comments(input)
28
- input.gsub(/[ \t\r\n\f]*<!--(.*?)-->*/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, '')
29
52
  end
30
53
 
31
54
  def transform_code_blocks(doc)
@@ -1,3 +1,3 @@
1
1
  module MarkdownViews
2
- VERSION = '2.1.3'
2
+ VERSION = '2.2.2'
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.23'
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
- spec.add_development_dependency "bundler", "~> 1.5"
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,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.3
4
+ version: 2.2.2
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-12-26 00:00:00.000000000 Z
11
+ date: 2021-06-23 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.23'
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.23'
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
  - - ">="
@@ -53,7 +39,7 @@ dependencies:
53
39
  version: '5.0'
54
40
  - - "<"
55
41
  - !ruby/object:Gem::Version
56
- version: '6.1'
42
+ version: '6.2'
57
43
  type: :runtime
58
44
  prerelease: false
59
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -63,21 +49,35 @@ dependencies:
63
49
  version: '5.0'
64
50
  - - "<"
65
51
  - !ruby/object:Gem::Version
66
- version: '6.1'
52
+ version: '6.2'
67
53
  - !ruby/object:Gem::Dependency
68
- name: bundler
54
+ name: rouge
69
55
  requirement: !ruby/object:Gem::Requirement
70
56
  requirements:
71
57
  - - "~>"
72
58
  - !ruby/object:Gem::Version
73
- version: '1.5'
74
- type: :development
59
+ version: '3.3'
60
+ type: :runtime
75
61
  prerelease: false
76
62
  version_requirements: !ruby/object:Gem::Requirement
77
63
  requirements:
78
64
  - - "~>"
79
65
  - !ruby/object:Gem::Version
80
- version: '1.5'
66
+ version: '3.3'
67
+ - !ruby/object:Gem::Dependency
68
+ name: minitest-reporters
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rake
83
83
  requirement: !ruby/object:Gem::Requirement
@@ -130,11 +130,13 @@ files:
130
130
  - lib/markdown_views/renderer.rb
131
131
  - lib/markdown_views/version.rb
132
132
  - markdown_views.gemspec
133
+ - test/strip_comments_test.rb
134
+ - test/test_helper.rb
133
135
  homepage: https://github.com/zarqman/markdown_views
134
136
  licenses:
135
137
  - MIT
136
138
  metadata: {}
137
- post_install_message:
139
+ post_install_message:
138
140
  rdoc_options: []
139
141
  require_paths:
140
142
  - lib
@@ -149,8 +151,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
151
  - !ruby/object:Gem::Version
150
152
  version: '0'
151
153
  requirements: []
152
- rubygems_version: 3.0.3
153
- signing_key:
154
+ rubygems_version: 3.2.15
155
+ signing_key:
154
156
  specification_version: 4
155
157
  summary: Add .md template handler to Rails.
156
- test_files: []
158
+ test_files:
159
+ - test/strip_comments_test.rb
160
+ - test/test_helper.rb