diff --git a/src/document.c b/src/document.c index 769c8bc..a9cb42c 100644 --- a/src/document.c +++ b/src/document.c @@ -77,6 +77,7 @@ static size_t char_autolink_url(hoedown_buffer *ob, hoedown_document *doc, uint8 static size_t char_autolink_email(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size); static size_t char_autolink_www(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size); static size_t char_link(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size); +static size_t char_image(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size); static size_t char_superscript(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size); static size_t char_math(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size); @@ -86,6 +87,7 @@ enum markdown_char_t { MD_CHAR_CODESPAN, MD_CHAR_LINEBREAK, MD_CHAR_LINK, + MD_CHAR_IMAGE, MD_CHAR_LANGLE, MD_CHAR_ESCAPE, MD_CHAR_ENTITY, @@ -103,6 +105,7 @@ static char_trigger markdown_char_ptrs[] = { &char_codespan, &char_linebreak, &char_link, + &char_image, &char_langle_tag, &char_escape, &char_entity, @@ -1095,6 +1098,17 @@ char_autolink_url(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size return link_len; } +static size_t +char_image(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size) { + size_t ret; + + if (size < 2 || data[1] != '[') return 0; + + ret = char_link(ob, doc, data + 1, offset + 1, size - 1); + if (!ret) return 0; + return ret + 1; +} + /* char_link • '[': parsing a link, a footnote or an image */ static size_t char_link(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size) @@ -1307,9 +1321,6 @@ char_link(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offse /* calling the relevant rendering function */ if (is_img) { - if (ob->size && ob->data[ob->size - 1] == '!') - ob->size -= 1; - ret = doc->md.image(ob, u_link, title, content, &doc->data); } else { ret = doc->md.link(ob, content, u_link, title, &doc->data); @@ -2812,8 +2823,10 @@ hoedown_document_new( if (doc->md.linebreak) doc->active_char['\n'] = MD_CHAR_LINEBREAK; - if (doc->md.image || doc->md.link || doc->md.footnotes || doc->md.footnote_ref) + if (doc->md.image || doc->md.link || doc->md.footnotes || doc->md.footnote_ref) { doc->active_char['['] = MD_CHAR_LINK; + doc->active_char['!'] = MD_CHAR_IMAGE; + } doc->active_char['<'] = MD_CHAR_LANGLE; doc->active_char['\\'] = MD_CHAR_ESCAPE; diff --git a/test/Tests/Images.html b/test/Tests/Images.html new file mode 100644 index 0000000..2e6367c --- /dev/null +++ b/test/Tests/Images.html @@ -0,0 +1,9 @@ +
This is an .
+ +This is a tricky !.
+ +This is another tricky case: !not image.
+ +This is a reference .
+ +Terminating !
diff --git a/test/Tests/Images.text b/test/Tests/Images.text new file mode 100644 index 0000000..24c0d32 --- /dev/null +++ b/test/Tests/Images.text @@ -0,0 +1,11 @@ +This is an ![image](/url). + +This is a tricky !![image](/url). + +This is another tricky case: \![not image](/url). + +This is a reference ![image][ref]. + +[ref]: /url2 + +Terminating ! diff --git a/test/config.json b/test/config.json index 5d873ad..5697951 100644 --- a/test/config.json +++ b/test/config.json @@ -115,6 +115,11 @@ "input": "Tests/Table.text", "output": "Tests/Table.html", "flags": ["--tables"] + }, + { + "input": "Tests/Images.text", + "output": "Tests/Images.html", + "flags": [] } ] }