gitlab_kramdown 0.3.0 → 0.4.0
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/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/VERSION +1 -1
- data/gitlab_kramdown.gemspec +6 -3
- data/lib/gitlab_kramdown/parser/autolink.rb +39 -0
- data/lib/gitlab_kramdown/parser/reference.rb +12 -6
- data/lib/gitlab_kramdown/parser.rb +1 -0
- data/lib/kramdown/parser/gitlab_kramdown.rb +3 -1
- data/spec/fixtures/autolink.html +21 -0
- data/spec/fixtures/autolink.text +18 -0
- data/spec/fixtures/references.html +3 -1
- data/spec/fixtures/references.text +3 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce8545ba899795f6dc56a1719b4b34f61b2a4658
|
4
|
+
data.tar.gz: 18241d90cfb9fa02b4115fc5d4f1fb388d2896e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6813cb7bf833a30a9a19090caab8f4bf4b5e55d9f006c85cbc3f7bbaa42dd21a2e70f6f3b4236e642c9315b35a398799297ee45556b1df9a8c6a0aaa6a73c38e
|
7
|
+
data.tar.gz: 82fc613035d1a7a9864cb22142aeef407a76331d3be7c7ba7fecd2d7da2ea3b7e6ec5dc7bc00af731e2a0e13e200dd3551e6dbe4a0c6e348b3fe3c93d810e7ee
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.4.0] - 2018-04-12
|
10
|
+
### Added
|
11
|
+
- URL auto-linking support
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- Fixed many inconsistencies in references autolink
|
15
|
+
|
9
16
|
## [0.3.0] - 2018-03-23
|
10
17
|
### Added
|
11
18
|
- Headers will include by default an anchor tag (you can disable with `linkable_headers: false`)
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ This is a list of GitLab Flavored Markdown (GFM) extensions and their status of
|
|
11
11
|
| [Newlines] | No |
|
12
12
|
| [Multiple underscores in words] | _Kramdown_ |
|
13
13
|
| [Headers with Anchors] | **Yes** |
|
14
|
-
| [URL auto-linking] |
|
14
|
+
| [URL auto-linking] | **Yes** |
|
15
15
|
| [Multiline Blockquote] | **Yes** |
|
16
16
|
| [Code and Syntax Highlighting] | **Yes** |
|
17
17
|
| [Inline Diff] | No |
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/gitlab_kramdown.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: gitlab_kramdown 0.
|
5
|
+
# stub: gitlab_kramdown 0.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "gitlab_kramdown".freeze
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.4.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Gabriel Mazetto".freeze]
|
14
|
-
s.date = "2018-
|
14
|
+
s.date = "2018-04-12"
|
15
15
|
s.description = "GitLab Flavored Markdown extensions on top of Kramdown markup. Tries to be as close as possible to existing extensions.".freeze
|
16
16
|
s.email = "brodock@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -33,11 +33,14 @@ Gem::Specification.new do |s|
|
|
33
33
|
"gitlab_kramdown.gemspec",
|
34
34
|
"lib/gitlab_kramdown.rb",
|
35
35
|
"lib/gitlab_kramdown/parser.rb",
|
36
|
+
"lib/gitlab_kramdown/parser/autolink.rb",
|
36
37
|
"lib/gitlab_kramdown/parser/fenced_blockquote.rb",
|
37
38
|
"lib/gitlab_kramdown/parser/fenced_codeblock.rb",
|
38
39
|
"lib/gitlab_kramdown/parser/header.rb",
|
39
40
|
"lib/gitlab_kramdown/parser/reference.rb",
|
40
41
|
"lib/kramdown/parser/gitlab_kramdown.rb",
|
42
|
+
"spec/fixtures/autolink.html",
|
43
|
+
"spec/fixtures/autolink.text",
|
41
44
|
"spec/fixtures/code_highlight.html",
|
42
45
|
"spec/fixtures/code_highlight.text",
|
43
46
|
"spec/fixtures/header.html",
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitlabKramdown
|
4
|
+
module Parser
|
5
|
+
# URL auto-linking
|
6
|
+
#
|
7
|
+
# This parser implements URL auto-linking support for the most widely used schemas
|
8
|
+
#
|
9
|
+
# @see https://docs.gitlab.com/ee/user/markdown.html#url-auto-linking
|
10
|
+
module Autolink
|
11
|
+
PUNCTUATION_PAIRS = /['"][)\]}][(\[{]/
|
12
|
+
ACHARS = /[[:alnum:]]_/
|
13
|
+
|
14
|
+
AUTOLINK_START = %r{
|
15
|
+
(
|
16
|
+
(?<schema>mailto|https?|ftps?|irc|smb):[^\s>]+(?<!\?|!|\.|,|:)
|
17
|
+
|
|
18
|
+
[-.[[:alnum:]]_]+@[-[[:alnum:]]_]+(?:\.[-[[:alnum:]]_]+)*\.[a-z]+
|
19
|
+
)
|
20
|
+
}x
|
21
|
+
|
22
|
+
def self.included(klass)
|
23
|
+
klass.define_parser(:gitlab_autolink, AUTOLINK_START)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Parse the autolink at the current location.
|
27
|
+
def parse_gitlab_autolink
|
28
|
+
start_line_number = @src.current_line_number
|
29
|
+
@src.pos += @src.matched_size
|
30
|
+
|
31
|
+
href = (@src[:schema].nil? ? "mailto:#{@src[0]}" : @src[0])
|
32
|
+
el = Kramdown::Element.new(:a, nil, { 'href' => href }, location: start_line_number)
|
33
|
+
|
34
|
+
add_text(@src[0].sub(/^mailto:/, ''), el)
|
35
|
+
@tree.children << el
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -9,23 +9,23 @@ module GitlabKramdown
|
|
9
9
|
#
|
10
10
|
# @see https://docs.gitlab.com/ee/user/markdown.html#special-gitlab-references
|
11
11
|
module Reference
|
12
|
-
|
12
|
+
PATH_REGEX = /[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*/
|
13
13
|
|
14
14
|
NAMESPACE_FORMAT_REGEX = %r{
|
15
|
-
(?:#{
|
15
|
+
(?:#{PATH_REGEX}[a-zA-Z0-9_\-]|[a-zA-Z0-9_])
|
16
16
|
(?<!\.git|\.atom)
|
17
17
|
}x
|
18
18
|
|
19
19
|
FULL_NAMESPACE_FORMAT_REGEX = %r{(#{NAMESPACE_FORMAT_REGEX}/)*#{NAMESPACE_FORMAT_REGEX}}
|
20
|
+
ALWAYS_FULL_NAMESPACE_FORMAT_REGEX = %r{(#{NAMESPACE_FORMAT_REGEX}/)+#{NAMESPACE_FORMAT_REGEX}}
|
20
21
|
|
21
22
|
USER_GROUP_PATTERN = %r{
|
22
|
-
(?<!\w)
|
23
23
|
#{Regexp.escape('@')}
|
24
24
|
(?<user>#{FULL_NAMESPACE_FORMAT_REGEX})
|
25
25
|
}x
|
26
26
|
|
27
27
|
PROJECT_COMMIT_PATTERN = %r{
|
28
|
-
(?<namespace>#{
|
28
|
+
(?<namespace>#{ALWAYS_FULL_NAMESPACE_FORMAT_REGEX})
|
29
29
|
#{Regexp.escape('@')}
|
30
30
|
(?<commit>[a-z0-9]+)
|
31
31
|
(?!\.{3})
|
@@ -34,9 +34,9 @@ module GitlabKramdown
|
|
34
34
|
PROJECT_COMMIT_DIFF_PATTERN = %r{
|
35
35
|
(?<namespace>#{FULL_NAMESPACE_FORMAT_REGEX})
|
36
36
|
#{Regexp.escape('@')}
|
37
|
-
(?<commit_source>[a-
|
37
|
+
(?<commit_source>[a-f0-9]+)
|
38
38
|
\.{3}
|
39
|
-
(?<commit_target>[a-
|
39
|
+
(?<commit_target>[a-f0-9]+)
|
40
40
|
}x
|
41
41
|
|
42
42
|
PROJECT_ISSUE_PATTERN = %r{
|
@@ -80,6 +80,12 @@ module GitlabKramdown
|
|
80
80
|
start_line_number = @src.current_line_number
|
81
81
|
@src.pos += @src.matched_size
|
82
82
|
|
83
|
+
# should not start with anything that looks like project/namespace
|
84
|
+
if @src.pre_match.match?(/[a-zA-Z0-9_\-]\Z/)
|
85
|
+
add_text(@src[0])
|
86
|
+
return
|
87
|
+
end
|
88
|
+
|
83
89
|
href = "#{@options[:gitlab_url]}/#{@src[:user]}"
|
84
90
|
|
85
91
|
el = Kramdown::Element.new(:a, nil, { 'href' => href }, location: start_line_number)
|
@@ -9,5 +9,6 @@ module GitlabKramdown
|
|
9
9
|
autoload :FencedCodeblock, 'gitlab_kramdown/parser/fenced_codeblock'
|
10
10
|
autoload :Header, 'gitlab_kramdown/parser/header'
|
11
11
|
autoload :Reference, 'gitlab_kramdown/parser/reference'
|
12
|
+
autoload :Autolink, 'gitlab_kramdown/parser/autolink'
|
12
13
|
end
|
13
14
|
end
|
@@ -13,6 +13,7 @@ module Kramdown
|
|
13
13
|
include ::GitlabKramdown::Parser::FencedCodeblock
|
14
14
|
include ::GitlabKramdown::Parser::Header
|
15
15
|
include ::GitlabKramdown::Parser::Reference
|
16
|
+
include ::GitlabKramdown::Parser::Autolink
|
16
17
|
|
17
18
|
def initialize(source, options)
|
18
19
|
super
|
@@ -21,7 +22,8 @@ module Kramdown
|
|
21
22
|
@options[:linkable_headers] = true if @options[:linkable_headers].nil?
|
22
23
|
@id_counter = Hash.new(-1)
|
23
24
|
|
24
|
-
prepend_span_parsers(:commit_diff, :commit, :user_group_mention,
|
25
|
+
prepend_span_parsers(:commit_diff, :commit, :user_group_mention,
|
26
|
+
:issue, :merge_request, :snippet, :label, :gitlab_autolink)
|
25
27
|
prepend_block_parsers(:fenced_blockquote)
|
26
28
|
replace_block_parser!(:codeblock_fenced, :codeblock_fenced_gitlab)
|
27
29
|
replace_block_parser!(:atx_header, :atx_gitlab_header)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<h1 id="autolinks">Autolinks</h1>
|
2
|
+
|
3
|
+
<p>The following URLs will be autolinked:</p>
|
4
|
+
|
5
|
+
<ul>
|
6
|
+
<li><a href="https://www.google.com">https://www.google.com</a> ! This is google</li>
|
7
|
+
<li><a href="https://google.com/">https://google.com/</a></li>
|
8
|
+
<li><a href="ftp://ftp.us.debian.org/debian/">ftp://ftp.us.debian.org/debian/</a></li>
|
9
|
+
<li><a href="smb://foo/bar/baz">smb://foo/bar/baz</a></li>
|
10
|
+
<li><a href="irc://irc.freenode.net/gitlab">irc://irc.freenode.net/gitlab</a></li>
|
11
|
+
<li><a href="http://localhost:3000">http://localhost:3000</a></li>
|
12
|
+
<li>This is an email: <a href="mailto:john.doe@example.com">john.doe@example.com</a> .</li>
|
13
|
+
<li>URL with ampersand: <a href="http://www.example.com/?doit&x=y">http://www.example.com/?doit&x=y</a> !</li>
|
14
|
+
</ul>
|
15
|
+
|
16
|
+
<blockquote>
|
17
|
+
<p>It works even inside other blocks: <a href="https://www.google.com">https://www.google.com</a></p>
|
18
|
+
</blockquote>
|
19
|
+
|
20
|
+
<pre><code>Doesn't work inside code-blocks: https://www.google.com
|
21
|
+
</code></pre>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Autolinks
|
2
|
+
|
3
|
+
The following URLs will be autolinked:
|
4
|
+
|
5
|
+
* https://www.google.com ! This is google
|
6
|
+
* https://google.com/
|
7
|
+
* ftp://ftp.us.debian.org/debian/
|
8
|
+
* smb://foo/bar/baz
|
9
|
+
* irc://irc.freenode.net/gitlab
|
10
|
+
* http://localhost:3000
|
11
|
+
* This is an email: john.doe@example.com .
|
12
|
+
* URL with ampersand: http://www.example.com/?doit&x=y !
|
13
|
+
|
14
|
+
> It works even inside other blocks: https://www.google.com
|
15
|
+
|
16
|
+
```
|
17
|
+
Doesn't work inside code-blocks: https://www.google.com
|
18
|
+
```
|
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
<p>Group: <a href="https://gitlab.com/group_name">@group_name</a></p>
|
4
4
|
|
5
|
+
<p>Subgroup: <a href="https://gitlab.com/maingroup123/group_name">@maingroup123/group_name</a></p>
|
6
|
+
|
5
7
|
<p>Project Issue: <a href="https://gitlab.com/group_name/project_name/issues/12345">group_name/project_name#12345</a></p>
|
6
8
|
|
7
9
|
<p>Merge Request: <a href="https://gitlab.com/group_name/project_name/merge_requests/12345">group_name/project_name!12345</a></p>
|
8
10
|
|
9
11
|
<p>Project Snippet: <a href="https://gitlab.com/group_name/project_name/snippets/12345">group_name/project_name$12345</a></p>
|
10
12
|
|
11
|
-
<p>Project Commit: <a href="https://gitlab.com/group_name/project_name/commit/9ba12248">group_name/project_name@9ba12248</a></p>
|
13
|
+
<p>Project Commit: <a href="https://gitlab.com/group_name/project_name/commit/9ba12248">group_name/project_name@9ba12248</a> not to get confused by email: <a href="mailto:john.doe@example.com">john.doe@example.com</a></p>
|
12
14
|
|
13
15
|
<p>Project Commit Range comparison: <a href="https://gitlab.com/group_name/project_name/compare/9ba12248...b19a04f5">group_name/project_name@9ba12248...b19a04f5</a></p>
|
14
16
|
|
@@ -2,13 +2,15 @@ User: @user_name
|
|
2
2
|
|
3
3
|
Group: @group_name
|
4
4
|
|
5
|
+
Subgroup: @maingroup123/group_name
|
6
|
+
|
5
7
|
Project Issue: group_name/project_name#12345
|
6
8
|
|
7
9
|
Merge Request: group_name/project_name!12345
|
8
10
|
|
9
11
|
Project Snippet: group_name/project_name$12345
|
10
12
|
|
11
|
-
Project Commit: group_name/project_name@9ba12248
|
13
|
+
Project Commit: group_name/project_name@9ba12248 not to get confused by email: john.doe@example.com
|
12
14
|
|
13
15
|
Project Commit Range comparison: group_name/project_name@9ba12248...b19a04f5
|
14
16
|
|
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
|
+
version: 0.4.0
|
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
|
+
date: 2018-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -145,11 +145,14 @@ files:
|
|
145
145
|
- gitlab_kramdown.gemspec
|
146
146
|
- lib/gitlab_kramdown.rb
|
147
147
|
- lib/gitlab_kramdown/parser.rb
|
148
|
+
- lib/gitlab_kramdown/parser/autolink.rb
|
148
149
|
- lib/gitlab_kramdown/parser/fenced_blockquote.rb
|
149
150
|
- lib/gitlab_kramdown/parser/fenced_codeblock.rb
|
150
151
|
- lib/gitlab_kramdown/parser/header.rb
|
151
152
|
- lib/gitlab_kramdown/parser/reference.rb
|
152
153
|
- lib/kramdown/parser/gitlab_kramdown.rb
|
154
|
+
- spec/fixtures/autolink.html
|
155
|
+
- spec/fixtures/autolink.text
|
153
156
|
- spec/fixtures/code_highlight.html
|
154
157
|
- spec/fixtures/code_highlight.text
|
155
158
|
- spec/fixtures/header.html
|