Class: BridgetownMarkdownLazylinks::Converter
- Inherits:
-
Bridgetown::Converter
- Object
- Bridgetown::Converter
- BridgetownMarkdownLazylinks::Converter
- Defined in:
- lib/bridgetown_markdown_lazylinks/converter.rb
Overview
Allows use of ‘*` link references where the next [*]: href defines the link Inspired by [tidbits] [*]: tidbits.com
Example: mkd = <<-MKD This is my text and [this is my link]. I’ll define the url for that link under the paragraph.
[*]: brettterpstra.com
I can use [multiple] lazy links in [a paragraph], and then just define them in order below it.
[*]: gist.github.com/ttscoff/7059952 [*]: blog.bignerdranch.com/4044-rock-heads/ MKD
Constant Summary collapse
- LAZY_LINKS_REGEX =
%r!(?<link>\[[^\]]+\]\s*\[)\*(?<url>\].*?^\[)\*\]:!m.freeze
Instance Method Summary collapse
- #convert(content) ⇒ Object
-
#initialize(config = {}) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(config = {}) ⇒ Converter
Returns a new instance of Converter.
26 27 28 29 30 31 |
# File 'lib/bridgetown_markdown_lazylinks/converter.rb', line 26 def initialize(config = {}) super self.class.input @config["markdown_ext"].split(",") @counter = 0 end |
Instance Method Details
#convert(content) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bridgetown_markdown_lazylinks/converter.rb', line 33 def convert(content) cache.getset(content) do while content =~ LAZY_LINKS_REGEX self.counter += 1 content.sub!(LAZY_LINKS_REGEX, "\\k<link>#{counter}\\k<url>#{counter}]:") end content end end |