From b4a660413e9a690467aeb697b996dff5aa423c32 Mon Sep 17 00:00:00 2001 From: Joshua Katz Date: Tue, 31 Oct 2023 19:53:32 +0000 Subject: [PATCH] Don't flatten links around images into autolinks Sometimes users of markdown will want to add a clickable image into their content. This is done using the following syntax: ``` [![alt text](http://.../img.png)](http://.../website) ``` This used to get turned into the following: ``` ``` This commit prevents that from happening for links. --- src/commonmark.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/commonmark.c b/src/commonmark.c index 987b47318..abe53675f 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -141,6 +141,12 @@ static bool is_autolink(cmark_node *node) { if (link_text == NULL) { return false; } + // Don't flatten links around images into autolinks. Ex: + // [ ![image](http://.../image.png) ](http://.../) + uint16_t text_type = link_text->type; + if (text_type == CMARK_NODE_IMAGE) { + return false; + } cmark_consolidate_text_nodes(link_text); realurl = (char *)url->data; realurllen = url->len;