add details plugin

This commit is contained in:
Rachel Lambda Samuelsson 2023-12-24 22:44:22 +01:00
parent ab3784c531
commit b06bc1bd1e
2 changed files with 24 additions and 1 deletions

View File

@ -42,7 +42,7 @@ EOF
svg = File.read("#{dir}/optimized_cd.svg")
return <<EOF
<figure class="cdfig">
<img class="cd" style="width: #{@scale}%;" src="data:image/svg+xml;base64#{Base64.encode64(svg)}" alt="A commutative diagram"/>
<img class="cd" style="width: #{@scale}%;" src="data:image/svg+xml;base64,#{Base64.encode64(svg)}" alt="A commutative diagram"/>
<figcaption>#{@caption}</figcaption>
</figure>
EOF

23
_plugins/details_tag.rb Normal file
View File

@ -0,0 +1,23 @@
# from http://movb.de/jekyll-details-support.html
module Jekyll
module Tags
class DetailsTag < Liquid::Block
def initialize(tag_name, markup, tokens)
super
@caption = markup
end
def render(context)
site = context.registers[:site]
converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
caption = converter.convert(@caption).gsub(/<\/?p[^>]*>/, '').chomp
body = converter.convert(super(context))
"<details><summary>#{caption}</summary>#{body}</details>"
end
end
end
end
Liquid::Template.register_tag('details', Jekyll::Tags::DetailsTag)