docs-seed/_plugins/markdown_anchor_block.rb

28 строки
656 B
Ruby

module Jekyll
class MarkdownAnchorBlock < Liquid::Block
def initialize(tag_name, markup, tokens)
super
end
def render(context)
contents = super
content = Liquid::Template.parse(contents).render context
anchorText = content[/\[.*\]/]
if !anchorText.nil?
anchorText = anchorText.sub("\[", "")
anchorText = anchorText.sub("\]", "")
end
anchor = content[/\(.*\)/]
if !anchorText.nil?
anchor = anchor.sub("\(", "")
anchor = anchor.sub("\)", "")
end
output = "<a href=\"#{anchor}\">#{anchorText}</a>"
end
end
end
Liquid::Template.register_tag('mdslug', Jekyll::MarkdownAnchorBlock)