Reputation: 135
Is it possible to add a post-processing step (in ruby) to run in Jekyll after it converts markup to HTML?
I'd like to add some html content, and can't see a way to do that in Jekyll files in general (though certain dialects of markup might support it), so I think it would have to be done by operating on the HTML after Jekyll converts it and before it writes it into _site/
.
EDIT: Clarified that I'm looking to do this in Ruby and in arbitrary dialects of markup.
Upvotes: 4
Views: 682
Reputation: 450
Newer versions of Jekyll let you use hooks to do post-processing (and many other things).
For example, you could put a file like this in the _plugins/
directory, and it will modify the contents of posts after they've been converted to HTML but before they've been embedded in a layout file or written to disk:
Jekyll::Hooks.register :posts, :post_convert do |post|
post.content = post.content.gsub('old', 'new')
end
Upvotes: 0
Reputation: 135
It looks like I may be able to do this by providing a Liquid filter that postprocess the html content, and changing {{ content }}
to {{ content | my_postprocess }}
in _layouts/post.html
and _layouts/page.html
.
Upvotes: 2
Reputation: 52829
Indeed, kramdown will not parse markdown in html element by default.
But, there is some configuration parameters that can be set to force kramdown to parse markdown in span or block elements.
Kramdown parameters in Jekyll documentation (look under the kramdown:
key) but more interesting things in the kramdown documentation particularly here and here
If you want to globally parse markdown in html, in _config.yml
, add :
kramdown:
parse_block_html: true
parse_span_html: true
{::options parse_block_html="true" /}
{::options parse_span_html="true" /}
<div>
## Some markdown here
**bold** and `code`
<cite>a **span** level element</cite>
</div>
You can also use markdown includes like this :
{% capture md %}{% include markdown_file.md %}{% endcapture %}
{{ md | markdownify }}
This will render any markdown as if it was in the original post/page.
Upvotes: 0