Skip to content

Instantly share code, notes, and snippets.

@btskinner
Forked from mignev/markdown-tag.rb
Last active March 30, 2020 14:09
Show Gist options
  • Save btskinner/4dbe92f204bee43e82c2 to your computer and use it in GitHub Desktop.
Save btskinner/4dbe92f204bee43e82c2 to your computer and use it in GitHub Desktop.
Ruby module to include online markdown files in Jekyll site
=begin
Tag to include markdown text from linked file (e.g. Github README.md)
Usage:
{% linkmarkdown <filename> %}
=end
require 'open-uri'
module Jekyll
class MarkdownTag < Liquid::Tag
def initialize(tag_name, url, tokens)
super
@url = url.strip
end
def render(context)
contents = URI.open(@url, &:read)
site = context.registers[:site]
converter = Jekyll::Converters::Markdown::KramdownParser.new(site.config)
contents = (Liquid::Template.parse contents).render site.site_payload
html = converter.convert(contents)
end
end
end
Liquid::Template.register_tag('linkmarkdown', Jekyll::MarkdownTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment