From 7c66b227a494748e2a546fb85317accd00aebe53 Mon Sep 17 00:00:00 2001 From: Justin Gassner Date: Thu, 15 Feb 2024 05:11:07 +0100 Subject: Update --- _plugins/enunciation.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to '_plugins/enunciation.rb') diff --git a/_plugins/enunciation.rb b/_plugins/enunciation.rb index 3301e0d..b141ae9 100644 --- a/_plugins/enunciation.rb +++ b/_plugins/enunciation.rb @@ -1,39 +1,37 @@ module Jekyll class EnunciationTagBlock < Liquid::Block - def initialize(tag_name, arg, parse_context) super @arg = arg.strip - @slugtemplate = Liquid::Template.parse("{{ string | slugify }}") + @slugtemplate = Liquid::Template.parse('{{ string | slugify }}') end def render(context) text = super # If the enunciation ends with a KaTeX displayed equation, # then we remove the bottom margin. - if text[-5,5] == " $$\n" + if text[-5, 5] == " $$\n" text += ' {: .katex-display .mb-0 }' - elsif text[-3,3] == "$$\n" + elsif text[-3, 3] == "$$\n" text += '{: .katex-display .mb-0 }' end # Check if a description was given. - if @arg.length < 1 - "{: .#{block_name} }\n #{text.gsub!(/^/,'> ')}" + if @arg.empty? + "{: .#{block_name} }\n #{text.gsub!(/^/, '> ')}" else - if @arg[0] == "*" - title = @arg.delete_prefix("* ") + if @arg[0] == '*' + title = @arg.delete_prefix('* ') else title = "#{block_name.capitalize} (#{@arg})" end - slug = @slugtemplate.render( 'string' => title ) - "{: .#{block_name}-title }\n> #{title}\n> {: \##{slug} }\n>\n#{text.gsub!(/^/,'> ')}" + slug = @slugtemplate.render('string' => title) + "{: .#{block_name}-title }\n> #{title}\n> {: \##{slug} }\n>\n#{text.gsub!(/^/, '> ')}" end end - end end # TODO: avoid reading configuration twice -Jekyll.configuration({})['callouts'].each do |name, value| +Jekyll.configuration({})['callouts'].each do |name, _| Liquid::Template.register_tag(name, Jekyll::EnunciationTagBlock) end -- cgit v1.2.3-54-g00ecf