mdcat icon indicating copy to clipboard operation
mdcat copied to clipboard

mdcat panics if image title is in two lines

Open laoshaw opened this issue 2 years ago • 2 comments

Not quite sure if this is a mdcat bug: if I split the image line into two lines as below, run mdcat test.md under kitty will abort as shown below.

test.md

![
](my.png)

run mdcat test.md it will report below errors:

thread 'main' panicked at 'Event SoftBreak impossible in state Stacked(StateStack { top_level: TopLevelAttrs { margin_before: Margin }, states: [Inline(InlineText, InlineAttrs { style: Style {}, indent: 0 })] }, RenderedImage)

put test.md above into one line it works fine.

laoshaw avatar Nov 16 '21 04:11 laoshaw

It probably is; I've never seen this before and it doesn't seem to be part of the common mark test suite, so I don't think mdcat handles this.

I'll perhaps fix this at some point but it'll take time; to me this is a weird corner case so until I actually hit a document with this it's pretty low on my priority list.

If you need to have this fixed any time soon please do open a pull request.

swsnr avatar Nov 16 '21 08:11 swsnr

I agree, just add why this happens: pandoc converts html to markdown and if an image has a long line, pandoc will break it into two lines and cause mdcat to misbehave, e.g.

! [ this is a super long line whatever asdf asdfsdafsdf fsdfsdfsf sfsdf  sfsdfs sdfsfsdf
and it has to continue to next time](you-image-here)

laoshaw avatar Nov 16 '21 12:11 laoshaw

On the macOS M1 environment, even a simple image does not display using kitty installed using brew.
It displays the base64 of the image instead of the image. iterm2 works just fine.

The error log shows [357 19:35:08.151068] [PARSE ERROR] OSC sequence too long, truncating. [357 19:35:08.151117] [PARSE ERROR] Unknown OSC code: 1337

The input file contains this single line.

