gitlab_kramdown 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: 8111e5ed2d1d7557b1e1de41fe5f5d45d9bb9225
4
- data.tar.gz: 76f39ec6a1a591acdd213ff2a2e3844840b61b26
3
+ metadata.gz: 0c302bd8a4d80884d60ae30af2e340bd5eeeafd2
4
+ data.tar.gz: ac9dd5677dde90928873a3b7fad43b9fa1472f82
5
5
  SHA512:
6
- metadata.gz: '0938e8bd16e0a6f6886ef7031074665fdd8e01d044162d1ab861c7aa4899c8a34d803022a9e150f4bd5db0de2aea2310e97c1b8c400e6bf4590ed776c6467bc0'
7
- data.tar.gz: b95d7735ae88b1847ca218ff2616ace5a0a20eb204b4aa25a0391daae5cdc8157254acde364979ac5c6892fd26d0941403bd4ff916a8359d9de2ae951842c376
6
+ metadata.gz: a1b66031f521c04b81ae3cd49a868a326b46784a56b12962870b2ad3c7d0600c75c0c53d52ec5d274db433e5f075b6f48ec4de926f329b0aa573d56a2f4abbfe
7
+ data.tar.gz: d987318ef35170813d4d90a4a44583d9865a079e84d248f9b3067b7a6f1406af0a4c3c772dc626d4d3eb67d1ec1ff509351a9ccee540b998d3e46e3915455958
data/.gitlab-ci.yml CHANGED
@@ -1,9 +1,10 @@
1
1
  image: "ruby:2.4"
2
2
 
3
3
  # Cache gems in between builds
4
- cache:
4
+ cache: &cache
5
5
  paths:
6
6
  - vendor/ruby
7
+ key: 'ruby2.4'
7
8
 
8
9
  before_script:
9
10
  - ruby -v # Print out ruby version for debugging
@@ -14,6 +15,14 @@ rubocop:
14
15
  script:
15
16
  - rubocop
16
17
 
17
- rspec:
18
+ rspec ruby2.4:
19
+ script:
20
+ - rake spec
21
+
22
+ rspec ruby2.5:
23
+ image: "ruby:2.5"
24
+ cache:
25
+ <<: *cache
26
+ key: 'ruby2.5'
18
27
  script:
19
28
  - rake spec
data/.rubocop.yml CHANGED
@@ -3,6 +3,7 @@ AllCops:
3
3
  - '**/Rakefile'
4
4
  - 'Gemfile'
5
5
  - 'vendor/**/**'
6
+ - '*.gemspec'
6
7
  Layout/IndentArray:
7
8
  EnforcedStyle: consistent
