mato 2.1.1 → 2.3.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: bf9376fe32fa4245c884ab54cfccc6cbc263198d86a401e8601b79d3dc76cfd2
4
- data.tar.gz: 88785abe066ee18c23b5b07cc3cc8b35cbdf6e447008c9a27e0bdfc7c6738351
3
+ metadata.gz: f7985e295c016bbc58c5cc8accc3c81e33e8351a13ed23e9ccc9bb55fe083a01
4
+ data.tar.gz: d18bb43005111174d922335385453ae4779d449a6efe75431693930fc72309f9
5
5
  SHA512:
6
- metadata.gz: d51e4046173e64152c07b133d7fe3d04af92e3dc4664c3346fdcd5f57da402005fd5b05a64bfb24bc158f52dc3536c7f1f3c56e210cf0e234dab114aaf2c95c1
7
- data.tar.gz: 633e03865baf4e21eb5e026aedd40ce447aa63750de3a6b216f0d695fc4e11385914e98aac4affdad99e556290d4ad7885296f54ef7e159d401323011aa0394e
6
+ metadata.gz: '08a8c3e69c1af3426109ff111846d3eba57fd91ff3095a606b9c3bae412b7b8947782017143dd894d161872b2907f3084611fe8bfb27e8e900f392bb321e09f5'
7
+ data.tar.gz: a4dc40fb37b6db9c12e5011e9ea3391d155e78ecbd922d6021a73d2d00ccdb7bc56708e2a17f972d604674accec01ad792f7535abfb385caceb192997179663f
@@ -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
 
@@ -90,7 +77,10 @@ Style/SignalException:
90
77
  Style/StringLiterals:
91
78
  Enabled: false
92
79
 
93
- Style/TrailingCommaInLiteral:
80
+ Style/TrailingCommaInArrayLiteral:
81
+ EnforcedStyleForMultiline: comma
82
+
83
+ Style/TrailingCommaInHashLiteral:
94
84
  EnforcedStyleForMultiline: comma
95
85
 
96
86
  Style/TrailingCommaInArguments:
@@ -117,6 +107,9 @@ Style/AsciiComments:
117
107
  Style/EmptyMethod:
118
108
  EnforcedStyle: expanded
119
109
 
110
+ Style/RaiseArgs:
111
+ Enabled: false
112
+
120
113
  Naming/VariableNumber:
121
114
  Enabled: false
122
115
 
@@ -143,3 +136,20 @@ Style/NonNilCheck:
143
136
 
144
137
  Performance/RedundantBlockCall:
145
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,9 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
- - 2.3
5
3
  - 2.4
4
+ - 2.5
5
+ - 2.6
6
+ - 2.7
6
7
  - ruby-head
7
8
 
8
9
  matrix:
@@ -1,5 +1,35 @@
1
1
  # The revision history of Mato
2
2
 
3
+ ## v2.3.0 - 2020/06/16
4
+
5
+ * 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)
6
+
7
+ ## v2.2.0 - 2020/05/08
8
+
9
+ https://github.com/bitjourney/mato/compare/v2.1.4...v2.2.0
10
+
11
+ * BREAKING: Drop support for Ruby 2.3
12
+ * Display code block as plan text if Rouge raises an error [#21](https://github.com/bitjourney/mato/pull/21)
13
+
14
+
15
+ ## v2.1.4 - 2019/4/11
16
+
17
+ https://github.com/bitjourney/mato/compare/v2.1.3...v2.1.4
18
+
19
+ * Fix broken mention link process in case of including unexpected text
20
+
21
+ ## v2.1.3 - 2019/1/15
22
+
23
+ https://github.com/bitjourney/mato/compare/v2.1.2...v2.1.3
24
+
25
+ * Fix anchor in case of heading which is only special characters
26
+
27
+ ## v2.1.2 - 2018/10/23
28
+
29
+ https://github.com/bitjourney/mato/compare/v2.1.1...v2.1.2
30
+
31
+ * Add UNSAFE to DEFAULT_MARKDOWN_RENDER_OPTIONS
32
+
3
33
  ## v2.1.1 - 2018/02/22
4
34
 
5
35
  https://github.com/bitjourney/mato/compare/v2.1.0...v2.1.1
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'
@@ -44,7 +44,13 @@ module Mato
44
44
  end
45
45
 
46
46
  def make_anchor_id_prefix(text)
47
- ERB::Util.url_encode(text.downcase.gsub(/[^\p{Word}\- ]/u, "").tr(" ", "-"))
47
+ prefix = ERB::Util.url_encode(text.downcase.gsub(/[^\p{Word}\- ]/u, "").tr(" ", "-"))
48
+
49
+ if prefix.empty?
50
+ "user-content" # GitHub compatible
51
+ else
52
+ prefix
53
+ end
48
54
  end
49
55
  end
50
56
  end
@@ -18,6 +18,7 @@ module Mato
18
18
  :DEFAULT,
19
19
  :HARDBREAKS, # convert "\n" as <br/>
20
20
  :TABLE_PREFER_STYLE_ATTRIBUTES,
21
+ :UNSAFE,
21
22
  # :SOURCEPOS, // TODO: enable it after assertions are supported
22
23
  ].freeze
