]> git.plutz.net Git - shellwiki/commitdiff
Squashed 'cgilite/' changes from 41642aa..1e12e80
authorPaul Hänsch <paul@plutz.net>
Mon, 9 Oct 2023 12:01:14 +0000 (14:01 +0200)
committerPaul Hänsch <paul@plutz.net>
Mon, 9 Oct 2023 12:01:14 +0000 (14:01 +0200)
1e12e80 force ALT-text for images

git-subtree-dir: cgilite
git-subtree-split: 1e12e80fbfed62596f992d0939418059174c4928

markdown.awk

index 75f182746bd29d9375c7af1b1e52c39737fb2a58..249f5074b213b68511f94009b5d708db99b0b51a 100755 (executable)
@@ -231,9 +231,10 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
     else if ( match(title, /^'.*'$/) ) { sub(/^'/, "", title); sub(/'$/, "", title); }
     else if ( match(title, /^\(.*\)$/) ) { sub(/^\(/, "", title); sub(/\)$/, "", title); }
 
-    gsub(/\\/, "", href); gsub(/\\/, "", title); gsub(/[\n\t]+/, " ", title);
+    gsub(/^[\t ]+$/, "", text); gsub(/\\/, "", href);
+    gsub(/\\/, "", title); gsub(/[\n\t]+/, " ", title);
 
-    return "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text) "\"" \
+    return "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text?text:title?title:href) "\"" \
            (title?" title=\"" HTML(title) "\"":"") (attrib?" class=\"" HTML(attrib) "\"":"") \
            ">" inline( substr( line, len + 1) );
 
@@ -660,10 +661,10 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code,
     else if ( match(title, /^'.*'$/) ) { sub(/^'/, "", title); sub(/'$/, "", title); }
     else if ( match(title, /^\(.*\)$/) ) { sub(/^\(/, "", title); sub(/\)$/, "", title); }
 
-    gsub(/\\/, "", href);
+    gsub(/^[\t ]+$/, "", text); gsub(/\\/, "", href);
 
     return "<figure data-src=\"" URL(href, 1) "\"" (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
-           "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text) "\"" \
+           "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text?text:title?title:href) "\"" \
            (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
            (title?"<figcaption>" inline(title) "</figcaption>":"") \
            "</figure>\n\n" \