2

Kramdown is now the default markdown renderer for Jekyll 4.0. I would like to know if there is a way to remove the end slash from the img tag.

For example:

![Flowers](flowers.jpg)

<img src="flowers.jpg" alt="Flowers" />

One way until a few months ago was to using Redcarpet, but now is dropped.

How can I do?

Thanks for the support.

2 Answers2

2

As said in my comment, this trailing slash is hard coded in Kramdown Html converter.

You can override this methods by creating a _plugins/my_img_tag.rb file :

module Kramdown

  module Converter

    class Html < Base

      # Overriding method
      def convert_img(el, _indent)
        "<img#{html_attributes(el.attr)}>"
      end

    end

  end

end

Note : this plugin will not work on Github pages.

David Jacquel
  • 51,670
  • 6
  • 121
  • 147
0

You can use regular expressions for this:

The regex below catches what we want:

(<img)(.*\n*\t*\s*)(\/>)

Then, you can do a replace of the 3rd group:

$1$2>

I've tested with a few variations of the tag img:

Test using Sublime Text

  • Oi Alexandre, obrigado. Mas eu utilizo markdown com **Jekyll**, portanto a sua sugestão não me ajuda. Como respondeu o David acima, preciso sovrescrever o Kramdown. O problema é como faze-lo. – user2008070 Apr 16 '20 at 19:47