23
24
 
@@ -79,16 +80,19 @@ module Mato
79
80
 
80
81
  def append_text_filter(text_filter, timeout: nil, on_timeout: nil, on_error: nil)
81
82
  raise "text_filter must respond to call()" unless text_filter.respond_to?(:call)
83
+
82
84
  text_filters.push(wrap(text_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
83
85
  end
84
86
 
85
87
  def append_markdown_filter(markdown_filter, timeout: nil, on_timeout: nil, on_error: nil)
86
88
  raise "markdown_filter must respond to call()" unless markdown_filter.respond_to?(:call)
89
+
87
90
  markdown_filters.push(wrap(markdown_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
88
91
  end
89
92
 
90
93
  def append_html_filter(html_filter, timeout: nil, on_timeout: nil, on_error: nil)
91
94
  raise "html_filter must respond to call()" unless html_filter.respond_to?(:call)
95
+
92
96
  html_filters.push(wrap(html_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
93
97
  end
94
98
 
@@ -48,7 +48,7 @@ module Mato
48
48
  node.sourcepos[:start_column] == 1 &&
49
49
  node.parent.type == :paragraph &&
50
50
  node.parent.parent.type == :document
51
- end.reverse.each do |node|
51
+ end.reverse_each do |node|
52
52
  replacement = node.string_content.gsub(/\A(#+)(?=\S)/, '\1 ')
53
53
 
54
54
  if node.string_content != replacement
@@ -1,4 +1,3 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require_relative './renderers/html_renderer'
@@ -17,6 +17,7 @@ module Mato
17
17
  def call(doc)
18
18
  doc.children.each do |node|
19
19
  next unless STANDALONE_INLINE_ELEMENTS.include?(node.name)
20
+
20
21
  parent = Nokogiri::HTML.fragment('<p/>')
21
22
  parent.child.add_child(node.dup)
22
23
  node.replace(parent)
@@ -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,8 @@ 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
+
53
57
  node.replace(node.child.content)
54
58
  end
55
59
  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
@@ -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.1"
4
+ VERSION = "2.3.0"
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,9 +25,9 @@ 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
- spec.add_runtime_dependency "commonmarker", ">= 0.17.8"
30
+ spec.add_runtime_dependency "commonmarker", ">= 0.18.1"
26
31
  spec.add_runtime_dependency "nokogiri", ">= 1.6"
27
32
  spec.add_runtime_dependency "rouge", ">= 3.0.0"
28
33
  end
@@ -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.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - FUJI Goro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-22 00:00:00.000000000 Z
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commonmarker
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.17.8
19
+ version: 0.18.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.17.8
26
+ version: 0.18.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -89,10 +89,15 @@ 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
+ 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
96
101
  post_install_message:
97
102
  rdoc_options: []
98
103
  require_paths:
@@ -101,15 +106,14 @@ 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
- rubyforge_project:
112
- rubygems_version: 2.7.6
116
+ rubygems_version: 3.2.0.pre1
113
117
  signing_key:
114
118
  specification_version: 4
115
119
  summary: MArkdown TOolkit