Last active
October 14, 2022 17:03
-
-
Save YJPL/48718e28d2b2fda3476aceac018c8f26 to your computer and use it in GitHub Desktop.
Jekyll plugin to replace Markdown images e.g. `` with `{% picture %}`. This tag works for collections in addition to posts. Written to work combined with Jekyll Picture Tag. The link opens the original image.
This file contains hidden or 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 HTML markup, written to work combined with Jekyll Picture Tag | |
Jekyll::Hooks.register :documents, :pre_render do |document, payload| | |
docExt = document.extname.tr('.', '') | |
# only process if we deal with a markdown file | |
if payload['site']['markdown_ext'].include? docExt | |
newContent = document.content.gsub(/!\[(.*)\]\(([^\)]+)\)(?:{:([^}]+)})*/, '{% picture default \2 --alt \1 --link /img/\2 %}') | |
document.content = newContent | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Improved thanks to https://gist.github.com/tadamcz/869802c919c72172486f219751904108