2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
# Helps create links using markdown (where references are at the bottom)
|
|
|
|
class MarkdownLinker
|
|
|
|
|
|
|
|
def initialize(base_url)
|
|
|
|
@base_url = base_url
|
|
|
|
@index = 1
|
|
|
|
@markdown_links = {}
|
|
|
|
@rendered = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(title, url)
|
2018-08-07 16:38:05 -04:00
|
|
|
@markdown_links[@index] = url.start_with?(@base_url) ? url : "#{@base_url}#{url}"
|
2013-02-05 14:16:51 -05:00
|
|
|
result = "[#{title}][#{@index}]"
|
2013-02-25 11:42:20 -05:00
|
|
|
@index += 1
|
2013-02-05 14:16:51 -05:00
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def references
|
2019-05-02 18:17:27 -04:00
|
|
|
result = +""
|
2017-07-27 21:20:09 -04:00
|
|
|
(@rendered..@index - 1).each do |i|
|
2013-08-21 13:12:41 -04:00
|
|
|
result << "[#{i}]: #{@markdown_links[i]}\n"
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
@rendered = @index
|
|
|
|
result
|
|
|
|
end
|
2013-02-25 11:42:20 -05:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|