gitlab_kramdown 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gitlab_kramdown/parser/autolink.rb +26 -9
- data/lib/gitlab_kramdown/parser/fenced_blockquote.rb +2 -2
- data/lib/gitlab_kramdown/parser/fenced_codeblock.rb +2 -2
- data/lib/gitlab_kramdown/parser/header.rb +11 -7
- data/lib/gitlab_kramdown/parser/reference.rb +11 -11
- data/lib/gitlab_kramdown/version.rb +1 -1
- data/lib/kramdown/parser/gitlab_kramdown.rb +1 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f56f5ad5ed710fefd24289c68ec7fe621f67261875def66fc7c4588a1a3f4930
|
4
|
+
data.tar.gz: 023f11be46858b9fff9cbf7aaf880629b665155aeb95f6f8804ff3fab19fd992
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41affa513909efce3c3aed46a185d0e2220dd96a64a54a33d0862aabf71fd21a46cc8fa3992966284e31a8deb6e0c0e38131427f3e0ab96d3e31d50f6ee94222
|
7
|
+
data.tar.gz: 2ad36ecf7f2b4003f1c7fbec5f99208be2e5098de42ad4bd129ff38004eaca9d334e1ac94eae14ca3dcbe84cfa39b4090227524c308d0b72c9492c0a82708c60
|
@@ -8,16 +8,18 @@ module GitlabKramdown
|
|
8
8
|
#
|
9
9
|
# @see https://docs.gitlab.com/ee/user/markdown.html#url-auto-linking
|
10
10
|
module Autolink
|
11
|
-
PUNCTUATION_PAIRS = /['"][)\]}][(\[{]
|
12
|
-
ACHARS = /[[:alnum:]]_
|
11
|
+
PUNCTUATION_PAIRS = /['"][)\]}][(\[{]/.freeze
|
12
|
+
ACHARS = /[[:alnum:]]_/.freeze
|
13
13
|
|
14
14
|
AUTOLINK_START = %r{
|
15
|
-
(
|
16
|
-
(?<schema>mailto|https?|ftps?|irc|smb):
|
17
|
-
|
18
|
-
|
15
|
+
(?<uri>
|
16
|
+
(?<schema>mailto|https?|ftps?|irc|smb):
|
17
|
+
[^\s\[\]>]+
|
18
|
+
(?<!\?|!|\.|,|:)
|
19
|
+
|
|
20
|
+
[-.#{ACHARS}]+@[-#{ACHARS}]+(?:\.[-#{ACHARS}]+)*\.[a-z]+
|
19
21
|
)
|
20
|
-
}x
|
22
|
+
}x.freeze
|
21
23
|
|
22
24
|
def self.included(klass)
|
23
25
|
klass.define_parser(:gitlab_autolink, AUTOLINK_START)
|
@@ -28,10 +30,25 @@ module GitlabKramdown
|
|
28
30
|
start_line_number = @src.current_line_number
|
29
31
|
@src.pos += @src.matched_size
|
30
32
|
|
31
|
-
|
33
|
+
# current StringScanner has limitations that prevent lookbehind to work properly
|
34
|
+
# so we can't use something like this: `(?<!\[)(?<!\]\()`. Using a negative lookbehind
|
35
|
+
# would improve performance on the cases where it would prevent a match.
|
36
|
+
#
|
37
|
+
# There is an alternative we could explore: https://github.com/luikore/zscan which
|
38
|
+
# does fix the current limitations, but them we are depending on another third party gem.
|
39
|
+
#
|
40
|
+
# Instead of depending on a third party, I'm opting for a simple fix that achieve the same
|
41
|
+
# results but without the performance improvements:
|
42
|
+
if @src.pre_match.end_with?('[', '](')
|
43
|
+
add_text(@src[:uri])
|
44
|
+
|
45
|
+
return
|
46
|
+
end
|
47
|
+
|
48
|
+
href = (@src[:schema].nil? ? "mailto:#{@src[:uri]}" : @src[:uri])
|
32
49
|
el = Kramdown::Element.new(:a, nil, { 'href' => href }, location: start_line_number)
|
33
50
|
|
34
|
-
add_text(@src[
|
51
|
+
add_text(@src[:uri].sub(/^mailto:/, ''), el)
|
35
52
|
@tree.children << el
|
36
53
|
end
|
37
54
|
end
|
@@ -8,7 +8,7 @@ module GitlabKramdown
|
|
8
8
|
#
|
9
9
|
# @see https://docs.gitlab.com/ee/user/markdown.html#multiline-blockquote
|
10
10
|
module FencedBlockquote
|
11
|
-
FENCED_BLOCKQUOTE_START = />{3}/x
|
11
|
+
FENCED_BLOCKQUOTE_START = />{3}/x.freeze
|
12
12
|
|
13
13
|
FENCED_BLOCKQUOTE_MATCH = %r{
|
14
14
|
^(?<delimiter>>{3}) # line must start with >>>
|
@@ -19,7 +19,7 @@ module GitlabKramdown
|
|
19
19
|
\k<delimiter> # same delimiter used to open the block
|
20
20
|
[ \t]* # any amount of trailling whitespace
|
21
21
|
\s
|
22
|
-
}xm
|
22
|
+
}xm.freeze
|
23
23
|
|
24
24
|
def self.included(klass)
|
25
25
|
klass.define_parser(:fenced_blockquote, FENCED_BLOCKQUOTE_START)
|
@@ -13,8 +13,8 @@ module GitlabKramdown
|
|
13
13
|
#
|
14
14
|
# @see https://docs.gitlab.com/ee/user/markdown.html#code-and-syntax-highlighting
|
15
15
|
module FencedCodeblock
|
16
|
-
FENCED_CODEBLOCK_START = /^[ ]{0,3}[~`]{3,}
|
17
|
-
FENCED_CODEBLOCK_MATCH = /^[ ]{0,3}(([~`]){3,})\s*?((\S+?)(?:\?\S*)?)?\s*?\n(.*?)^[ ]{0,3}\1\2*\s*?\n/m
|
16
|
+
FENCED_CODEBLOCK_START = /^[ ]{0,3}[~`]{3,}/.freeze
|
17
|
+
FENCED_CODEBLOCK_MATCH = /^[ ]{0,3}(([~`]){3,})\s*?((\S+?)(?:\?\S*)?)?\s*?\n(.*?)^[ ]{0,3}\1\2*\s*?\n/m.freeze
|
18
18
|
|
19
19
|
def self.included(klass)
|
20
20
|
klass.define_parser(:codeblock_fenced_gitlab, FENCED_CODEBLOCK_START, nil, 'parse_codeblock_fenced')
|
@@ -9,8 +9,12 @@ module GitlabKramdown
|
|
9
9
|
#
|
10
10
|
# @see https://docs.gitlab.com/ee/user/markdown.html#headers
|
11
11
|
module Header
|
12
|
-
HEADER_ID = /(?:[ \t]+\{#([A-Za-z][\w:-]*)\})
|
13
|
-
SETEXT_HEADER_START =
|
12
|
+
HEADER_ID = /(?:[ \t]+\{#([A-Za-z][\w:-]*)\})?/.freeze
|
13
|
+
SETEXT_HEADER_START = %r{
|
14
|
+
^(#{Kramdown::Parser::Kramdown::OPT_SPACE}[^ \t].*?)
|
15
|
+
#{HEADER_ID}[ \t]*?\n
|
16
|
+
(-|=)+\s*?\n
|
17
|
+
}x.freeze
|
14
18
|
|
15
19
|
def self.included(klass)
|
16
20
|
klass.define_parser(:setext_gitlab_header, SETEXT_HEADER_START)
|
@@ -26,7 +30,7 @@ module GitlabKramdown
|
|
26
30
|
|
27
31
|
el = new_block_el(:header, nil, nil, level: (level == '-' ? 2 : 1), raw_text: text, location: start_line_number)
|
28
32
|
add_text(text, el)
|
29
|
-
el.attr['id'] = id
|
33
|
+
el.attr['id'] = id || generate_header_id(text)
|
30
34
|
|
31
35
|
if @options[:linkable_headers]
|
32
36
|
el.children << Kramdown::Element.new(:a, nil, {
|
@@ -40,8 +44,8 @@ module GitlabKramdown
|
|
40
44
|
true
|
41
45
|
end
|
42
46
|
|
43
|
-
ATX_HEADER_START = /^\#{1,6}
|
44
|
-
ATX_HEADER_MATCH = /^(\#{1,6})(.+?(?:\\#)?)\s*?#*#{HEADER_ID}\s*?\n
|
47
|
+
ATX_HEADER_START = /^\#{1,6}/.freeze
|
48
|
+
ATX_HEADER_MATCH = /^(\#{1,6})(.+?(?:\\#)?)\s*?#*#{HEADER_ID}\s*?\n/.freeze
|
45
49
|
|
46
50
|
# Parse the Atx header at the current location.
|
47
51
|
def parse_atx_gitlab_header
|
@@ -54,7 +58,7 @@ module GitlabKramdown
|
|
54
58
|
|
55
59
|
el = new_block_el(:header, nil, nil, level: level.length, raw_text: text, location: start_line_number)
|
56
60
|
add_text(text, el)
|
57
|
-
el.attr['id'] = id
|
61
|
+
el.attr['id'] = id || generate_header_id(text)
|
58
62
|
|
59
63
|
if @options[:linkable_headers]
|
60
64
|
el.children << Kramdown::Element.new(:a, nil, {
|
@@ -68,7 +72,7 @@ module GitlabKramdown
|
|
68
72
|
true
|
69
73
|
end
|
70
74
|
|
71
|
-
NON_WORD_RE = /[^\p{Word}\- \t]
|
75
|
+
NON_WORD_RE = /[^\p{Word}\- \t]/.freeze
|
72
76
|
|
73
77
|
def generate_header_id(text)
|
74
78
|
result = text.downcase
|
@@ -9,28 +9,28 @@ module GitlabKramdown
|
|
9
9
|
#
|
10
10
|
# @see https://docs.gitlab.com/ee/user/markdown.html#special-gitlab-references
|
11
11
|
module Reference
|
12
|
-
PATH_REGEX = /[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]
|
12
|
+
PATH_REGEX = /[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]+/.freeze
|
13
13
|
|
14
14
|
NAMESPACE_FORMAT_REGEX = %r{
|
15
15
|
(?:#{PATH_REGEX}[a-zA-Z0-9_\-])
|
16
16
|
(?<!\.git|\.atom)
|
17
17
|
|[a-zA-Z0-9_]
|
18
|
-
}x
|
18
|
+
}x.freeze
|
19
19
|
|
20
|
-
FULL_NAMESPACE_FORMAT_REGEX = %r{(#{NAMESPACE_FORMAT_REGEX}/)*#{NAMESPACE_FORMAT_REGEX}}
|
21
|
-
ALWAYS_FULL_NAMESPACE_FORMAT_REGEX = %r{(#{NAMESPACE_FORMAT_REGEX}/)+#{NAMESPACE_FORMAT_REGEX}}
|
20
|
+
FULL_NAMESPACE_FORMAT_REGEX = %r{(#{NAMESPACE_FORMAT_REGEX}/)*#{NAMESPACE_FORMAT_REGEX}}.freeze
|
21
|
+
ALWAYS_FULL_NAMESPACE_FORMAT_REGEX = %r{(#{NAMESPACE_FORMAT_REGEX}/)+#{NAMESPACE_FORMAT_REGEX}}.freeze
|
22
22
|
|
23
23
|
USER_GROUP_PATTERN = %r{
|
24
24
|
#{Regexp.escape('@')}
|
25
25
|
(?<user>#{FULL_NAMESPACE_FORMAT_REGEX})
|
26
|
-
}x
|
26
|
+
}x.freeze
|
27
27
|
|
28
28
|
PROJECT_COMMIT_PATTERN = %r{
|
29
29
|
(?<namespace>#{ALWAYS_FULL_NAMESPACE_FORMAT_REGEX})
|
30
30
|
#{Regexp.escape('@')}
|
31
31
|
(?<commit>[a-f0-9]{7,40})
|
32
32
|
(?!\.{3})
|
33
|
-
}x
|
33
|
+
}x.freeze
|
34
34
|
|
35
35
|
PROJECT_COMMIT_DIFF_PATTERN = %r{
|
36
36
|
(?<namespace>#{ALWAYS_FULL_NAMESPACE_FORMAT_REGEX})
|
@@ -38,25 +38,25 @@ module GitlabKramdown
|
|
38
38
|
(?<commit_source>[a-f0-9]{7,40})
|
39
39
|
\.{3}
|
40
40
|
(?<commit_target>[a-f0-9]{7,40})
|
41
|
-
}x
|
41
|
+
}x.freeze
|
42
42
|
|
43
43
|
PROJECT_ISSUE_PATTERN = %r{
|
44
44
|
(?<namespace>#{ALWAYS_FULL_NAMESPACE_FORMAT_REGEX})
|
45
45
|
#{Regexp.escape('#')}
|
46
46
|
(?<issue>[1-9][0-9]*)
|
47
|
-
}x
|
47
|
+
}x.freeze
|
48
48
|
|
49
49
|
PROJECT_MERGE_REQUEST_PATTERN = %r{
|
50
50
|
(?<namespace>#{ALWAYS_FULL_NAMESPACE_FORMAT_REGEX})
|
51
51
|
#{Regexp.escape('!')}
|
52
52
|
(?<merge_request>[1-9][0-9]*)
|
53
|
-
}x
|
53
|
+
}x.freeze
|
54
54
|
|
55
55
|
PROJECT_SNIPPET_PATTERN = %r{
|
56
56
|
(?<namespace>#{ALWAYS_FULL_NAMESPACE_FORMAT_REGEX})
|
57
57
|
#{Regexp.escape('$')}
|
58
58
|
(?<snippet>[1-9][0-9]*)
|
59
|
-
}x
|
59
|
+
}x.freeze
|
60
60
|
|
61
61
|
PROJECT_LABEL_PATTERN = %r{
|
62
62
|
(?<namespace>#{ALWAYS_FULL_NAMESPACE_FORMAT_REGEX})
|
@@ -65,7 +65,7 @@ module GitlabKramdown
|
|
65
65
|
[A-Za-z0-9_\-\?\.&]+ | # String-based single-word label title, or
|
66
66
|
".+?" # String-based multi-word label surrounded in quotes
|
67
67
|
)
|
68
|
-
}x
|
68
|
+
}x.freeze
|
69
69
|
|
70
70
|
def self.included(klass)
|
71
71
|
klass.define_parser(:user_group_mention, USER_GROUP_PATTERN, '@')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab_kramdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Mazetto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.16.2
|
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:
|
26
|
+
version: 1.16.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rouge
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec_junit_formatter
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: benchmark-ips
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|