Created
November 30, 2011 08:10
-
-
Save tmtk75/1408402 to your computer and use it in GitHub Desktop.
Jekyll Markdown Tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Jekyll tag to include Markdown text from _includes directory preprocessing with Liquid. | |
Usage: | |
{% markdown <filename> %} | |
Dependency: | |
- kramdown | |
=end | |
module Jekyll | |
class MarkdownTag < Liquid::Tag | |
def initialize(tag_name, text, tokens) | |
super | |
@text = text.strip | |
end | |
require "kramdown" | |
def render(context) | |
tmpl = File.read File.join Dir.pwd, "_includes", @text | |
site = context.registers[:site] | |
tmpl = (Liquid::Template.parse tmpl).render site.site_payload | |
html = Kramdown::Document.new(tmpl).to_html | |
end | |
end | |
end | |
Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag) | |
Hi,
This is my current code:
{% if member.brief %}
{% include /briefs/{{ member.brief }} %}
{% endif %}
I need to change this so it uses the markdown command instead of include, but
{% if member.brief %}
{% markdown /briefs/{{ member.brief }} %}
{% endif %}
Gives me a "file not found" error. How can I make it work?
Best,
Kristian
Even after inserting this code in _plugins
directory, I am getting page build error:
The tag
markdown
in_posts/2015-08-26-compiling-html-templates-to-html-pages.md
is not a recognized Liquid tag.
I am using kramdown
markdown.
Please help.
@kamlekar I've just had the same problem. I forgot to restart my site with jekyll serve
.
How would variables be passed into the included markdown ?
{% markdown query_parameters.md param="value" %}
Liquid Exception: No such file or directory - _includes/query_parameters.md param="value" in _posts/2016-01-22-user.markdown
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've mentioned this on @mignev's fork, but it also applies to this version:
Something weird seems to happen to the markdown with this plugin. For example, when using fenced code blocks, the newlines seem to disappear. I've also added support for MathJax to my installation, and the backslashes get removed. Explicit inclusion along the lines of
Doesn't have these problems. Any ideas how to work around these while still using the plugin?