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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +6 -1
- data/lib/bridgetown_markdown_lazylinks/converter.rb +24 -7
- data/lib/bridgetown_markdown_lazylinks/version.rb +1 -1
- data/lib/bridgetown_markdown_lazylinks.rb +9 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfb7aabefee9a49f88a7c2969723a72700aa7faf9418384aefe0e9cdeda8f0ce
|
4
|
+
data.tar.gz: a365c1dfe8b03f391be738437d8a04ac9e3b3f6b6659db57b3a6b22ff83620fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
@
|
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
|
-
|
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 =~
|
45
|
+
while content =~ basic_regex
|
39
46
|
self.counter += 1
|
40
|
-
content.sub!(
|
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
|
52
|
-
Regexp.quote(@
|
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
|
@@ -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
|
-
|
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.
|
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
|