class Kramdown::Converter::Html def add_block_count(attr) @block_count ||= 0 @block_count += 1 unless attr["id"] attr["id"] = "b:#{@block_count}" end end %i(format_as_block_html format_as_indented_block_html).each do |method| alias_method :"original_#{method}", method define_method(method) do |*args| add_block_count(args[1]) send(:"original_#{method}", *args) end end end