From ccc93a0562d36788cef3df0d9796d670486ca722 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 29 Aug 2024 13:22:57 +0200 Subject: [PATCH] minor fix: in fenced divs and fenced code blocks, omit empty class attribute --- markdown.awk | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/markdown.awk b/markdown.awk index d54d125..7e20ebb 100755 --- a/markdown.awk +++ b/markdown.awk @@ -557,10 +557,14 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code, attrib = gensub(/^:::+[ \t]*\{?[ \t]*([^\}\n]*)\}?[ \t]*\n.*$/, "\\1", 1, block); gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib); - if ( match(code, "(^|\n)" guard "+(\n|$)" ) ) { + if ( match(code, "(^|\n)" guard "+(\n|$)" ) && attrib ) { len = RLENGTH; st = RSTART; return "
" _nblock( substr(code, 1, st - 1) ) "
\n" \ _block( substr( code, st + len ) ); + } else if ( match(code, "(^|\n)" guard "+(\n|$)" ) ) { + len = RLENGTH; st = RSTART; + return "
" _nblock( substr(code, 1, st - 1) ) "
\n" \ + _block( substr( code, st + len ) ); } else { match( block, /(^|\n)[[:space:]]*(\n|$)/ ) || match( block, /$/ ); len = RLENGTH; st = RSTART; @@ -575,10 +579,14 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code, attrib = gensub(/^(~~~+|```+)[ \t]*\{?[ \t]*([^\}\n]*)\}?[ \t]*\n.*$/, "\\2", 1, block); gsub(/[^a-zA-Z0-9_-]+/, " ", attrib); gsub(/(^ | $)/, "", attrib); - if ( match(code, "(^|\n)" guard "+(\n|$)" ) ) { + if ( match(code, "(^|\n)" guard "+(\n|$)" ) && attrib ) { len = RLENGTH; st = RSTART; return "
" HTML( substr(code, 1, st - 1) ) "
\n" \ _block( substr( code, st + len ) ); + } else if ( match(code, "(^|\n)" guard "+(\n|$)" ) ) { + len = RLENGTH; st = RSTART; + return "
" HTML( substr(code, 1, st - 1) ) "
\n" \ + _block( substr( code, st + len ) ); } else { match( block, /(^|\n)[[:space:]]*(\n|$)/ ) || match( block, /$/ ); len = RLENGTH; st = RSTART; -- 2.39.2