discourse/lib/markdown_linker.rb

28 lines
535 B
Ruby
Raw Normal View History

2013-02-05 13:16:51 -06: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)
2013-02-25 10:42:20 -06:00
@markdown_links[@index] = "#{@base_url}#{url}"
2013-02-05 13:16:51 -06:00
result = "[#{title}][#{@index}]"
2013-02-25 10:42:20 -06:00
@index += 1
2013-02-05 13:16:51 -06:00
result
end
def references
result = ""
(@rendered..@index-1).each do |i|
result << " [#{i}]: #{@markdown_links[i]}\n"
end
@rendered = @index
result
end
2013-02-25 10:42:20 -06:00
2013-02-05 13:16:51 -06:00
end