8
9
  Metrics/LineLength:
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.0] - 2018-03-19
10
+ ### Added
11
+ - Syntax highlighter uses ``` or ~~~
12
+
13
+ ### Changed
14
+ - Requires Ruby 2.4
15
+ - Requires rouge `~> 3.0`
16
+
17
+ ## [0.1.0] - 2018-03-17
18
+ ### Added
19
+ - The initial version of the Gem
20
+ - Special GitLab References
21
+ - Multiline Blockquote
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem 'kramdown', '~> 1.16'
4
+ gem 'rouge', '~> 3.0'
4
5
 
5
6
  group :development do
6
7
  gem 'rdoc', '~> 3.12'
data/Gemfile.lock CHANGED
@@ -55,6 +55,7 @@ GEM
55
55
  rake (12.3.0)
56
56
  rdoc (3.12.2)
57
57
  json (~> 1.4)
58
+ rouge (3.1.1)
58
59
  rspec (3.7.0)
59
60
  rspec-core (~> 3.7.0)
60
61
  rspec-expectations (~> 3.7.0)
@@ -93,6 +94,7 @@ DEPENDENCIES
93
94
  juwelier (~> 2.1.0)
94
95
  kramdown (~> 1.16)
95
96
  rdoc (~> 3.12)
97
+ rouge (~> 3.0)
96
98
  rspec
97
99
  rubocop
98
100
  simplecov
data/README.md CHANGED
@@ -2,6 +2,60 @@
2
2
 
3
3
  This is an unofficial gem that implements [GitLab flavored Markdown] extensions on top of [Kramdown]
4
4
 
5
+ ## GitLab Flavored Markdown extensions support
6
+
7
+ This is a list of GitLab Flavored Markdown (GFM) extensions and their status of support on this gem:
8
+
9
+ | GFM Extensions | Implemented? |
10
+ |---------------------------------|--------------|
11
+ | [Newlines] | No |
12
+ | [Multiple underscores in words] | _Kramdown_ |
13
+ | [URL auto-linking] | No |
14
+ | [Multiline Blockquote] | **Yes** |
15
+ | [Code and Syntax Highlighting] | **Yes** |
16
+ | [Inline Diff] | No |
17
+ | [Emoji] | No |
18
+ | [Special GitLab references] | **Yes** |
19
+ | [Task Lists] | No |
20
+ | [Videos] | No |
21
+ | [Math] | No |
22
+ | [Colors] | No |
23
+ | [Mermaid] | No |
24
+
25
+ > **Note**: Extensions marked as `Kramdown` in the `Implemented?` means behavior already exists
26
+ in Kramdown flavor.
27
+
28
+ ## Usage example
29
+
30
+ To use this gem you're also required to install [Kramdown]. This gem will hook into Kramdown and provide custom
31
+ parser.
32
+
33
+ ```ruby
34
+ require 'kramdown'
35
+ require 'gitlab_kramdown'
36
+
37
+ source = <<-EOF
38
+ # GFM example
39
+
40
+ We support custom extensions like:
41
+
42
+ >>>
43
+ This is a multiline
44
+ Blockquote
45
+
46
+ Using `>>>` as delimiter
47
+ >>>
48
+ EOF
49
+
50
+ Kramdown::Document.new(source, input: 'GitlabKramdown').to_html
51
+ ```
52
+
53
+ To have also syntax highlighting using the same engine GitLab use, you need to define the highlighter as `:rouge`:
54
+
55
+ ```ruby
56
+ Kramdown::Document.new(source, input: 'GitlabKramdown', syntax_highlighter: :rouge).to_html
57
+ ```
58
+
5
59
  ## Contributing to gitlab_kramdown
6
60
 
7
61
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -10,7 +64,8 @@ This is an unofficial gem that implements [GitLab flavored Markdown] extensions
10
64
  * Start a feature/bugfix branch.
11
65
  * Commit and push until you are happy with your contribution.
12
66
  * 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.
67
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version,
68
+ or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
69
 
15
70
  ## Copyright
16
71
 
@@ -19,3 +74,16 @@ further details.
19
74
 
20
75
  [GitLab flavored Markdown]: https://docs.gitlab.com/ee/user/markdown.html
21
76
  [Kramdown]: https://kramdown.gettalong.org/
77
+ [Newlines]: https://docs.gitlab.com/ee/user/markdown.html#newlines
78
+ [Multiple underscores in words]: https://docs.gitlab.com/ee/user/markdown.html#multiple-underscores-in-words
79
+ [URL auto-linking]: https://docs.gitlab.com/ee/user/markdown.html#url-auto-linking
80
+ [Multiline Blockquote]: https://docs.gitlab.com/ee/user/markdown.html#multiline-blockquote
81
+ [Code and Syntax Highlighting]: https://docs.gitlab.com/ee/user/markdown.html#code-and-syntax-highlighting
82
+ [Inline Diff]: https://docs.gitlab.com/ee/user/markdown.html#inline-diff
83
+ [Emoji]: https://docs.gitlab.com/ee/user/markdown.html#emoji
84
+ [Special GitLab references]: https://docs.gitlab.com/ee/user/markdown.html#special-gitlab-references
85
+ [Task Lists]: https://docs.gitlab.com/ee/user/markdown.html#task-lists
86
+ [Videos]: https://docs.gitlab.com/ee/user/markdown.html#videos
87
+ [Math]: https://docs.gitlab.com/ee/user/markdown.html#math
88
+ [Colors]: https://docs.gitlab.com/ee/user/markdown.html#colors
89
+ [Mermaid]: https://docs.gitlab.com/ee/user/markdown.html#mermaid
data/Rakefile CHANGED
@@ -18,6 +18,7 @@ Juwelier::Tasks.new do |gem|
18
18
  gem.description = %Q{GitLab Flavored Markdown extensions on top of Kramdown markup. Tries to be as close as possible to existing extensions.}
19
19
  gem.email = "brodock@gmail.com"
20
20
  gem.authors = ["Gabriel Mazetto"]
21
+ gem.required_ruby_version = '~> 2.4'
21
22
 
22
23
  # dependencies defined in Gemfile
23
24
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -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.1.0 ruby lib
5
+ # stub: gitlab_kramdown 0.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "gitlab_kramdown".freeze
9
- s.version = "0.1.0"
9
+ s.version = "0.2.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-03-17"
14
+ s.date = "2018-03-19"
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 = [
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  ".gitlab-ci.yml",
24
24
  ".rubocop.yml",
25
25
  ".ruby-version",
26
+ "CHANGELOG.md",
26
27
  "Gemfile",
27
28
  "Gemfile.lock",
28
29
  "LICENSE.txt",
@@ -33,8 +34,11 @@ Gem::Specification.new do |s|
33
34
  "lib/gitlab_kramdown.rb",
34
35
  "lib/gitlab_kramdown/parser.rb",
35
36
  "lib/gitlab_kramdown/parser/fenced_blockquote.rb",
37
+ "lib/gitlab_kramdown/parser/fenced_codeblock.rb",
36
38
  "lib/gitlab_kramdown/parser/reference.rb",
37
39
  "lib/kramdown/parser/gitlab_kramdown.rb",
40
+ "spec/fixtures/code_highlight.html",
41
+ "spec/fixtures/code_highlight.text",
38
42
  "spec/fixtures/multi_blockquote.html",
39
43
  "spec/fixtures/multi_blockquote.text",
40
44
  "spec/fixtures/references.html",
@@ -45,6 +49,7 @@ Gem::Specification.new do |s|
45
49
  ]
46
50
  s.homepage = "http://gitlab.com/brodock/gitlab_kramdown".freeze
47
51
  s.licenses = ["MIT".freeze]
52
+ s.required_ruby_version = Gem::Requirement.new("~> 2.4".freeze)
48
53
  s.rubygems_version = "2.6.14".freeze
49
54
  s.summary = "GitLab Flavored Kramdown".freeze
50
55
 
@@ -53,6 +58,7 @@ Gem::Specification.new do |s|
53
58
 
54
59
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
60
  s.add_runtime_dependency(%q<kramdown>.freeze, ["~> 1.16"])
61
+ s.add_runtime_dependency(%q<rouge>.freeze, ["~> 3.0"])
56
62
  s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
57
63
  s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
58
64
  s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
@@ -61,6 +67,7 @@ Gem::Specification.new do |s|
61
67
  s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
62
68
  else
63
69
  s.add_dependency(%q<kramdown>.freeze, ["~> 1.16"])
70
+ s.add_dependency(%q<rouge>.freeze, ["~> 3.0"])
64
71
  s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
65
72
  s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
66
73
  s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
@@ -70,6 +77,7 @@ Gem::Specification.new do |s|
70
77
  end
71
78
  else
72
79
  s.add_dependency(%q<kramdown>.freeze, ["~> 1.16"])
80
+ s.add_dependency(%q<rouge>.freeze, ["~> 3.0"])
73
81
  s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
74
82
  s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
75
83
  s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabKramdown
4
+ module Parser
5
+ # Fenced Codeblock
6
+ #
7
+ # This parser implements codeblocks fenced by ``` or ~~~
8
+ #
9
+ # With a codeblock you can pass the language after the initial fenced separator
10
+ # and use one of Kramdowns syntax highlighters
11
+ #
12
+ # For maximum compatibility with GitLab, use `:rouge` as your highlighter.
13
+ #
14
+ # @see https://docs.gitlab.com/ee/user/markdown.html#code-and-syntax-highlighting
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
18
+
19
+ def self.included(klass)
20
+ klass.define_parser(:codeblock_fenced_gitlab, FENCED_CODEBLOCK_START, nil, 'parse_codeblock_fenced')
21
+ end
22
+ end
23
+ end
24
+ end
@@ -6,6 +6,7 @@ module GitlabKramdown
6
6
  # All GitLab extensions to Kramdown are implemented as a Parser in this module
