Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Merge pull request #287 from pengjiz/fix/gh-285
Browse files Browse the repository at this point in the history
Ignore all descriptions for rendered images

Closes GH-285
  • Loading branch information
swsnr authored Aug 4, 2024
2 parents b641315 + 3ed060b commit f67b44d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Use `cargo release` to create a new release.
### Changed
- Release builds no longer use fat LTO, which significantly reduces compilation time.

### Fixed
- mdcat no longer panics on markups in descriptions of rendered images (see [GH-287]).

[GH-287]: https://github.com/swsnr/mdcat/pull/287

## [2.3.0] – 2024-07-28

### Added
Expand Down
18 changes: 15 additions & 3 deletions pulldown-cmark-mdcat/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,22 @@ pub fn write_event<'a, W: Write>(
.and_data(data)
.ok()
}
(Stacked(stack, RenderedImage), Text(_)) => {
Stacked(stack, RenderedImage).and_data(data).ok()
}
// To correctly handle nested images in the image description, we push a dummy rendered
// image state so to maintain a correct state stack at the end of image event, where the
// tail of the stack gets popped.
(Stacked(stack, RenderedImage), Start(Image(_, _, _))) => stack
.push(RenderedImage)
.current(RenderedImage)
.and_data(data)
.ok(),
(Stacked(stack, RenderedImage), End(Image(_, _, _))) => stack.pop().and_data(data).ok(),
// Immediately after the start of image event comes the alt text, which we do not support
// for rendered images. So we just ignore all events other than image events, which are
// handled above.
//
// See also https://docs.rs/pulldown-cmark/0.9.6/src/pulldown_cmark/html.rs.html#280-290 for
// how the upstream handles images.
(Stacked(stack, RenderedImage), _) => Stacked(stack, RenderedImage).and_data(data).ok(),
(Stacked(stack, Inline(state, attrs)), End(Image(_, target, title))) => {
if let InlineLink = state {
clear_link(writer)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ An inline ]8;;https://example.com/\linked image[2]

An inline ]8;;https://example.com/\linked image[3]]8;;\ with nested formatting.

An inline]8;;file://HOSTNAME/WORKING_DIRECTORY/tests/render/md/samples/image.png\ image with a nested image[4] and markups in description]8;;\.

Or as block:

]8;;file://HOSTNAME/WORKING_DIRECTORY/tests/render/md/samples/image.png\image]8;;\

[1]: ]8;;file://HOSTNAME/WORKING_DIRECTORY/tests/render/md/samples/image.png\./image.png]8;;\
[2]: ]8;;file://HOSTNAME/WORKING_DIRECTORY/tests/render/md/samples/image.png\./image.png]8;;\
[3]: ]8;;file://HOSTNAME/WORKING_DIRECTORY/tests/render/md/samples/image.png\./image.png]8;;\
[4]: ]8;;file://HOSTNAME/WORKING_DIRECTORY/tests/render/md/samples/image.png\./image.png]8;;\
6 changes: 5 additions & 1 deletion pulldown-cmark-mdcat/tests/render/golden/dump/samples/images
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ An inline linked image[4][5] with some extra text.

An inline linked image[6][7] with nested formatting.

An inline image with a nested image[8] and markups in description[9].

Or as block:

image[8]
image[10]

[1]: ./image.png
[2]: ./image.png
Expand All @@ -18,3 +20,5 @@ image[8]
[6]: ./image.png
[7]: https://example.com
[8]: ./image.png
[9]: ./image.png
[10]: ./image.png
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ An inline ]8;;https://example.com/\linked]1337;File=name=aW1hZ2UucG5

An inline ]8;;https://example.com/\linked]1337;File=name=aW1hZ2UucG5n;size=1371;inline=1:iVBORw0KGgoAAAANSUhEUgAAACgAAAAUCAYAAAD/Rn+7AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAC4jAAAuIwF4pT92AAAE+0lEQVRIx62WTWgTaxSGnyTDmKKNNqOMxpoW02AbDHUK7gKV6kJxYfEHcacLXTRQdKsRKrhQXCnBhS5F/EcXioK0ILqQQqmhkmKDOIkQOi0ziZMqpaWdu5D5blISrL33wPD9M+93vnPe93gcx3H4C7MsC9u2sW2bUqkk5oLBIC0tLQQCAdr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vk86XSadDqN1+sVL2YYBtJKkjQMgx8/fojYcKXI6/Vy8uRJnj17BkBHRwd+vx+AX79+sXXrVs6dO8e1a9cYGxujUqnw8+dPZFkGYH5+Hq/XiyzLeDwe8vk8AA8ePGB5eZmenh42btxIpVIhm82KmJRCoVANcQJCjpaWlpidncUwDJqammhubsbd39zczNzcnNj38OFDTp8+TaFQ4Pv372J+37597N27l3Q6jaIovHz5Er/fT2dnJwCHDx8mFoshyzILCwt8+PCBVColEsV36tSpoQ0bNjA9PQ1ALpdjcnLyN3pJQtd1RkdHKZVK+P1+Ll68KELh8+fPvH//Hl3XOXbsGFNTU5TLZYLBICMjI8TjcTweD1euXKG7u5vl5WXK5TLRaJSOjg7a29t5/Pgxs7OzTExM0NnZiW3b7NixQySL5+7duw4gKonqTEokEgC0tLTgOI6oVDweD47j4PF4XLIXfXe8tLSEJElMTk7S398PwNTUFACvX7/m4MGDYv+7d+/I5XKiYABQVZVoNIqkKIoAVE+04/F4Xb6rBlTdd8eS9FtF37x5QzKZZHBwkJmZGVRVFTzqErZlWZw9e1ZwoKZpRKNR4vE4UiOyLRaL5HI54vE4ay0oAHp7e7l+/TqmaeLz+fj48SNdXV0C3EpyPnDgAJFIhNbW1n+VpFqwq1lcURQhbW4916gYbWQ9PT08evSo4bpt20IEQqEQmqYJKdV1Hck0zZpbaJomlKQ6Nl05zOfzqypQV2ujo6MitBKJhFAo1yG+M2fODLW2thIOh5FlGUVR0DSNnTt3srCwwNjYGJlMhlKpRCaTQZZlfD4fTU1NbNq0ac3ALMti3bp1zMzMMD8/T6VSEUyxuLhIIBDAtm3+Ach61YAcN+PJAAAAAElFTkSuQmCC\
2 changes: 2 additions & 0 deletions pulldown-cmark-mdcat/tests/render/md/samples/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ An inline [linked ![image](./image.png)](https://example.com) with some extra te

An inline [**linked ![image](./image.png)**](https://example.com) with nested formatting.

An inline ![image with a nested ![image](./image.png) and *markups* in description](./image.png).

Or as block:

![image](./image.png)

0 comments on commit f67b44d

Please sign in to comment.