Enter-tainer / typst-preview

[DEPRECATED] Use tinymist instead
https://Enter-tainer.github.io/typst-preview/
MIT License
444 stars 21 forks source link

Links to local files do not open properly in slide mode #258

Open ntjess opened 9 months ago

ntjess commented 9 months ago

Describe the bug #link("./path/to/file")[text] should provide a hyperlink to a local resource. This works in PDF and SVG outputs. However, slide mode previews just open a new copy of the slide deck instead of the linked resource

To Reproduce

  1. Add a relative link to a local file (a mp4 video in my case)
  2. Specify "preview in browser and slide mode"
  3. Click the link
  4. You will be redirected to a new browser tab showing the slide deck, not your local resource
Enter-tainer commented 9 months ago

I just confirm this. This is because the target of the link is ./path/to/file, so the browser jumps to 127.0.0.1:some_port/path/to/file. And we jump to / for all unknown path, so another preview tab is opened. https://github.com/Enter-tainer/typst-preview/blob/eb88f6056d9212f209e1b799c5ea456aee7b2811/src/main.rs#L46

But i think this can be hard to fix. And links in official typst-cli's svg is not clickable.

Myriad-Dreamin commented 9 months ago

The webview is likely to never have access to the filesystem, because the browser disallows you to do that. We can forward file resources with authorization from preview server, tho.

It may still beyond the design of typst, which is probably broken by future typst. Regard to that, should we discuss it in scope of typst instead of in scope of typst-preview?

Myriad-Dreamin commented 9 months ago

To avoid webview indirectly accessing to filesystem, you can embed the video by reading content by read first.

#let video = read("./video.mp4");
#let svg-to-embed = embed-video(video);
ntjess commented 9 months ago

A note to future readers, you will need to specify encoding: none and ensure the video is very short. Even a 1MB will cause the extension to hang for a long time (at least in my case)