![title](https://styles.redditmedia.com/t5_3r1tmi/styles/communityIcon_1g0st8ztvcc61.png)

The traceback when I put the ']' on the second line.

AAAAAAAAAA+BP/D/opYN+C64vvAAAAAElFTkSuQmCCthread 'main' panicked at 'Event SoftBreak impossible in state Stacked(StateStack { top_level: TopLevelAttrs { margin_before: Margin }, states: [Inline(InlineText, InlineAttrs { style: Style {}, indent: 0 })] }, RenderedImage)

Please do report an issue at https://github.com/swsnr/mdcat/issues/new including

  • a copy of this message, and
  • the markdown document which caused this error.', /Users/norm/Projects/mdcat/src/render.rs:726:19 stack backtrace: 0: 0x1019b6fc0 - std::backtrace_rs::backtrace::libunwind::trace::hbe97f4303076f99a at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x1019b6fc0 - std::backtrace_rs::backtrace::trace_unsynchronized::hb462a91ac605b16b at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x1019b6fc0 - std::sys_common::backtrace::_print_fmt::h555c176cf2344151 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:65:5 3: 0x1019b6fc0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he84d5e26d26c914d at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:44:22 4: 0x1019d3644 - core::fmt::write::h07c7e4739f78f3b0 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/fmt/mod.rs:1209:17 5: 0x1019b0c58 - std::io::Write::write_fmt::h4a3c5f094ffc65e8 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/io/mod.rs:1682:15 6: 0x1019b6dd4 - std::sys_common::backtrace::_print::h03a1c9ac6001091a at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:47:5 7: 0x1019b6dd4 - std::sys_common::backtrace::print::h6fc2cc8be2392a8e at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:34:9 8: 0x1019b8614 - std::panicking::default_hook::{{closure}}::h3bb44ba6ff437e23 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:267:22 9: 0x1019b836c - std::panicking::default_hook::h92c6668a1a98ae8c at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:286:9 10: 0x1019b8c50 - std::panicking::rust_panic_with_hook::h9b8acc949e1fb807 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:688:13 11: 0x1019b8a60 - std::panicking::begin_panic_handler::{{closure}}::hfc38b2cc56e3623c at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:579:13 12: 0x1019b7428 - std::sys_common::backtrace::__rust_end_short_backtrace::hbafd151207fc448f at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:137:18 13: 0x1019b87b4 - rust_begin_unwind at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:575:5 14: 0x1019f0550 - core::panicking::panic_fmt::h8c7f3d540a75578f at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/panicking.rs:65:14 15: 0x100eeb080 - mdcat::render::write_event::h10ccc23c4232565a at /Users/norm/Projects/mdcat/src/render.rs:726:19 16: 0x100f14ac4 - mdcat::push_tty::{{closure}}::h94cc4bc97b7a9631 at /Users/norm/Projects/mdcat/src/lib.rs:120:13 17: 0x100f06194 - core::iter::traits::iterator::Iterator::try_fold::h0019ef915c00a4e5 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/iter/traits/iterator.rs:2238:21 18: 0x100f14744 - mdcat::push_tty::h85fc26d5fbe5d71a at /Users/norm/Projects/mdcat/src/lib.rs:117:49 19: 0x100f0916c - mdcat::process_file::h0e0b1b8aa1a74138 at /Users/norm/Projects/mdcat/src/bin/mdcat/main.rs:69:5 20: 0x100f0dedc - mdcat::main::{{closure}}::h483d4172edbda92b at /Users/norm/Projects/mdcat/src/bin/mdcat/main.rs:151:25 21: 0x100f05d4c - core::iter::traits::iterator::Iterator::try_fold::h13ca726bde246f31 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/iter/traits/iterator.rs:2238:21 22: 0x100f07d3c - mdcat::main::h9b7facbac412622b at /Users/norm/Projects/mdcat/src/bin/mdcat/main.rs:148:17 23: 0x100efd490 - core::ops::function::FnOnce::call_once::h6b1f44c4cfca9755 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/ops/function.rs:251:5 24: 0x100f050f8 - std::sys_common::backtrace::__rust_begin_short_backtrace::haef8f3d97380be68 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:121:18 25: 0x100eff44c - std::rt::lang_start::{{closure}}::h8c71eb024f89d86c at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/rt.rs:166:18 26: 0x1019ab23c - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::ha4b10a239e2af884 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/ops/function.rs:286:13 27: 0x1019ab23c - std::panicking::try::do_call::h6b4bcb7d3635e86a at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:483:40 28: 0x1019ab23c - std::panicking::try::h579c8cca81ff0f69 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:447:19 29: 0x1019ab23c - std::panic::catch_unwind::h4a997c12755a6e33 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panic.rs:137:14 30: 0x1019ab23c - std::rt::lang_start_internal::{{closure}}::hf20057b44f57f87c at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/rt.rs:148:48 31: 0x1019ab23c - std::panicking::try::do_call::hdfca34da16d8863f at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:483:40 32: 0x1019ab23c - std::panicking::try::h4f4022e500de0807 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:447:19 33: 0x1019ab23c - std::panic::catch_unwind::h62721286166676e8 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panic.rs:137:14 34: 0x1019ab23c - std::rt::lang_start_internal::h659a783147314d97 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/rt.rs:148:20 35: 0x100eff414 - std::rt::lang_start::hfaf5ae2cd6568221 at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/rt.rs:165:17 36: 0x100f09288 - _main

norman-abramovitz avatar Dec 24 '22 03:12 norman-abramovitz

Can you please fix the formatting of your comment?

I've only skimmed it but the actual error seems to be that images don't get shown in kitty? If so that's a separate problem; please open a new issue for this.

swsnr avatar Dec 24 '22 06:12 swsnr

@norman-abramovitz Friendly ping. Please fix the syntax of your comment; I've hidden it meanwhile.

You might also want to run mdcat --detect-only to check what terminal mdcat assumes you have, because I presume it's wrong: mdcat has a dedicated kitty backend, and thus shouldn't attempt to print iterm commands to kitty terminals.

swsnr avatar Dec 28 '22 20:12 swsnr

Hi,

I was attempting to reproduce the original issue and not introduce a new issue and provide additional information that I found. I will try the detect-only option when I look at this issue again. I do have iterm2 and kitty on my mac, but I do launch them independently. Maybe some env vars getting in the way.

norman-abramovitz avatar Jan 03 '23 17:01 norman-abramovitz

Closing this, because it doesn't affect me.

swsnr avatar Oct 18 '23 18:10 swsnr