# markdown_preview: Fix rendering image not at all or too often \(\#25592\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/85a761cb2b7cb55fb9fca05828b7750a3f42949d)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 85a761cb2b7cb55fb9fca05828b7750a3f42949d

Requested commit: 85a761cb2b7cb55fb9fca05828b7750a3f42949d

Commit: 85a761cb2b7cb55fb9fca05828b7750a3f42949d

Tree: 76d661603c9563378e5a1fad08cbbe3a4bbd037a

Author: Martin Fischer

Committer: GitHub

## Message

```
markdown_preview: Fix rendering image not at all or too often (#25592)

Before MarkdownParagraphChunk::Image was pushed for every Text event if
we're currently inside an image. This was wrong since pulldown-cmark
parses `![](foo)` as:

Start(Image { link_type: Inline, dest_url: "foo", title: "", id: "" })
    End(Image)

If there is no alt text, no Text event is emitted. Which caused images
without any alt text not to be rendered at all.

For alt texts containing inline formatting this was even more obviously
broken since e.g. `![foo *bar* baz](foo)` gets parsed as:

Start(Image { link_type: Inline, dest_url: "foo", title: "", id: "" })
      Text(Borrowed("foo "))
      Start(Emphasis)
        Text(Borrowed("bar"))
      End(Emphasis)
      Text(Borrowed(" baz"))
    End(Image)

which for this example caused the image to appear 3 times in the
preview.

This commit fixes these two bugs which have existed since the
introduction of the image previews in
96854c68eadd1dd72aa379368fde3cea791498a4.

Release Notes:

- Fixed images in the markdown preview appearing not at all or too
often.
```

## Parents

- [739f45eb23831f9e7ce3397337c7402ba212b3d4](https://git.cafe/gitcafe/zed/commit/739f45eb23831f9e7ce3397337c7402ba212b3d4?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/85a761cb2b7cb55fb9fca05828b7750a3f42949d?format=markdown)
