Forked from mmistakes/markdown-img-picture-replacement.rb
Created
November 28, 2018 14:30
-
-
Save harper357/0be1ab0bc0b631c51f0510d36cf7ff8a to your computer and use it in GitHub Desktop.
Jekyll plugin to replace Markdown images eg. `![description](image.jpg)` with `{% picture %}` 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
# Description: Jekyll plugin to replace Markdown image syntax with {% picture %} tag for crafting responsive images | |
# place in /_plugins/ | |
Jekyll::Hooks.register :posts, :pre_render do |post, payload| | |
docExt = post.extname.tr('.', '') | |
# only process if we deal with a markdown file | |
if payload['site']['markdown_ext'].include? docExt | |
newContent = post.content.gsub(/\!\[(.+)\]\((.+)\)/, '{% picture default \2 alt="\1" %}') | |
post.content = newContent | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment