Skip to content

Instantly share code, notes, and snippets.

@harper357
Created February 5, 2020 15:44
Show Gist options
  • Save harper357/c25b00fa95273c1267c2012de6ca1785 to your computer and use it in GitHub Desktop.
Save harper357/c25b00fa95273c1267c2012de6ca1785 to your computer and use it in GitHub Desktop.
Jekyll plugin to replace Markdown code blocks (for mermaid syntax)
# modified from https://gist.github.com/mmistakes/77c68fbb07731a456805a7b473f47841
# Description: Jekyll plugin to replace Markdown code blocks (for mermaid syntax) with <div class="mermaid"> tag for crafting mermaid charts with minimal headache
# 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(/```mermaid([^`]+?)```/, '<div class="mermaid">\1</div>')
post.content = newContent
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment