Skip to content

Commit 0169d38

Browse files
committed
Omit alt tag if image description is empty.
This is better than `alt=""`, which signals to browsers that the image is not part of the main content. See commonmark/commonmark-spec#718.
1 parent c0459dd commit 0169d38

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/html.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,22 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
300300
houdini_escape_href(html, node->as.link.url,
301301
strlen((char *)node->as.link.url));
302302
}
303-
cmark_strbuf_puts(html, "\" alt=\"");
303+
cmark_strbuf_puts(html, "\"");
304+
if (node->first_child) {
305+
cmark_strbuf_puts(html, " alt=\"");
306+
}
304307
state->plain = node;
305308
} else {
309+
if (node->first_child) {
310+
cmark_strbuf_puts(html, "\"");
311+
}
306312
if (node->as.link.title) {
307-
cmark_strbuf_puts(html, "\" title=\"");
313+
cmark_strbuf_puts(html, " title=\"");
308314
escape_html(html, node->as.link.title,
309315
strlen((char *)node->as.link.title));
316+
cmark_strbuf_puts(html, "\"");
310317
}
311-
312-
cmark_strbuf_puts(html, "\" />");
318+
cmark_strbuf_puts(html, " />");
313319
}
314320
break;
315321

0 commit comments

Comments
 (0)