gitlab_kramdown 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8111e5ed2d1d7557b1e1de41fe5f5d45d9bb9225
4
+ data.tar.gz: 76f39ec6a1a591acdd213ff2a2e3844840b61b26
5
+ SHA512:
6
+ metadata.gz: '0938e8bd16e0a6f6886ef7031074665fdd8e01d044162d1ab861c7aa4899c8a34d803022a9e150f4bd5db0de2aea2310e97c1b8c400e6bf4590ed776c6467bc0'
7
+ data.tar.gz: b95d7735ae88b1847ca218ff2616ace5a0a20eb204b4aa25a0391daae5cdc8157254acde364979ac5c6892fd26d0941403bd4ff916a8359d9de2ae951842c376
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,19 @@
1
+ image: "ruby:2.4"
2
+
3
+ # Cache gems in between builds
4
+ cache:
5
+ paths:
6
+ - vendor/ruby
7
+
8
+ before_script:
9
+ - ruby -v # Print out ruby version for debugging
10
+ - gem install bundler --no-ri --no-rdoc # Bundler is not installed with the image
11
+ - bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
12
+
13
+ rubocop:
14
+ script:
15
+ - rubocop
16
+
17
+ rspec:
18
+ script:
19
+ - rake spec
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ Exclude:
3
+ - '**/Rakefile'
4
+ - 'Gemfile'
5
+ - 'vendor/**/**'
6
+ Layout/IndentArray:
7
+ EnforcedStyle: consistent
8
+ Metrics/LineLength:
9
+ Max: 120
10
+ Style/FrozenStringLiteralComment:
11
+ Exclude:
12
+ - 'spec/**/**'
13
+ Style/RegexpLiteral:
14
+ EnforcedStyle: mixed
15
+ Metrics/MethodLength:
16
+ Enabled: false
17
+ Metrics/ModuleLength:
18
+ Enabled: false
@@ -0,0 +1 @@
1
+ ruby-2.4.3
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'kramdown', '~> 1.16'
4
+
5
+ group :development do
6
+ gem 'rdoc', '~> 3.12'
7
+ gem 'bundler', '~> 1.0'
8
+ gem 'juwelier', '~> 2.1.0'
9
+ gem 'simplecov', '>= 0'
10
+ gem 'rubocop'
11
+ gem 'rspec'
12
+ end
@@ -0,0 +1,101 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.5.2)
5
+ public_suffix (>= 2.0.2, < 4.0)
6
+ ast (2.4.0)
7
+ builder (3.2.3)
8
+ descendants_tracker (0.0.4)
9
+ thread_safe (~> 0.3, >= 0.3.1)
10
+ diff-lcs (1.3)
11
+ docile (1.1.5)
12
+ faraday (0.12.2)
13
+ multipart-post (>= 1.2, < 3)
14
+ git (1.3.0)
15
+ github_api (0.18.2)
16
+ addressable (~> 2.4)
17
+ descendants_tracker (~> 0.0.4)
18
+ faraday (~> 0.8)
19
+ hashie (~> 3.5, >= 3.5.2)
20
+ oauth2 (~> 1.0)
21
+ hashie (3.5.7)
22
+ highline (1.7.10)
23
+ json (1.8.6)
24
+ juwelier (2.1.3)
25
+ builder
26
+ bundler (>= 1.13)
27
+ git (>= 1.2.5)
28
+ github_api
29
+ highline (>= 1.6.15)
30
+ nokogiri (>= 1.5.10)
31
+ rake
32
+ rdoc
33
+ semver
34
+ jwt (1.5.6)
35
+ kramdown (1.16.2)
36
+ mini_portile2 (2.3.0)
37
+ multi_json (1.13.1)
38
+ multi_xml (0.6.0)
39
+ multipart-post (2.0.0)
40
+ nokogiri (1.8.2)
41
+ mini_portile2 (~> 2.3.0)
42
+ oauth2 (1.4.0)
43
+ faraday (>= 0.8, < 0.13)
44
+ jwt (~> 1.0)
45
+ multi_json (~> 1.3)
46
+ multi_xml (~> 0.5)
47
+ rack (>= 1.2, < 3)
48
+ parallel (1.12.1)
49
+ parser (2.5.0.2)
50
+ ast (~> 2.4.0)
51
+ powerpack (0.1.1)
52
+ public_suffix (3.0.2)
53
+ rack (2.0.4)
54
+ rainbow (3.0.0)
55
+ rake (12.3.0)
56
+ rdoc (3.12.2)
57
+ json (~> 1.4)
58
+ rspec (3.7.0)
59
+ rspec-core (~> 3.7.0)
60
+ rspec-expectations (~> 3.7.0)
61
+ rspec-mocks (~> 3.7.0)
62
+ rspec-core (3.7.1)
63
+ rspec-support (~> 3.7.0)
64
+ rspec-expectations (3.7.0)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.7.0)
67
+ rspec-mocks (3.7.0)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.7.0)
70
+ rspec-support (3.7.1)
71
+ rubocop (0.52.1)
72
+ parallel (~> 1.10)
73
+ parser (>= 2.4.0.2, < 3.0)
74
+ powerpack (~> 0.1)
75
+ rainbow (>= 2.2.2, < 4.0)
76
+ ruby-progressbar (~> 1.7)
77
+ unicode-display_width (~> 1.0, >= 1.0.1)
78
+ ruby-progressbar (1.9.0)
79
+ semver (1.0.1)
80
+ simplecov (0.15.1)
81
+ docile (~> 1.1.0)
82
+ json (>= 1.8, < 3)
83
+ simplecov-html (~> 0.10.0)
84
+ simplecov-html (0.10.2)
85
+ thread_safe (0.3.6)
86
+ unicode-display_width (1.3.0)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ bundler (~> 1.0)
93
+ juwelier (~> 2.1.0)
94
+ kramdown (~> 1.16)
95
+ rdoc (~> 3.12)
96
+ rspec
97
+ rubocop
98
+ simplecov
99
+
100
+ BUNDLED WITH
101
+ 1.16.1
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2018 Gabriel Mazetto
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # GitLab Kramdown
2
+
3
+ This is an unofficial gem that implements [GitLab flavored Markdown] extensions on top of [Kramdown]
4
+
5
+ ## Contributing to gitlab_kramdown
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ ## Copyright
16
+
17
+ Copyright (c) 2018 Gabriel Mazetto. See LICENSE.txt for
18
+ further details.
19
+
20
+ [GitLab flavored Markdown]: https://docs.gitlab.com/ee/user/markdown.html
21
+ [Kramdown]: https://kramdown.gettalong.org/
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+ require 'juwelier'
12
+ Juwelier::Tasks.new do |gem|
13
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
14
+ gem.name = "gitlab_kramdown"
15
+ gem.homepage = "http://gitlab.com/brodock/gitlab_kramdown"
16
+ gem.license = "MIT"
17
+ gem.summary = %Q{GitLab Flavored Kramdown}
18
+ gem.description = %Q{GitLab Flavored Markdown extensions on top of Kramdown markup. Tries to be as close as possible to existing extensions.}
19
+ gem.email = "brodock@gmail.com"
20
+ gem.authors = ["Gabriel Mazetto"]
21
+
22
+ # dependencies defined in Gemfile
23
+ end
24
+ Juwelier::RubygemsDotOrgTasks.new
25
+
26
+ require 'rspec'
27
+ require 'rspec/core/rake_task'
28
+ desc "Run all examples"
29
+ RSpec::Core::RakeTask.new(:spec) do |t|
30
+ t.ruby_opts = %w[-w]
31
+ t.rspec_opts = %w[--color]
32
+ end
33
+
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['spec'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "gitlab_kramdown #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,81 @@
1
+ # Generated by juwelier
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: gitlab_kramdown 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "gitlab_kramdown".freeze
9
+ s.version = "0.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Gabriel Mazetto".freeze]
14
+ s.date = "2018-03-17"
15
+ s.description = "GitLab Flavored Markdown extensions on top of Kramdown markup. Tries to be as close as possible to existing extensions.".freeze
16
+ s.email = "brodock@gmail.com".freeze
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitlab-ci.yml",
24
+ ".rubocop.yml",
25
+ ".ruby-version",
26
+ "Gemfile",
27
+ "Gemfile.lock",
28
+ "LICENSE.txt",
29
+ "README.md",
30
+ "Rakefile",
31
+ "VERSION",
32
+ "gitlab_kramdown.gemspec",
33
+ "lib/gitlab_kramdown.rb",
34
+ "lib/gitlab_kramdown/parser.rb",
35
+ "lib/gitlab_kramdown/parser/fenced_blockquote.rb",
36
+ "lib/gitlab_kramdown/parser/reference.rb",
37
+ "lib/kramdown/parser/gitlab_kramdown.rb",
38
+ "spec/fixtures/multi_blockquote.html",
39
+ "spec/fixtures/multi_blockquote.text",
40
+ "spec/fixtures/references.html",
41
+ "spec/fixtures/references.text",
42
+ "spec/integration/parser_spec.rb",
43
+ "spec/spec_helper.rb",
44
+ "spec/support/fixtures.rb"
45
+ ]
46
+ s.homepage = "http://gitlab.com/brodock/gitlab_kramdown".freeze
47
+ s.licenses = ["MIT".freeze]
48
+ s.rubygems_version = "2.6.14".freeze
49
+ s.summary = "GitLab Flavored Kramdown".freeze
50
+
51
+ if s.respond_to? :specification_version then
52
+ s.specification_version = 4
53
+
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_runtime_dependency(%q<kramdown>.freeze, ["~> 1.16"])
56
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
57
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
58
+ s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
59
+ s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
60
+ s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
61
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
62
+ else
63
+ s.add_dependency(%q<kramdown>.freeze, ["~> 1.16"])
64
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
65
+ s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
66
+ s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
67
+ s.add_dependency(%q<simplecov>.freeze, [">= 0"])
68
+ s.add_dependency(%q<rubocop>.freeze, [">= 0"])
69
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
70
+ end
71
+ else
72
+ s.add_dependency(%q<kramdown>.freeze, ["~> 1.16"])
73
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
74
+ s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
75
+ s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
76
+ s.add_dependency(%q<simplecov>.freeze, [">= 0"])
77
+ s.add_dependency(%q<rubocop>.freeze, [">= 0"])
78
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
79
+ end
80
+ end
81
+
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kramdown/parser'
4
+
5
+ # GitLab Kramdown implements Markdown flavored extensions on top of Kramdown
6
+ #
7
+ # This modules includes parser extensions that will be available as `GitlabKramdown`
8
+ # input option for Kramdown gem.
9
+ #
10
+ # Not all extensions are available as some of the requires access to context information
11
+ # that is only available on GitLab application.
12
+ #
13
+ # To use Kramdown with this extensions initialize your Kramdown::Document with:
14
+ #
15
+ # Kramdown::Document.new(source, input: 'GitlabKramdown')
16
+ #
17
+ module GitlabKramdown
18
+ autoload :Parser, 'gitlab_kramdown/parser'
19
+ end
20
+
21
+ # Autoload extensions
22
+ Kramdown::Parser.autoload :GitlabKramdown, 'kramdown/parser/gitlab_kramdown'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabKramdown
4
+ # GitLab Kramdown Parser
5
+ #
6
+ # All GitLab extensions to Kramdown are implemented as a Parser in this module
7
+ module Parser
8
+ autoload :FencedBlockquote, 'gitlab_kramdown/parser/fenced_blockquote'
9
+ autoload :Reference, 'gitlab_kramdown/parser/reference'
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabKramdown
4
+ module Parser
5
+ # Multiline Blockquote
6
+ #
7
+ # This parser implements multiline blockquotes fenced by `>>>`
8
+ #
9
+ # @see https://docs.gitlab.com/ee/user/markdown.html#multiline-blockquote
10
+ module FencedBlockquote
11
+ FENCED_BLOCKQUOTE_START = />{3}/x
12
+
13
+ FENCED_BLOCKQUOTE_MATCH = %r{
14
+ ^(?<delimiter>>{3}) # line must start with >>>
15
+ \s* # any amount of trailling whitespace
16
+ \n # followed by a linebreak
17
+ (?<content>[\S\s]+) # at least one non whitespace chracter
18
+ \n
19
+ \k<delimiter> # same delimiter used to open the block
20
+ \s* # any amount of trailling whitespace
21
+ }xm
22
+
23
+ def self.included(klass)
24
+ klass.define_parser(:fenced_blockquote, FENCED_BLOCKQUOTE_START)
25
+ end
26
+
27
+ def parse_fenced_blockquote
28
+ if @src.check(FENCED_BLOCKQUOTE_MATCH)
29
+ start_line_number = @src.current_line_number
30
+ @src.pos += @src.matched_size
31
+
32
+ el = new_block_el(:blockquote, nil, nil, location: start_line_number)
33
+
34
+ content = parse_inner_fenced_content(@src[:content])
35
+ el.children = content
36
+ @tree.children << el
37
+ true
38
+ else
39
+ false
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def parse_inner_fenced_content(content)
46
+ parsed = Kramdown::Parser::GitlabKramdown.parse(content, @options)
47
+ parsed[0].children
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabKramdown
4
+ module Parser
5
+ # Special GitLab References
6
+ #
7
+ # This parser implements any non context-specific reference as described
8
+ # in the GitLab Flavored Markdown reference
9
+ #
10
+ # @see https://docs.gitlab.com/ee/user/markdown.html#special-gitlab-references
11
+ module Reference
12
+ PATH_REGEX_STR = '[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*'
13
+
14
+ NAMESPACE_FORMAT_REGEX = %r{
15
+ (?:#{PATH_REGEX_STR}[a-zA-Z0-9_\-]|[a-zA-Z0-9_])
16
+ (?<!\.git|\.atom)
17
+ }x
18
+
19
+ FULL_NAMESPACE_FORMAT_REGEX = %r{(#{NAMESPACE_FORMAT_REGEX}/)*#{NAMESPACE_FORMAT_REGEX}}
20
+
21
+ USER_GROUP_PATTERN = %r{
22
+ (?<!\w)
23
+ #{Regexp.escape('@')}
24
+ (?<user>#{FULL_NAMESPACE_FORMAT_REGEX})
25
+ }x
26
+
27
+ PROJECT_COMMIT_PATTERN = %r{
28
+ (?<namespace>#{FULL_NAMESPACE_FORMAT_REGEX})
29
+ #{Regexp.escape('@')}
30
+ (?<commit>[a-z0-9]+)
31
+ (?!\.{3})
32
+ }x
33
+
34
+ PROJECT_COMMIT_DIFF_PATTERN = %r{
35
+ (?<namespace>#{FULL_NAMESPACE_FORMAT_REGEX})
36
+ #{Regexp.escape('@')}
37
+ (?<commit_source>[a-z0-9]+)
38
+ \.{3}
39
+ (?<commit_target>[a-z0-9]+)
40
+ }x
41
+
42
+ PROJECT_ISSUE_PATTERN = %r{
43
+ (?<namespace>#{FULL_NAMESPACE_FORMAT_REGEX})
44
+ #{Regexp.escape('#')}
45
+ (?<issue>[1-9][0-9]*)
46
+ }x
47
+
48
+ PROJECT_MERGE_REQUEST_PATTERN = %r{
49
+ (?<namespace>#{FULL_NAMESPACE_FORMAT_REGEX})
50
+ #{Regexp.escape('!')}
51
+ (?<merge_request>[1-9][0-9]*)
52
+ }x
53
+
54
+ PROJECT_SNIPPET_PATTERN = %r{
55
+ (?<namespace>#{FULL_NAMESPACE_FORMAT_REGEX})
56
+ #{Regexp.escape('$')}
57
+ (?<snippet>[1-9][0-9]*)
58
+ }x
59
+
60
+ PROJECT_LABEL_PATTERN = %r{
61
+ (?<namespace>#{FULL_NAMESPACE_FORMAT_REGEX})
62
+ #{Regexp.escape('~')}
63
+ (?<label>
64
+ [A-Za-z0-9_\-\?\.&]+ | # String-based single-word label title, or
65
+ ".+?" # String-based multi-word label surrounded in quotes
66
+ )
67
+ }x
68
+
69
+ def self.included(klass)
70
+ klass.define_parser(:user_group_mention, USER_GROUP_PATTERN)
71
+ klass.define_parser(:commit, PROJECT_COMMIT_PATTERN)
72
+ klass.define_parser(:commit_diff, PROJECT_COMMIT_DIFF_PATTERN)
73
+ klass.define_parser(:issue, PROJECT_ISSUE_PATTERN)
74
+ klass.define_parser(:merge_request, PROJECT_MERGE_REQUEST_PATTERN)
75
+ klass.define_parser(:snippet, PROJECT_SNIPPET_PATTERN)
76
+ klass.define_parser(:label, PROJECT_LABEL_PATTERN)
77
+ end
78
+
79
+ def parse_user_group_mention
80
+ start_line_number = @src.current_line_number
81
+ @src.pos += @src.matched_size
82
+
83
+ href = "#{@options[:gitlab_url]}/#{@src[:user]}"
84
+
85
+ el = Kramdown::Element.new(:a, nil, { 'href' => href }, location: start_line_number)
86
+ add_text(@src[0], el)
87
+ @tree.children << el
88
+ end
89
+
90
+ def parse_commit
91
+ start_line_number = @src.current_line_number
92
+ @src.pos += @src.matched_size
93
+
94
+ href = "#{@options[:gitlab_url]}/#{@src[:namespace]}/commit/#{@src[:commit]}"
95
+
96
+ el = Kramdown::Element.new(:a, nil, { 'href' => href }, location: start_line_number)
97
+ add_text(@src[0], el)
98
+ @tree.children << el
99
+ end
100
+
101
+ def parse_commit_diff
102
+ start_line_number = @src.current_line_number
103
+ @src.pos += @src.matched_size
104
+
105
+ href = "#{@options[:gitlab_url]}/#{@src[:namespace]}/compare/" \
106
+ "#{@src[:commit_source]}...#{@src[:commit_target]}"
107
+
108
+ el = Kramdown::Element.new(:a, nil, { 'href' => href }, location: start_line_number)
109
+ add_text(@src[0], el)
110
+ @tree.children << el
111
+ end
112
+
113
+ def parse_issue
114
+ start_line_number = @src.current_line_number
115
+ @src.pos += @src.matched_size
116
+
117
+ href = "#{@options[:gitlab_url]}/#{@src[:namespace]}/issues/#{@src[:issue]}"
118
+
119
+ el = Kramdown::Element.new(:a, nil, { 'href' => href }, location: start_line_number)
120
+ add_text(@src[0], el)
121
+ @tree.children << el
122
+ end
123
+
124
+ def parse_merge_request
125
+ start_line_number = @src.current_line_number
126
+ @src.pos += @src.matched_size
127
+
128
+ href = "#{@options[:gitlab_url]}/#{@src[:namespace]}/merge_requests/#{@src[:merge_request]}"
129
+
130
+ el = Kramdown::Element.new(:a, nil, { 'href' => href }, location: start_line_number)
131
+ add_text(@src[0], el)
132
+ @tree.children << el
133
+ end
134
+
135
+ def parse_snippet
136
+ start_line_number = @src.current_line_number
137
+ @src.pos += @src.matched_size
138
+
139
+ href = "#{@options[:gitlab_url]}/#{@src[:namespace]}/snippets/#{@src[:snippet]}"
140
+
141
+ el = Kramdown::Element.new(:a, nil, { 'href' => href }, location: start_line_number)
142
+ add_text(@src[0], el)
143
+ @tree.children << el
144
+ end
145
+
146
+ def parse_label
147
+ start_line_number = @src.current_line_number
148
+ @src.pos += @src.matched_size
149
+
150
+ label_param = @src[:label].delete('"').tr(' ', '+')
151
+ href = "#{@options[:gitlab_url]}/#{@src[:namespace]}/issues?label_name=#{label_param}"
152
+
153
+ el = Kramdown::Element.new(:a, nil, { 'href' => href }, location: start_line_number)
154
+ add_text(@src[0], el)
155
+ @tree.children << el
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kramdown/parser'
4
+
5
+ module Kramdown
6
+ module Parser
7
+ # Used for parsing documents in GitLab Flavored Markdown like format.
8
+ #
9
+ # This is not 100% compatible with GFM used in GitLab application as it
10
+ # includes extensions available only in kramdown.
11
+ class GitlabKramdown < Kramdown::Parser::Kramdown
12
+ def initialize(source, options)
13
+ super
14
+
15
+ @options[:gitlab_url] = 'https://gitlab.com'
16
+ @span_parsers.unshift(:commit_diff, :commit, :user_group_mention, :issue, :merge_request, :snippet, :label)
17
+ @block_parsers.unshift(:fenced_blockquote)
18
+ end
19
+
20
+ include ::GitlabKramdown::Parser::FencedBlockquote
21
+ include ::GitlabKramdown::Parser::Reference
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ <blockquote>
2
+ <p>If you paste a message from somewhere else</p>
3
+
4
+ <p>that</p>
5
+
6
+ <p>spans</p>
7
+
8
+ <p>multiple lines,</p>
9
+
10
+ <p>you can quote that without having to manually prepend <code>&gt;</code> to every line!</p>
11
+ </blockquote>
@@ -0,0 +1,11 @@
1
+ >>>
2
+ If you paste a message from somewhere else
3
+
4
+ that
5
+
6
+ spans
7
+
8
+ multiple lines,
9
+
10
+ you can quote that without having to manually prepend `>` to every line!
11
+ >>>
@@ -0,0 +1,17 @@
1
+ <p>User: <a href="https://gitlab.com/user_name">@user_name</a></p>
2
+
3
+ <p>Group: <a href="https://gitlab.com/group_name">@group_name</a></p>
4
+
5
+ <p>Project Issue: <a href="https://gitlab.com/group_name/project_name/issues/12345">group_name/project_name#12345</a></p>
6
+
7
+ <p>Merge Request: <a href="https://gitlab.com/group_name/project_name/merge_requests/12345">group_name/project_name!12345</a></p>
8
+
9
+ <p>Project Snippet: <a href="https://gitlab.com/group_name/project_name/snippets/12345">group_name/project_name$12345</a></p>
10
+
11
+ <p>Project Commit: <a href="https://gitlab.com/group_name/project_name/commit/9ba12248">group_name/project_name@9ba12248</a></p>
12
+
13
+ <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
+
15
+ <p>Project Label: <a href="https://gitlab.com/group_name/project_name/issues?label_name=label">group_name/project_name~label</a></p>
16
+
17
+ <p>Project Label with Space: <a href="https://gitlab.com/group_name/project_name/issues?label_name=Some+label">group_name/project_name~"Some label"</a></p>
@@ -0,0 +1,17 @@
1
+ User: @user_name
2
+
3
+ Group: @group_name
4
+
5
+ Project Issue: group_name/project_name#12345
6
+
7
+ Merge Request: group_name/project_name!12345
8
+
9
+ Project Snippet: group_name/project_name$12345
10
+
11
+ Project Commit: group_name/project_name@9ba12248
12
+
13
+ Project Commit Range comparison: group_name/project_name@9ba12248...b19a04f5
14
+
15
+ Project Label: group_name/project_name~label
16
+
17
+ Project Label with Space: group_name/project_name~"Some label"
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ context 'GitLab Kramdown Integration tests' do
4
+ let(:options) do
5
+ { input: 'GitlabKramdown' }
6
+ end
7
+
8
+ context 'HTML render' do
9
+ Fixtures.text_files.each do |text_file|
10
+ it "Renders #{File.basename(text_file)} as #{File.basename(Fixtures.html_file(text_file))}" do
11
+ source = File.read(text_file)
12
+ target = File.read(Fixtures.html_file(text_file))
13
+ parser = Kramdown::Document.new(source, options)
14
+
15
+ expect(parser.to_html).to eq(target)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ Bundler.setup
5
+
6
+ require 'simplecov'
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
8
+ SimpleCov::Formatter::HTMLFormatter
9
+ ])
10
+ SimpleCov.start { add_filter '/spec/' }
11
+
12
+ require 'kramdown'
13
+ require 'gitlab_kramdown'
14
+
15
+ # Load support files
16
+ Dir[File.join('./spec/support/**/*.rb')].each { |f| require f }
17
+
18
+ RSpec.configure do |config|
19
+ # some (optional) config here
20
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fixtures
4
+ def self.text_files
5
+ Dir[File.join(folder, '**/*.text')]
6
+ end
7
+
8
+ def self.html_file(text_file)
9
+ text_file.sub('.text', '.html')
10
+ end
11
+
12
+ def self.folder
13
+ File.expand_path(File.join(File.dirname(__FILE__), '../fixtures'))
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitlab_kramdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Mazetto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kramdown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: juwelier
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: GitLab Flavored Markdown extensions on top of Kramdown markup. Tries
112
+ to be as close as possible to existing extensions.
113
+ email: brodock@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files:
117
+ - LICENSE.txt
118
+ - README.md
119
+ files:
120
+ - ".document"
121
+ - ".gitlab-ci.yml"
122
+ - ".rubocop.yml"
123
+ - ".ruby-version"
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - VERSION
130
+ - gitlab_kramdown.gemspec
131
+ - lib/gitlab_kramdown.rb
132
+ - lib/gitlab_kramdown/parser.rb
133
+ - lib/gitlab_kramdown/parser/fenced_blockquote.rb
134
+ - lib/gitlab_kramdown/parser/reference.rb
135
+ - lib/kramdown/parser/gitlab_kramdown.rb
136
+ - spec/fixtures/multi_blockquote.html
137
+ - spec/fixtures/multi_blockquote.text
138
+ - spec/fixtures/references.html
139
+ - spec/fixtures/references.text
140
+ - spec/integration/parser_spec.rb
141
+ - spec/spec_helper.rb
142
+ - spec/support/fixtures.rb
143
+ homepage: http://gitlab.com/brodock/gitlab_kramdown
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.6.14
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: GitLab Flavored Kramdown
167
+ test_files: []