gitlab_kramdown 0.4.2 → 0.5.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
  SHA256:
3
- metadata.gz: f56f5ad5ed710fefd24289c68ec7fe621f67261875def66fc7c4588a1a3f4930
4
- data.tar.gz: 023f11be46858b9fff9cbf7aaf880629b665155aeb95f6f8804ff3fab19fd992
3
+ metadata.gz: 863ff5cdca8cd14c9de1619a1fcb4512ad12ae602a688097a4f3a03d85483d77
4
+ data.tar.gz: 4adb0e3732d0bf380c1e8b7afc0bc6ae4db90a39d51a6a81489d02025a5c9629
5
5
  SHA512:
6
- metadata.gz: 41affa513909efce3c3aed46a185d0e2220dd96a64a54a33d0862aabf71fd21a46cc8fa3992966284e31a8deb6e0c0e38131427f3e0ab96d3e31d50f6ee94222
7
- data.tar.gz: 2ad36ecf7f2b4003f1c7fbec5f99208be2e5098de42ad4bd129ff38004eaca9d334e1ac94eae14ca3dcbe84cfa39b4090227524c308d0b72c9492c0a82708c60
6
+ metadata.gz: c8d9d12504b784b056dd2ef6e49bfb9664b454b1fefd6242c388a3e6ffc52bc18d0706bd08eb907b3a5759e8cf4ac84647e4a4ac3c55334d862b65042181f6b7
7
+ data.tar.gz: 131c9a44c743e52ddcb74684c2236155ad89c54b073b80b1887e4213a043c821a56fcc042b1e27eb69596ae54032e17be5a71474a8adf2ecc25a057c140fe452
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2018 Gabriel Mazetto
1
+ Copyright (c) 2018-2019 Gabriel Mazetto
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # GitLab Kramdown
2
2
 
3
- This is an official gem that implements [GitLab flavored Markdown] extensions on top of [Kramdown].
3
+ This is an official gem that implements [GitLab flavored Markdown] extensions on top of [Kramdown].
4
4
 
5
- > **Note**: This is not the same code that runs on GitLab. The [GitLab flavored Markdown] runs on top of
6
- CommonMark with extensions implemented inside the Rails application.
5
+ > **Note**: This is not the same code that runs on GitLab. The [GitLab flavored Markdown] runs on top of
6
+ CommonMark with extensions implemented inside the Rails application.
7
7
 
8
8
  ## GitLab Flavored Markdown extensions support
9
9
 
@@ -17,6 +17,7 @@ This is a list of GitLab Flavored Markdown (GFM) extensions and their status of
17
17
  | [URL auto-linking] | **Yes** |
18
18
  | [Multiline Blockquote] | **Yes** |
19
19
  | [Code and Syntax Highlighting] | **Yes** |
20
+ | [Strikethrough] | **Yes** |
20
21
  | [Inline Diff] | No |
21
22
  | [Emoji] | No |
22
23
  | [Special GitLab references] | **Yes** |
@@ -26,16 +27,16 @@ This is a list of GitLab Flavored Markdown (GFM) extensions and their status of
26
27
  | [Colors] | No |
27
28
  | [Mermaid] | No |
28
29
 
29
- > **Note**: Extensions marked as `Kramdown` in the `Implemented?` means behavior already exists
30
+ > **Note**: Extensions marked as `Kramdown` in the `Implemented?` means behavior already exists
30
31
  in Kramdown flavor.
31
-
32
+
32
33
  ## Configuration parameters
33
34
 
34
35
  | Parameter | Default | Description |
35
36
  | :------------------| :------------------: | -------------------------------------------- |
36
37
  | `gitlab_url` | `https://gitlab.com` | GitLab instance URL to build reference links |
37
- | `linkable_headers` | true | Generate anchor tags with headers? |
38
-
38
+ | `linkable_headers` | true | Generate anchor tags with headers? |
39
+
39
40
  ## Usage example
40
41
 
41
42
  To use this gem you're also required to install [Kramdown]. This gem will hook into Kramdown and provide custom
@@ -54,8 +55,8 @@ We support custom extensions like:
54
55
  This is a multiline
55
56
  Blockquote
56
57
 