7
7
  module Parser
8
8
  autoload :FencedBlockquote, 'gitlab_kramdown/parser/fenced_blockquote'
9
+ autoload :FencedCodeblock, 'gitlab_kramdown/parser/fenced_codeblock'
9
10
  autoload :Reference, 'gitlab_kramdown/parser/reference'
10
11
  end
11
12
  end
@@ -9,16 +9,35 @@ module Kramdown
9
9
  # This is not 100% compatible with GFM used in GitLab application as it
10
10
  # includes extensions available only in kramdown.
11
11
  class GitlabKramdown < Kramdown::Parser::Kramdown
12
+ include ::GitlabKramdown::Parser::FencedBlockquote
13
+ include ::GitlabKramdown::Parser::FencedCodeblock
14
+ include ::GitlabKramdown::Parser::Reference
15
+
12
16
  def initialize(source, options)
13
17
  super
14
18
 
15
19
  @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)
20
+ prepend_span_parsers(:commit_diff, :commit, :user_group_mention, :issue, :merge_request, :snippet, :label)
21
+ prepend_block_parsers(:fenced_blockquote)
22
+ replace_block_parser!(:codeblock_fenced, :codeblock_fenced_gitlab)
18
23
  end
19
24
 
20
- include ::GitlabKramdown::Parser::FencedBlockquote
21
- include ::GitlabKramdown::Parser::Reference
25
+ private
26
+
27
+ def replace_block_parser!(original, new)
28
+ index = @block_parsers.index(original)
29
+
30
+ return false unless index
31
+ @block_parsers[index] = new
32
+ end
33
+
34
+ def prepend_span_parsers(*parsers)
35
+ @span_parsers.unshift(*parsers)
36
+ end
37
+
38
+ def prepend_block_parsers(*parsers)
39
+ @block_parsers.unshift(*parsers)
40
+ end
22
41
  end
