mato 2.1.3 → 2.3.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: ae49205cffd8bb04eda2cb06753f69b22fa00fe306e5bfb1b6272aa6798548df
4
- data.tar.gz: 4c81ac4ccd5452847ac8bee9f5da87923c91f0aa11b4808497ce278a82f4308c
3
+ metadata.gz: 74c9936ed1ef8bc63b7b0785597f92f4100dad15c432ebf5b6b0bfa5681a2d03
4
+ data.tar.gz: 8234e66b936b71bbb25d60e5a2df5cbd1a11903c724fab6a0f2c64e22dcc3c3d
5
5
  SHA512:
6
- metadata.gz: 9d9d711ec47f52a5b5835172c3884b2ccc1b3b23ca0bc7374b7693d72c562ce0546f8e427a957b20c4527e1d434efef1fb20409199516fba9ed057b7a4725be5
7
- data.tar.gz: fcbab2b0c37a2d7272361c41e972a6ae7531ee2c10e349342fb526556b5a78ea7d1ba9729596a173d814e9673cc7403535da0517c6076b4c0969f7374055cfab
6
+ metadata.gz: b21e6c3a89540d0775ff30eccefa0f755b5c9f9dd2ac17d40c0d6818430b68222b34bfa06d6337e55c4c52f890dbf308d5cb8b466c02a0f87fb345d45352372c
7
+ data.tar.gz: 8fb4996b32a9bbaf34091f7c34fc2e6b03a7fb2899561b98b40cc0e130a024063d0d3e190b751817444e23b9b6c063d67e702dcde77a651aaaffcda5076226f4
@@ -1,11 +1,16 @@
1
1
  # See also https://github.com/onk/onkcop/blob/master/config/rubocop.yml
2
+ require:
3
+ - rubocop-performance
2
4
 
3
5
  AllCops:
4
- TargetRubyVersion: 2.3
6
+ TargetRubyVersion: 2.4
5
7
  DisplayCopNames: true
6
8
  Exclude:
7
9
  - bin/**/*
8
10
 
11
+ Metrics:
12
+ Enabled: false
13
+
9
14
  Lint/UnusedBlockArgument:
10
15
  Enabled: false
11
16
 
@@ -21,31 +26,7 @@ Layout/MultilineMethodCallIndentation:
21
26
  Layout/EmptyLinesAroundClassBody:
22
27
  Enabled: false
23
28
 
24
- Metrics/AbcSize:
25
- Max: 35
26
-
27
- Metrics/PerceivedComplexity:
28
- Max: 10
29
-
30
- Metrics/CyclomaticComplexity:
31
- Max: 10
32
-
33
- Metrics/ClassLength:
34
- Enabled: false
35
-
36
- Metrics/BlockLength:
37
- Enabled: false
38
-
39
- Metrics/LineLength:
40
- Enabled: false
41
-
42
- Metrics/MethodLength:
43
- Max: 45
44
-
45
- Metrics/ModuleLength:
46
- Enabled: false
47
-
48
- Metrics/ParameterLists:
29
+ Layout/LineLength:
49
30
  Enabled: false
50
31
 
51
32
  Style/RescueStandardError:
@@ -63,6 +44,12 @@ Style/Documentation:
63
44
  Naming/FileName:
64
45
  Enabled: false
65
46
 
47
+ Naming/MethodParameterName:
48
+ Enabled: false
49
+
50
+ Naming/RescuedExceptionsVariableName:
51
+ Enabled: false
52
+
66
53
  Style/GuardClause:
67
54
  Enabled: false
68
55
 
@@ -120,6 +107,9 @@ Style/AsciiComments:
120
107
  Style/EmptyMethod:
121
108
  EnforcedStyle: expanded
122
109
 
110
+ Style/RaiseArgs:
111
+ Enabled: false
112
+
123
113
  Naming/VariableNumber:
124
114
  Enabled: false
125
115
 
@@ -146,3 +136,20 @@ Style/NonNilCheck:
146
136
 
