mato 2.1.2 → 2.3.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 +4 -4
- data/.rubocop.yml +37 -27
- data/.travis.yml +3 -2
- data/CHANGELOG.md +28 -0
- data/Gemfile +3 -1
- data/lib/mato/anchor_builder.rb +7 -1
- data/lib/mato/config.rb +3 -0
- data/lib/mato/converter.rb +1 -1
- data/lib/mato/document.rb +0 -1
- data/lib/mato/html_filters/bare_inline_element.rb +1 -0
- data/lib/mato/html_filters/mention_link.rb +5 -1
- data/lib/mato/html_filters/syntax_highlight.rb +24 -5
- data/lib/mato/html_filters/task_list.rb +27 -8
- data/lib/mato/version.rb +1 -1
- data/mato.gemspec +6 -1
- data/sider.yml +4 -0
- metadata +13 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59902decca423364fc185eef127151622e9348e7ce4ed5a90bab8ca1d44dfbf3
|
4
|
+
data.tar.gz: bd618687101adb2f9f9e1d6a4ac5a25baafa44018fa7bff2869e19703ec0375d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25752490aeb9a2a7d7926a8037dac4138836b5c2582dbe3894e5761566cc9c60c15e14f9ed70a457d78dc96346961d9d795c188671c7055bfc612d596c5163a3
|
7
|
+
data.tar.gz: 8eb1dd626ad5147fb8e1d0050a3650a1207860227cc4f88a79220a87a68f8040e9bf0c5be890b5af248fe5542b2c55b04b06c1357e098cfab1cb409903c48559
|
data/.rubocop.yml
CHANGED
@@ -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.
|
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
|
-
|
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/
|
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
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
# The revision history of Mato
|
2
2
|
|
3
|
+
## v2.3.1 - 2020/07/15
|
4
|
+
|
5
|
+
* Allow loose task list. [#24](https://github.com/bitjourney/mato/pull/24)
|
6
|
+
|
7
|
+
## v2.3.0 - 2020/06/16
|
8
|
+
|
9
|
+
* 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)
|
10
|
+
|
11
|
+
## v2.2.0 - 2020/05/08
|
12
|
+
|
13
|
+
https://github.com/bitjourney/mato/compare/v2.1.4...v2.2.0
|
14
|
+
|
15
|
+
* BREAKING: Drop support for Ruby 2.3
|
16
|
+
* Display code block as plan text if Rouge raises an error [#21](https://github.com/bitjourney/mato/pull/21)
|
17
|
+
|
18
|
+
|
19
|
+
## v2.1.4 - 2019/4/11
|
20
|
+
|
21
|
+
https://github.com/bitjourney/mato/compare/v2.1.3...v2.1.4
|
22
|
+
|
23
|
+
* Fix broken mention link process in case of including unexpected text
|
24
|
+
|
25
|
+
## v2.1.3 - 2019/1/15
|
26
|
+
|
27
|
+
https://github.com/bitjourney/mato/compare/v2.1.2...v2.1.3
|
28
|
+
|
29
|
+
* Fix anchor in case of heading which is only special characters
|
30
|
+
|
3
31
|
## v2.1.2 - 2018/10/23
|
4
32
|
|
5
33
|
https://github.com/bitjourney/mato/compare/v2.1.1...v2.1.2
|
data/Gemfile
CHANGED
data/lib/mato/anchor_builder.rb
CHANGED
@@ -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
|
data/lib/mato/config.rb
CHANGED
@@ -80,16 +80,19 @@ module Mato
|
|
80
80
|
|
81
81
|
def append_text_filter(text_filter, timeout: nil, on_timeout: nil, on_error: nil)
|
82
82
|
raise "text_filter must respond to call()" unless text_filter.respond_to?(:call)
|
83
|
+
|
83
84
|
text_filters.push(wrap(text_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
|
84
85
|
end
|
85
86
|
|
86
87
|
def append_markdown_filter(markdown_filter, timeout: nil, on_timeout: nil, on_error: nil)
|
87
88
|
raise "markdown_filter must respond to call()" unless markdown_filter.respond_to?(:call)
|
89
|
+
|
88
90
|
markdown_filters.push(wrap(markdown_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
|
89
91
|
end
|
90
92
|
|
91
93
|
def append_html_filter(html_filter, timeout: nil, on_timeout: nil, on_error: nil)
|
92
94
|
raise "html_filter must respond to call()" unless html_filter.respond_to?(:call)
|
95
|
+
|
93
96
|
html_filters.push(wrap(html_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
|
94
97
|
end
|
95
98
|
|
data/lib/mato/converter.rb
CHANGED
@@ -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.
|
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
|
data/lib/mato/document.rb
CHANGED
@@ -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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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 =
|
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&.
|
43
|
+
text_node&.content&.match?(checked_mark)
|
41
44
|
end
|
42
45
|
|
43
46
|
def has_unchecked_mark?(text_node)
|
44
|
-
text_node&.content&.
|
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(
|
52
|
+
content.sub(checked_mark, '')
|
50
53
|
else
|
51
|
-
content.sub(
|
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
|
|
data/lib/mato/version.rb
CHANGED
data/mato.gemspec
CHANGED
@@ -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.
|
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"
|
data/sider.yml
ADDED
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
|
4
|
+
version: 2.3.1
|
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:
|
11
|
+
date: 2020-07-15 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
|
-
|
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,16 +106,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
106
|
requirements:
|
102
107
|
- - ">="
|
103
108
|
- !ruby/object:Gem::Version
|
104
|
-
version: '2.
|
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
|
-
|
112
|
-
|
113
|
-
signing_key:
|
116
|
+
rubygems_version: 3.2.0.pre1
|
117
|
+
signing_key:
|
114
118
|
specification_version: 4
|
115
119
|
summary: MArkdown TOolkit
|
116
120
|
test_files: []
|