bridgetown_markdown_lazylinks 0.2.2 → 0.3.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: a944effb47e50a54e844dc41a7394af50a8f8140273794953eb01c2b3cc4a662
4
- data.tar.gz: 7fbaf75c16eae42ed8911ef74860e557aa20e8bba193796cd356ed8692ff2ada
3
+ metadata.gz: bfb7aabefee9a49f88a7c2969723a72700aa7faf9418384aefe0e9cdeda8f0ce
4
+ data.tar.gz: a365c1dfe8b03f391be738437d8a04ac9e3b3f6b6659db57b3a6b22ff83620fb
5
5
  SHA512:
6
- metadata.gz: d56b2bf3438a69233e4c1bc407c30c97adcf9cd8e814ea7867e72c0f444ccf3ebdcc179091fe975dda7ca7ba072e7af5b0334cf759bea7ca74296f6dbb0b9acb
7
- data.tar.gz: 4a908bf5d842001475673bf092fc6f4a8d21f45932cc0be9c0633a1733d25252f37ef6e63175c5e318f545e6233fb84deb90beb8d5eb05f7e35ab3adf3d5e70e
6
+ metadata.gz: 2fec30ccdadb994e07aa840fddcbb6c13079c1dcf4987f6058a1288f6e40117c4481be0976f70dfa3e21085f3cc0ac877c7ff581707564a0aeeb4a2164c2b6fc
7
+ data.tar.gz: 8cce949321493052945ff333827add6046e57eb4ccf59b03c09aaa8d0920b9a449ba62a3634ab16740042ae4cb1db73727049ee8318a36310206d2388e0bc712
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0] - 2023-06-26
11
+
12
+ - distinguish between basic & external placeholders
13
+
10
14
  ## [0.2.2] - 2023-06-26
11
15
 
12
16
  - allow placeholder customization
@@ -28,3 +32,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
28
32
  [0.2.0]: https://github.com/akarzim/bridgetown_markdown_lazylinks/releases/tag/v0.2.0
29
33
  [0.2.1]: https://github.com/akarzim/bridgetown_markdown_lazylinks/releases/tag/v0.2.1
30
34
  [0.2.2]: https://github.com/akarzim/bridgetown_markdown_lazylinks/releases/tag/v0.2.2
35
+ [0.3.0]: https://github.com/akarzim/bridgetown_markdown_lazylinks/releases/tag/v0.3.0
data/README.md CHANGED
@@ -28,7 +28,8 @@ You can customize the lazylinks placeholder in this way to use `+` instead of `*
28
28
 
29
29
  ```ruby
30
30
  init :bridgetown_markdown_lazylinks do
31
- placeholder "+"
31
+ basic_placeholder "-"
32
+ external_placeholder "@"
32
33
  end
33
34
  ```
34
35
 
@@ -52,6 +53,10 @@ and then just define them in order below it.
52
53
  [*]: http://blog.bignerdranch.com/4044-rock-heads/
53
54
  ```
54
55
 
56
+ Since version 0.3.0, we can use `+` as an external link reference, in the same
57
+ way as `*`, but this will add `target="_blank" rel="external"` to the resulting
58
+ links.
59
+
55
60
  ## Testing
56
61
 
57
62
  * Run `bundle exec rake test` to run the test suite
@@ -21,23 +21,36 @@ module BridgetownMarkdownLazylinks
21
21
  class Converter < Bridgetown::Converter
22
22
  priority :high
23
23
 
24
- DEFAULT_PLACEHOLDER = :*
24
+ DEFAULT_BASIC_PLACEHOLDER = :*
25
+ DEFAULT_EXTERNAL_PLACEHOLDER = :+
25
26
 
26
27
  def initialize(config = {})
27
28
  super
28
29
 
29
30
  self.class.input @config["markdown_ext"].split(",")
30
31
  @counter = 0
31
- @placeholder = config.bridgetown_markdown_lazylinks.placeholder || DEFAULT_PLACEHOLDER
32
+ @basic_placeholder = config.bridgetown_markdown_lazylinks.basic_placeholder
33
+ @basic_placeholder ||= DEFAULT_BASIC_PLACEHOLDER
34
+ @external_placeholder = config.bridgetown_markdown_lazylinks.external_placeholder
35
+ @external_placeholder ||= DEFAULT_EXTERNAL_PLACEHOLDER
32
36
  end
33
37
 
34
38
  def convert(content)
35
- lazy_links_regex = %r!(\[[^\]]+\]\s*\[)#{placeholder}(\].*?^\[)#{placeholder}\]:!m.freeze
39
+ # rubocop:disable Layout/LineLength
40
+ basic_regex = %r!(\[[^\]]+\]\s*\[)#{basic_placeholder}(\].*?^\[)#{basic_placeholder}\]:!m.freeze
41
+ external_regex = %r!(\[[^\]]+\]\s*\[)#{external_placeholder}\](.*?^\[)#{external_placeholder}\]:!m.freeze
42
+ # rubocop:enable Layout/LineLength
36
43
 
37
44
  cache.getset(content) do
38
- while content =~ lazy_links_regex
45
+ while content =~ basic_regex
39
46
  self.counter += 1
40
- content.sub!(lazy_links_regex, "\\1#{counter}\\2#{counter}]:")
47
+ content.sub!(basic_regex, "\\1#{counter}\\2#{counter}]:")
48
+ end
49
+
50
+ while content =~ external_regex
51
+ self.counter += 1
52
+ attrs = '{:target="_blank"}{:rel="external"}'
53
+ content.sub!(external_regex, %(\\1#{counter}]#{attrs}\\2#{counter}]:))
41
54
  end
42
55
 
43
56
  content
@@ -48,8 +61,12 @@ module BridgetownMarkdownLazylinks
48
61
 
49
62
  attr_accessor :counter
50
63
 
51
- def placeholder
52
- Regexp.quote(@placeholder)
64
+ def basic_placeholder
65
+ Regexp.quote(@basic_placeholder)
66
+ end
67
+
68
+ def external_placeholder
69
+ Regexp.quote(@external_placeholder)
53
70
  end
54
71
 
55
72
  def cache
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgetownMarkdownLazylinks
4
- VERSION = "0.2.2"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -8,7 +8,14 @@ require "bridgetown_markdown_lazylinks/converter"
8
8
  # @see https://github.com/bridgetownrb/bridgetown/issues/769#issuecomment-1596520674
9
9
  #
10
10
  # @param config [Bridgetown::Configuration::ConfigurationDSL]
11
- Bridgetown.initializer :bridgetown_markdown_lazylinks do |config, placeholder: :*|
11
+ # @param [Hash<String, String>] opts custom configuration
12
+ # @option opts [String] :placeholder ('*') the basic placeholder
13
+ # @option opts [String] :external_placeholder ('+') the external placeholder
14
+ #
15
+ # rubocop:disable Metrics/LineLength
16
+ Bridgetown.initializer :bridgetown_markdown_lazylinks do |config, placeholder: "*", external_placeholder: "+"|
12
17
  config.bridgetown_markdown_lazylinks ||= {}
13
- config.bridgetown_markdown_lazylinks.placeholder = placeholder
18
+ config.bridgetown_markdown_lazylinks.basic_placeholder = placeholder
19
+ config.bridgetown_markdown_lazylinks.external_placeholder = external_placeholder
14
20
  end
21
+ # rubocop:enable Metrics/LineLength
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown_markdown_lazylinks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - François Vantomme