Skip to content

Commit

Permalink
Omit alt tag if image description is empty.
Browse files Browse the repository at this point in the history
This is better than `alt=""`, which signals to browsers that
the image is not part of the main content.
See commonmark/commonmark-spec#718.
  • Loading branch information
jgm committed Aug 13, 2022
1 parent c0459dd commit 0169d38
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,22 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
houdini_escape_href(html, node->as.link.url,
strlen((char *)node->as.link.url));
}
cmark_strbuf_puts(html, "\" alt=\"");
cmark_strbuf_puts(html, "\"");
if (node->first_child) {
cmark_strbuf_puts(html, " alt=\"");
}
state->plain = node;
} else {
if (node->first_child) {
cmark_strbuf_puts(html, "\"");
}
if (node->as.link.title) {
cmark_strbuf_puts(html, "\" title=\"");
cmark_strbuf_puts(html, " title=\"");
escape_html(html, node->as.link.title,
strlen((char *)node->as.link.title));
cmark_strbuf_puts(html, "\"");
}

cmark_strbuf_puts(html, "\" />");
cmark_strbuf_puts(html, " />");
}
break;

Expand Down

0 comments on commit 0169d38

Please sign in to comment.