astefanutti / decktape

PDF exporter for HTML presentations
MIT License
2.17k stars 175 forks source link

Handling relative URLs with Decktape #238

Open btjanaka opened 2 years ago

btjanaka commented 2 years ago

Hi! I am trying to convert a reveal.js presentation which includes relative links on the slides, e.g.

<a href="./foobar.html">Text</a>

When I convert via the ?print-pdf URL with reveal.js, such links are converted into absolute links, e.g. https://btjanaka.net/foobar.html, such that when I open the PDF, I can click on the link and be taken to the correct website.

Currently, I am trying to convert a local presentation on my filesystem to a PDF with decktape, e.g.

decktape ./build/index.html slides.pdf

The conversion works fine, but when I click on the link, it remains a relative URL and does not work. Of course, this makes sense, since I did everything locally.

I am wondering, is there some way to turn relative URLs into absolute URLs when performing a conversion with Decktape?

If not, would it be advisable to try something like developing a script that iterates through and changes every link? Thanks!

astefanutti commented 2 years ago

Hi, indeed the link URLs are not processed and exported as is.

Obviously, you could develop a pre-processing step that would change all the links and then run Decktape.

An other alternative could be to have an option in Decktape, that would activate the logic of iterating over all the relative links in every PDF page, and changing them to absolute links. We already iterate over images and fonts, so iterating over links would perfectly fit there:

https://github.com/astefanutti/decktape/blob/e4cb6319830cd1c2c1c633afe39cde36dfeac5b1/decktape.js#L405

btjanaka commented 2 years ago

Wow, thank you for such a prompt response. Unfortunately, I don't think I have bandwidth to implement this, but I will definitely keep an eye on this issue.

psimm commented 6 months ago

Hi, indeed the link URLs are not processed and exported as is.

Obviously, you could develop a pre-processing step that would change all the links and then run Decktape.

Could you please explain what this pre-processing step would have to do?

For example, I have an internal link:

<a href="#/section-1">Section 1</a>

What would the processed link be? I attempted to use an absolute link to the local file:

<a href="file:///Users/me/Documents/presentation.html#section-1>Section 1</a>

but that didn't work.

astefanutti commented 6 months ago

@psimm based on your example, I think your use case is about internal links rather than relative links. There is another issue #49 open for handling the former.