gitlab_kramdown 0.8.0 → 0.9.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: f3acfbac18fc6cf8508130278d8c3fb763d34faf3653c9e9d74d89a5ec407de7
4
- data.tar.gz: af3d23c6d0e713db32a24d2fed92287136becee538ac92ff691c32cf0d484d22
3
+ metadata.gz: 31afbf2c3237ca13dbfb45e2611bdcdd6027462367ce044b503d5d0cd7f3c9db
4
+ data.tar.gz: c7aa8f8972f357ae9a7e35800949a43db74fe5b99cfc091c0d8e2f25d9e11448
5
5
  SHA512:
6
- metadata.gz: a604e72d430c7e61a62aad73a0ed6aac16ace06d1abe6e49134d671a15cff72e5b470a7fecaea4d4b01e354ab1570410731dd244ba3ac14f5ae383aa74730b83
7
- data.tar.gz: f451eb7e8da889ac1fcbb5c9ff47cb6a253a522392e7f920ceca1b3d8ba2c618d171d0ef51c27c0ccca79925be5559738fd2773c8df9c7b52f5d638fb19bfed9
6
+ metadata.gz: e1c695552bdcbed7e035ea012834c8d650a77339b9fb188b7fb560c73cdb0d5bfe86ad9130cfa41a7ea4e1eedd82185f5b5ec75776572a430ccd6f362f5978e7
7
+ data.tar.gz: 44f541a9c9402e4888e85af1cb9c870ce4ba09ea6da5b5ed82d05d64ebedfa521737ec9dfa116addc92de3c006e5671cef0e321897d96fc7d2d288c7b39d9f57
data/README.md CHANGED
@@ -38,6 +38,7 @@ This is a list of GitLab Flavored Markdown (GFM) extensions and their status of
38
38
  | `gitlab_url` | `https://gitlab.com` | GitLab instance URL to build reference links |
39
39
  | `linkable_headers` | true | Generate anchor tags with headers? |
40
40
  | `autolink` | false | Converts URLs to HTML links (can be slow) |
41
+ | `clickable_images` | true | Autolink images to themselves |
41
42
 
42
43
  ## Usage example
43
44
 
@@ -10,6 +10,20 @@ module GitlabKramdown
10
10
  #
11
11
  # This includes GitLab custom elements from GitLab Flavored Markdown syntax
12
12
  module GitlabHtml
13
+ # Initializes a GitLab custom HTML converter with a given document
14
+ #
15
+ # It accepts all existing options for HTML converter with our custom ones:
16
+ #
17
+ # * +clickable_images+ (default: true) - whether images will have a link to itself
18
+ #
19
+ # @param [Kramdown::Document] root
20
+ # @param [Hash] options
21
+ def initialize(root, options)
22
+ super(root, options)
23
+
24
+ @clickable_images = options[:clickable_images] != false
25
+ end
26
+
13
27
  # Codeblock is customized in order to implement a different output to Mermaid
14
28
  #
15
29
  # Mermaid requires `<div class="mermaid"></div>` surrounding the content in order
@@ -38,6 +52,21 @@ module GitlabKramdown
38
52
  conf.txt_enable = false
39
53
  end
40
54
  end
55
+
56
+ # Images can have a link to themselves when configuration allows
57
+ #
58
+ # We don't autolink when image is already linked to something-else
59
+ #
60
+ # @param [Kramdown::Element] element
61
+ # @param [Integer] _indent
62
+ def convert_img(element, _indent)
63
+ return super unless @clickable_images
64
+ return super if @stack.last.type == :a
65
+
66
+ href = element.attr['src']
67
+
68
+ %(<a href="#{href}" target="_blank" rel="noopener noreferrer">#{super}</a>)
69
+ end
41
70
  end
42
71
  end
43
72
  end
@@ -73,9 +73,11 @@ module GitlabKramdown
73
73
  end
74
74
 
75
75
  NON_WORD_RE = /[^\p{Word}\- \t]/.freeze
76
+ MARKDOWN_LINK_TEXT = /\[(?<link_text>[^\]]+)\]\((?<link_url>[^\)]+)\)/.freeze
76
77
 
77
78
  def generate_header_id(text)
78
79
  result = text.downcase
80
+ result.gsub!(MARKDOWN_LINK_TEXT) { |s| MARKDOWN_LINK_TEXT.match(s)[:link_text].gsub(NON_WORD_RE, '') }
79
81
  result.gsub!(NON_WORD_RE, '')
80
82
  result.tr!(" \t", '-')
81
83
  @id_counter[result] += 1
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.8.0
4
+ version: 0.9.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: 2019-10-14 00:00:00.000000000 Z
11
+ date: 2019-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -224,8 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  - !ruby/object:Gem::Version
225
225
  version: '0'
226
226
  requirements: []
227
- rubyforge_project:
228
- rubygems_version: 2.7.6.2
227
+ rubygems_version: 3.0.6
229
228
  signing_key:
230
229
  specification_version: 4
231
230
  summary: GitLab Flavored Kramdown