bridgetown_markdown_lazylinks 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +16 -0
- data/lib/bridgetown_markdown_lazylinks/converter.rb +27 -3
- data/lib/bridgetown_markdown_lazylinks/version.rb +1 -1
- data/lib/bridgetown_markdown_lazylinks.rb +10 -2
- metadata +2 -2
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,14 @@ 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
|
+
|
|
14
|
+
## [0.2.2] - 2023-06-26
|
|
15
|
+
|
|
16
|
+
- allow placeholder customization
|
|
17
|
+
|
|
10
18
|
## [0.2.1] - 2023-06-19
|
|
11
19
|
|
|
12
20
|
- add a plugin initializer
|
|
@@ -23,3 +31,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
23
31
|
[0.1.0]: https://github.com/akarzim/bridgetown_markdown_lazylinks/releases/tag/v0.1.0
|
|
24
32
|
[0.2.0]: https://github.com/akarzim/bridgetown_markdown_lazylinks/releases/tag/v0.2.0
|
|
25
33
|
[0.2.1]: https://github.com/akarzim/bridgetown_markdown_lazylinks/releases/tag/v0.2.1
|
|
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
|
@@ -22,6 +22,18 @@ Or if there's a `bridgetown.automation.rb` automation script, you can run that i
|
|
|
22
22
|
bin/bridgetown apply https://github.com/akarzim/bridgetown_markdown_lazylinks
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
### Customization
|
|
26
|
+
|
|
27
|
+
You can customize the lazylinks placeholder in this way to use `+` instead of `*`:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
init :bridgetown_markdown_lazylinks do
|
|
31
|
+
basic_placeholder "-"
|
|
32
|
+
external_placeholder "@"
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
25
37
|
## Usage
|
|
26
38
|
|
|
27
39
|
The plugin will allow you to use `*` as link references in your markdown
|
|
@@ -41,6 +53,10 @@ and then just define them in order below it.
|
|
|
41
53
|
[*]: http://blog.bignerdranch.com/4044-rock-heads/
|
|
42
54
|
```
|
|
43
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
|
+
|
|
44
60
|
## Testing
|
|
45
61
|
|
|
46
62
|
* Run `bundle exec rake test` to run the test suite
|
|
@@ -21,20 +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
|
|
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
|
|
31
36
|
end
|
|
32
37
|
|
|
33
38
|
def convert(content)
|
|
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
|
|
43
|
+
|
|
34
44
|
cache.getset(content) do
|
|
35
|
-
while content =~
|
|
45
|
+
while content =~ basic_regex
|
|
46
|
+
self.counter += 1
|
|
47
|
+
content.sub!(basic_regex, "\\1#{counter}\\2#{counter}]:")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
while content =~ external_regex
|
|
36
51
|
self.counter += 1
|
|
37
|
-
|
|
52
|
+
attrs = '{:target="_blank"}{:rel="external"}'
|
|
53
|
+
content.sub!(external_regex, %(\\1#{counter}]#{attrs}\\2#{counter}]:))
|
|
38
54
|
end
|
|
39
55
|
|
|
40
56
|
content
|
|
@@ -45,6 +61,14 @@ module BridgetownMarkdownLazylinks
|
|
|
45
61
|
|
|
46
62
|
attr_accessor :counter
|
|
47
63
|
|
|
64
|
+
def basic_placeholder
|
|
65
|
+
Regexp.quote(@basic_placeholder)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def external_placeholder
|
|
69
|
+
Regexp.quote(@external_placeholder)
|
|
70
|
+
end
|
|
71
|
+
|
|
48
72
|
def cache
|
|
49
73
|
@cache ||= Bridgetown::Cache.new("BridgetownMarkdownLazylinks")
|
|
50
74
|
end
|
|
@@ -8,6 +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
|
-
|
|
12
|
-
|
|
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: "+"|
|
|
17
|
+
config.bridgetown_markdown_lazylinks ||= {}
|
|
18
|
+
config.bridgetown_markdown_lazylinks.basic_placeholder = placeholder
|
|
19
|
+
config.bridgetown_markdown_lazylinks.external_placeholder = external_placeholder
|
|
13
20
|
end
|
|
21
|
+
# rubocop:enable Metrics/LineLength
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bridgetown_markdown_lazylinks
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- François Vantomme
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-06-
|
|
11
|
+
date: 2023-06-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bridgetown
|