147
137
  Performance/RedundantBlockCall:
148
138
  Enabled: false
139
+
140
+ # Configure pending cops
141
+
142
+ Layout/SpaceAroundMethodCallOperator:
143
+ Enabled: true
144
+ Lint/RaiseException:
145
+ Enabled: true
146
+ Lint/StructNewOverride:
147
+ Enabled: true
148
+ Style/ExponentialNotation:
149
+ Enabled: true
150
+ Style/HashEachMethods:
151
+ Enabled: true
152
+ Style/HashTransformKeys:
153
+ Enabled: true
154
+ Style/HashTransformValues:
155
+ Enabled: true
@@ -1,8 +1,7 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
- - 2.3
5
- - 2.4
3
+ - 2.7
4
+ - 3.0
6
5
  - ruby-head
7
6
 
8
7
  matrix:
@@ -1,5 +1,31 @@
1
1
  # The revision history of Mato
2
2
 
3
+ ## v2.3.2 - 2021/01/08
4
+
5
+ * Fix error on mention link with Nokogiri v1.11.0+. [#26](https://github.com/bitjourney/mato/pull/26)
6
+
7
+ ## v2.3.1 - 2020/07/15
8
+
9
+ * Allow loose task list. [#24](https://github.com/bitjourney/mato/pull/24)
10
+
11
+ ## v2.3.0 - 2020/06/16
12
+
13
+ * Add `convert_empty_task_list` option to TaskList filter to convert task list event if the text is empty. [#23](https://github.com/bitjourney/mato/pull/23)
14
+
15
+ ## v2.2.0 - 2020/05/08
16
+
17
+ https://github.com/bitjourney/mato/compare/v2.1.4...v2.2.0
18
+
19
+ * BREAKING: Drop support for Ruby 2.3
20
+ * Display code block as plan text if Rouge raises an error [#21](https://github.com/bitjourney/mato/pull/21)
21
+
22
+
23
+ ## v2.1.4 - 2019/4/11
24
+
25
+ https://github.com/bitjourney/mato/compare/v2.1.3...v2.1.4
26
+
27
+ * Fix broken mention link process in case of including unexpected text
28
+
3
29
  ## v2.1.3 - 2019/1/15
4
30
 
5
31
  https://github.com/bitjourney/mato/compare/v2.1.2...v2.1.3
data/Gemfile CHANGED
@@ -12,4 +12,6 @@ gem "m"
12
12
  gem "minitest"
13
13
  gem "minitest-power_assert"
14
14
  gem "rake", ">= 10.0"
15
- gem "rubocop"
15
+ gem 'rr'
16
+ gem "rubocop", '>= 0.78.0'
17
+ gem 'rubocop-performance'
@@ -37,7 +37,9 @@ module Mato
37
37
  next if text_node.content == candidate_html
38
38
 
39
39
  candidate_fragment = text_node.replace(candidate_html)
40
- candidate_fragment.css('span').each do |mention_element|
40
+ candidate_fragment.css('span.mention-candidate').each do |mention_element|
41
+ next unless mention_element.child
42
+
41
43
  (candidate_map[mention_element.child.content] ||= []) << mention_element
42
44
  end
43
45
 
@@ -50,6 +52,13 @@ module Mato
50
52
  # cleanup
51
53
  candidates.each do |candidate_fragment|
52
54
  candidate_fragment.css('span.mention-candidate').each do |node|
55
+ next unless node.child
56
+ # If link_builder calls Node#replace for a node,
57
+ # the node's parent becames nil.
58
+ # Node#replace doesn't accept node that doesn't have parent since Nokogiri v1.11.0,
59
+ # so we need to skip it.
60
+ next unless node.parent
61
+
53
62
  node.replace(node.child.content)
54
63
  end
55
64
  end
@@ -5,6 +5,12 @@
5
5
  module Mato
6
6
  module HtmlFilters
7
7
  class SyntaxHighlight
8
+ class RougeError < StandardError
9
+ end
10
+
11
+ def initialize(on_rouge_error: ->(ex) { warn ex })
12
+ @on_rouge_error = on_rouge_error
13
+ end
8
14
 
9
15
  # @param [Nokogiri::HTML::DocumentFragment] doc
10
16
  def call(doc)
@@ -57,11 +63,21 @@ module Mato
57
63
 
58
64
  lexer = guess_lexer(language, filename, source)
59
65
 
60
- document = Nokogiri::HTML.fragment(%{<div class="code-frame"/>})
61
-
62
- div = document.at('div')
63
- div.add_child(label_fragment(filename || language || lexer.tag)) if filename || !lexer.is_a?(Rouge::Lexers::PlainText)
64
- div.add_child(%{<pre class="highlight"><code data-lang="#{lexer.tag}">#{format(lexer, source)}</code></pre>})
66
+ begin
67
+ document = Nokogiri::HTML.fragment(%{<div class="code-frame"/>})
68
+ div = document.at('div')
69
+ div.add_child(label_fragment(filename || language || lexer.tag)) if filename || !lexer.is_a?(Rouge::Lexers::PlainText)
70
+ div.add_child(%{<pre class="highlight"><code data-lang="#{lexer.tag}">#{format(lexer, source)}</code></pre>})
71
+ rescue => ex
72
+ if ex.is_a?(RougeError) && !lexer.is_a?(Rouge::Lexers::PlainText)
73
+ # Retry highlighting with PlainText lexer if Rouge raises an error.
74
+ # It avoids to affect the error to whole of converting.
75
+ lexer = Rouge::Lexers::PlainText.new
76
+ retry
77
+ else
78
+ raise ex
79
+ end
80
+ end
65
81
 
66
82
  document
67
83
  end
@@ -79,6 +95,9 @@ module Mato
79
95
  def format(lexer, source)
80
96
  tokens = lexer.lex(source)
81
97
  formatter.format(tokens)
98
+ rescue => ex
99
+ @on_rouge_error.call(ex)
100
+ raise RougeError.new
82
101
  end
83
102
  end
84
103
  end
@@ -3,15 +3,18 @@
3
3
  module Mato
4
4
  module HtmlFilters
5
5
  class TaskList
6
- CHECKED_MARK = "[x] "
7
- UNCHECKED_MARK = "[ ] "
6
+ CHECKED_MARK = /\A\[x\] /
7
+ UNCHECKED_MARK = /\A\[ \] /
8
+ CHECKED_MARK_FOR_EMPTY_TASK_LIST = /\A\[x\] ?/
9
+ UNCHECKED_MARK_FOR_EMPTY_TASK_LIST = /\A\[ \] ?/
8
10
 
9
11
  DEFAULT_TASK_LIST_CLASS = "task-list-item"
10
12
  DEFAULT_CHECKBOX_CLASS = "task-list-item-checkbox"
11
13
 
12
- def initialize(task_list_class: DEFAULT_TASK_LIST_CLASS, checkbox_class: DEFAULT_CHECKBOX_CLASS)
14
+ def initialize(task_list_class: DEFAULT_TASK_LIST_CLASS, checkbox_class: DEFAULT_CHECKBOX_CLASS, convert_empty_task_list: false)
13
15
  @task_list_class = task_list_class
14
16
  @checkbox_class = checkbox_class
17
+ @convert_empty_task_list = convert_empty_task_list
15
18
  end
16
19
 
17
20
  # @param [Nokogiri::HTML::DocumentFragment] doc
@@ -23,7 +26,7 @@ module Mato
23
26
 
24
27
  # @param [Nokogiri::XML::Node] li
25
28
  def weave(li)
26
- text_node = li.xpath('.//text()').first
29
+ text_node = li.xpath('./p[1]/text()').first || li.xpath('.//text()').first
27
30
  checked = has_checked_mark?(text_node)
28
31
  unchecked = has_unchecked_mark?(text_node)
29
32
 
@@ -37,18 +40,34 @@ module Mato
37
40
  end
38
41
 
39
42
  def has_checked_mark?(text_node)
40
- text_node&.content&.start_with?(CHECKED_MARK)
43
+ text_node&.content&.match?(checked_mark)
41
44
  end
42
45
 
43
46
  def has_unchecked_mark?(text_node)
44
- text_node&.content&.start_with?(UNCHECKED_MARK)
47
+ text_node&.content&.match?(unchecked_mark)
45
48
  end
46
49
 
47
50
  def trim_mark(content, checked)
48
51
  if checked
49
- content.sub(CHECKED_MARK, '')
52
+ content.sub(checked_mark, '')
50
53
  else
51
- content.sub(UNCHECKED_MARK, '')
54
+ content.sub(unchecked_mark, '')
55
+ end
56
+ end
57
+
58
+ def checked_mark
59
+ if @convert_empty_task_list
60
+ CHECKED_MARK_FOR_EMPTY_TASK_LIST
61
+ else
62
+ CHECKED_MARK
63
+ end
64
+ end
65
+
66
+ def unchecked_mark
67
+ if @convert_empty_task_list
68
+ UNCHECKED_MARK_FOR_EMPTY_TASK_LIST
69
+ else
70
+ UNCHECKED_MARK
52
71
  end
53
72
  end
54
73
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mato
4
- VERSION = "2.1.3"
4
+ VERSION = "2.3.2"
5
5
  end
@@ -13,6 +13,11 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/bitjourney/mato"
14
14
  spec.license = "MIT"
15
15
 
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = 'https://github.com/bitjourney/mato/blob/master/CHANGELOG.md'
19
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/bitjourney/mato/issues'
20
+
16
21
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
22
  f.match(%r{^(?:test|spec|features|example)/})
18
23
  end
@@ -20,7 +25,7 @@ Gem::Specification.new do |spec|
20
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
26
  spec.require_paths = ["lib"]
22
27
 
23
- spec.required_ruby_version = ">= 2.3"
28
+ spec.required_ruby_version = ">= 2.4"
24
29
 
25
30
  spec.add_runtime_dependency "commonmarker", ">= 0.18.1"
26
31
  spec.add_runtime_dependency "nokogiri", ">= 1.6"
@@ -0,0 +1,4 @@
1
+ linter:
2
+ rubocop:
3
+ gems:
4
+ - "rubocop-performance"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mato
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - FUJI Goro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-15 00:00:00.000000000 Z
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commonmarker
@@ -89,11 +89,16 @@ files:
89
89
  - lib/mato/timeout.rb
90
90
  - lib/mato/version.rb
91
91
  - mato.gemspec
92
+ - sider.yml
92
93
  homepage: https://github.com/bitjourney/mato
93
94
  licenses:
94
95
  - MIT
95
- metadata: {}
96
- post_install_message:
96
+ metadata:
97
+ homepage_uri: https://github.com/bitjourney/mato
98
+ source_code_uri: https://github.com/bitjourney/mato
99
+ changelog_uri: https://github.com/bitjourney/mato/blob/master/CHANGELOG.md
100
+ bug_tracker_uri: https://github.com/bitjourney/mato/issues
101
+ post_install_message:
97
102
  rdoc_options: []
98
103
  require_paths:
99
104
  - lib
@@ -101,15 +106,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
106
  requirements:
102
107
  - - ">="
103
108
  - !ruby/object:Gem::Version
104
- version: '2.3'
109
+ version: '2.4'
105
110
  required_rubygems_version: !ruby/object:Gem::Requirement
106
111
  requirements:
107
112
  - - ">="
108
113
  - !ruby/object:Gem::Version
109
114
  version: '0'
110
115
  requirements: []
111
- rubygems_version: 3.0.1
112
- signing_key:
116
+ rubygems_version: 3.1.4
117
+ signing_key:
113
118
  specification_version: 4
114
119
  summary: MArkdown TOolkit
115
120
  test_files: []