23
42
  end
24
43
  end
@@ -0,0 +1,18 @@
1
+ <p>This is a code block using 4 spaces syntax:
2
+ class Something
3
+ def method(param)
4
+ end
5
+ end</p>
6
+
7
+ <p>This is a code block using 3-backticks ```:</p>
8
+
9
+ <pre><code>This is a code block without any specific language
10
+ </code></pre>
11
+
12
+ <p>This is a code block specifying a language:</p>
13
+
14
+ <pre><code class="language-ruby">class Something
15
+ def method(param)
16
+ end
17
+ end
18
+ </code></pre>
@@ -0,0 +1,20 @@
1
+ This is a code block using 4 spaces syntax:
2
+ class Something
3
+ def method(param)
4
+ end
5
+ end
6
+
7
+ This is a code block using 3-backticks ```:
8
+
9
+ ```
10
+ This is a code block without any specific language
11
+ ```
12
+
13
+ This is a code block specifying a language:
14
+
15
+ ```ruby
16
+ class Something
17
+ def method(param)
18
+ end
19
+ end
20
+ ```
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.1.0
4
+ version: 0.2.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-03-17 00:00:00.000000000 Z
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rouge
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rdoc
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -121,6 +135,7 @@ files:
121
135
  - ".gitlab-ci.yml"
122
136
  - ".rubocop.yml"
123
137
  - ".ruby-version"
138
+ - CHANGELOG.md
124
139
  - Gemfile
125
140
  - Gemfile.lock
126
141
  - LICENSE.txt
@@ -131,8 +146,11 @@ files:
131
146
  - lib/gitlab_kramdown.rb
132
147
  - lib/gitlab_kramdown/parser.rb
133
148
  - lib/gitlab_kramdown/parser/fenced_blockquote.rb
149
+ - lib/gitlab_kramdown/parser/fenced_codeblock.rb
134
150
  - lib/gitlab_kramdown/parser/reference.rb
135
151
  - lib/kramdown/parser/gitlab_kramdown.rb
152
+ - spec/fixtures/code_highlight.html
153
+ - spec/fixtures/code_highlight.text
136
154
  - spec/fixtures/multi_blockquote.html
137
155
  - spec/fixtures/multi_blockquote.text
138
156
  - spec/fixtures/references.html
@@ -150,9 +168,9 @@ require_paths:
150
168
  - lib
151
169
  required_ruby_version: !ruby/object:Gem::Requirement
152
170
  requirements:
153
- - - ">="
171
+ - - "~>"
154
172
  - !ruby/object:Gem::Version
155
- version: '0'
173
+ version: '2.4'
156
174
  required_rubygems_version: !ruby/object:Gem::Requirement
157
175
  requirements:
158
176
  - - ">="