Force HTML5 <br> instead of <br />

14 views
Skip to first unread message

Dave Everitt

unread,
Oct 29, 2023, 12:10:01 PM10/29/23
to kramdown-users
I use kramdown with nanoc to generate websites from Markdown files. Line breaks (two spaces after a line mid-paragraph) are being rendered as <br /> but I'm using HTML5, which causes a notification in the validator:

"Trailing slash on void elements has no effect and interacts badly with unquoted attribute values."

HTML5 tends to avoid trailing slashes on self-closing elements, so it would be nice to have a "switch" that removes them, at least for <br> tags - is this already possible?

I’ve put a question on StackOverflow so will update that if this gets answered here.

Thomas Leitner

unread,
Oct 30, 2023, 2:44:50 AM10/30/23
to kramdow...@googlegroups.com
On 2023-10-29 09:10 -0700 'Dave Everitt' via kramdown-users wrote:
> I use kramdown with nanoc to generate websites from Markdown files.
> Line breaks (two spaces after a line mid-paragraph) are being
> rendered as <br /> but I'm using HTML5, which causes a notification
> in the validator:

The output of kramdown is built so that it is compatible with HTML and
XHTML. If you need to change the output to be just HTML compatible,
please customize the HTML converter.

All the best,
Thomas

Dave Everitt

unread,
Oct 30, 2023, 6:25:16 PM10/30/23
to kramdown-users
I found the location of the line I need to change on line 267 in "/usr/local/lib/ruby/gems/3.2.0/gems/kramdown-2.4.0/lib/kramdown/converter/html.rb" and sudo edited <br /> to <br> with the Pico editor. It works, but I presume any update to the kramdown gem will overwrite it - any idea how to make this permanent for my local kramdown gem?

Dave Everitt

unread,
Oct 31, 2023, 6:01:22 AM10/31/23
to kramdown-users
update - used Micro on OS X (brew install micro) to go through the html.rb file and change all " />" to ">" for all self-closing tags. My version is now happily generating HTML5 that the syntax checker likes. I know XHTML is still out there but for most web dev jobs, HTML5 is now pretty universal.
Reply all
Reply to author
Forward
0 new messages