57
- Using `>>>` as delimiter
58
- >>>
58
+ Using `>>>` as delimiter
59
+ >>>
59
60
  EOF
60
61
 
61
62
  Kramdown::Document.new(source, input: 'GitlabKramdown').to_html
@@ -75,12 +76,12 @@ Kramdown::Document.new(source, input: 'GitlabKramdown', syntax_highlighter: :rou
75
76
  * Start a feature/bugfix branch.
76
77
  * Commit and push until you are happy with your contribution.
77
78
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
78
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version,
79
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version,
79
80
  or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
80
81
 
81
82
  ## Copyright
82
83
 
83
- Copyright (c) 2018 Gabriel Mazetto. See LICENSE.txt for
84
+ Copyright (c) 2018-2019 Gabriel Mazetto. See LICENSE.txt for
84
85
  further details.
85
86
 
86
87
  [GitLab flavored Markdown]: https://docs.gitlab.com/ee/user/markdown.html
@@ -91,6 +92,7 @@ further details.
91
92
  [URL auto-linking]: https://docs.gitlab.com/ee/user/markdown.html#url-auto-linking
92
93
  [Multiline Blockquote]: https://docs.gitlab.com/ee/user/markdown.html#multiline-blockquote
93
94
  [Code and Syntax Highlighting]: https://docs.gitlab.com/ee/user/markdown.html#code-and-syntax-highlighting
95
+ [Strikethrough]: https://docs.gitlab.com/ee/user/markdown.html#emphasis
94
96
  [Inline Diff]: https://docs.gitlab.com/ee/user/markdown.html#inline-diff
95
97
  [Emoji]: https://docs.gitlab.com/ee/user/markdown.html#emoji
96
98
  [Special GitLab references]: https://docs.gitlab.com/ee/user/markdown.html#special-gitlab-references
@@ -5,10 +5,12 @@ module GitlabKramdown
5
5
  #
6
6
  # All GitLab extensions to Kramdown are implemented as a Parser in this module
7
7
  module Parser
8
+ autoload :Autolink, 'gitlab_kramdown/parser/autolink'
9
+ autoload :Escape, 'gitlab_kramdown/parser/escape'
8
10
  autoload :FencedBlockquote, 'gitlab_kramdown/parser/fenced_blockquote'
9
11
  autoload :FencedCodeblock, 'gitlab_kramdown/parser/fenced_codeblock'
10
12
  autoload :Header, 'gitlab_kramdown/parser/header'
11
13
  autoload :Reference, 'gitlab_kramdown/parser/reference'
12
- autoload :Autolink, 'gitlab_kramdown/parser/autolink'
14
+ autoload :Strikethrough, 'gitlab_kramdown/parser/strikethrough'
13
15
  end
14
16
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabKramdown
4
+ module Parser
5
+ # Escape chars support
6
+ #
7
+ # This is a standalone parser because making it so is an optimization
8
+ #
9
+ # Based on Kramdown GFM implementation
10
+ module Escape
11
+ ESCAPED_CHARS_GFM = /\\([\\.*_+`<>()\[\]{}#!:\|"'\$=\-~])/.freeze
12
+
13
+ def self.included(klass)
14
+ klass.define_parser(:escape_chars_gitlab, ESCAPED_CHARS_GFM, '\\\\', :parse_escaped_chars)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -11,6 +11,8 @@ module GitlabKramdown
11
11
  #
12
12
  # For maximum compatibility with GitLab, use `:rouge` as your highlighter.
13
13
  #
14
+ # Based on Kramdown GFM implementation
15
+ #
14
16
  # @see https://docs.gitlab.com/ee/user/markdown.html#code-and-syntax-highlighting
15
17
  module FencedCodeblock
16
18
  FENCED_CODEBLOCK_START = /^[ ]{0,3}[~`]{3,}/.freeze
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabKramdown
4
+ module Parser
5
+ # Strikethrough
6
+ #
7
+ # This parser implements strikethrough markup based on GFM
8
+ # used as-is in GitLab Flavored Markdown
9
+ #
10
+ # Based on Kramdown GFM implementation
11
+ #
12
+ # @see https://docs.gitlab.com/ee/user/markdown.html#emphasis
13
+ module Strikethrough
14
+ STRIKETHROUGH_DELIM = /~~/.freeze
15
+ STRIKETHROUGH_MATCH = %r{
16
+ (?<re>
17
+ #{STRIKETHROUGH_DELIM} # start with ~~
18
+ (?!\s|~) # not followed by ~ or space (negative lookahead)
19
+ (?:\g<re>|.*?)* # recursive <re> or lazy match anything
20
+ (?<!\s|~) # something different than space and ~ (negative lookbehind)
21
+ #{STRIKETHROUGH_DELIM} # end with ~~
22
+ )
23
+ }x.freeze
24
+
25
+ def self.included(klass)
26
+ klass.define_parser(:strikethrough_gitlab, STRIKETHROUGH_MATCH, '~~')
27
+ end
28
+
29
+ def parse_strikethrough_gitlab
30
+ line_number = @src.current_line_number
31
+
32
+ @src.pos += @src.matched_size
33
+ el = Kramdown::Element.new(:html_element, 'del', {}, category: :span, line: line_number)
34
+ @tree.children << el
35
+
36
+ env = save_env
37
+ reset_env(src: Kramdown::Utils::StringScanner.new(@src.matched[2..-3], line_number), text_type: :text)
38
+ parse_spans(el)
39
+ restore_env(env)
40
+
41
+ el
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitlabKramdown
4
- VERSION = '0.4.2'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -9,11 +9,13 @@ 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::Autolink
13
+ include ::GitlabKramdown::Parser::Escape
12
14
  include ::GitlabKramdown::Parser::FencedBlockquote
13
15
  include ::GitlabKramdown::Parser::FencedCodeblock
14
16
  include ::GitlabKramdown::Parser::Header
15
17
  include ::GitlabKramdown::Parser::Reference
16
- include ::GitlabKramdown::Parser::Autolink
18
+ include ::GitlabKramdown::Parser::Strikethrough
17
19
 
18
20
  def initialize(source, options)
19
21
  super
@@ -22,8 +24,8 @@ module Kramdown
22
24
  @options[:linkable_headers] = true if @options[:linkable_headers].nil?
23
25
  @id_counter = Hash.new(-1)
24
26
 
25
- prepend_span_parsers(:commit_diff, :commit, :user_group_mention,
26
- :issue, :merge_request, :snippet, :label, :gitlab_autolink)
27
+ prepend_span_parsers(:escape_chars_gitlab, :commit_diff, :commit, :user_group_mention,
28
+ :issue, :merge_request, :snippet, :label, :gitlab_autolink, :strikethrough_gitlab)
27
29
  prepend_block_parsers(:fenced_blockquote)
28
30
  replace_block_parser!(:codeblock_fenced, :codeblock_fenced_gitlab)
29
31
  replace_block_parser!(:atx_header, :atx_gitlab_header)
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.2
4
+ version: 0.5.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-21 00:00:00.000000000 Z
11
+ date: 2019-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -164,10 +164,12 @@ files:
164
164
  - lib/gitlab_kramdown.rb
165
165
  - lib/gitlab_kramdown/parser.rb
166
166
  - lib/gitlab_kramdown/parser/autolink.rb
167
+ - lib/gitlab_kramdown/parser/escape.rb
167
168
  - lib/gitlab_kramdown/parser/fenced_blockquote.rb
168
169
  - lib/gitlab_kramdown/parser/fenced_codeblock.rb
169
170
  - lib/gitlab_kramdown/parser/header.rb
170
171
  - lib/gitlab_kramdown/parser/reference.rb
172
+ - lib/gitlab_kramdown/parser/strikethrough.rb
171
173
  - lib/gitlab_kramdown/version.rb
172
174
  - lib/kramdown/parser/gitlab_kramdown.rb
173
175
  homepage: http://gitlab.com/gitlab-org/gitlab_kramdown
@@ -193,8 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
195
  - !ruby/object:Gem::Version
194
196
  version: '0'
195
197
  requirements: []
196
- rubyforge_project:
197
- rubygems_version: 2.7.7
198
+ rubygems_version: 3.0.3
198
199
  signing_key:
199
200
  specification_version: 4
200
201
  summary: GitLab Flavored Kramdown