Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save harper357/0be1ab0bc0b631c51f0510d36cf7ff8a to your computer and use it in GitHub Desktop.
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
# 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