rstudio / pagedown

Paginate the HTML Output of R Markdown with CSS for Print

Home Page:https://pagedown.rbind.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chrome_print: URLs not formatted correctly

JonasGeschke opened this issue · comments

Hi, I am using chrome_print, pagedown version 0.18. I have the following settings, but the URLs in the PDF are not formatted correctly:

pagedown::chrome_print(input = output_html, output = output_pdf, format = "pdf",
wait = 5,
options = list(printBackground = TRUE,
marginTop = 0,
marginRight = 0,
marginBottom = 0,
marginLeft = 0,
preferCSSPageSize = TRUE))

When creating the HTML file with R markdown, the issue comes both using [Text](URL) and <a href="URL">Text</a>.
In the HTML, the URLs look fine. In the PDF, the URLs look like Text (URL).

Any idea on what could cause this? Or actually how to solve this?

In the PDF, the URLs look like Text (URL).

This is expected, and in fact a feature of pagedown. See the documentation about that https://pagedown.rbind.io/#links

Without interactivity (if you print on paper for example for a report), an inline link where url is hidden behind a text wouldn't be accessible. So it needs to be shown in the print version.

You can set links-to-footnotes: true in YAML so that the inline link is transformed to a footnote.

It seems you are expecting a different behavior. Can you give details ? Maybe we need to add another option to format links depending on another usage.

Many thanks for the quick repsonse, which is very useful! I actually didnt see the pagedown.rbind.io manual before...

What I expected was similar to the inline link on a website, that in the PDF too you have a some text with a link to a more complex/ugly URL hidden behind it. But if thats not supposed to be the manual helps working around it :-)

What I expected was similar to the inline link on a website, that in the PDF too you have a some text with a link to a more complex/ugly URL hidden behind it.

We could add an option for this but this would mean that printing the PDF on paper will make link disappear. That is why we are showing the url somehow so that it is still seen even without interactivity when you can't click on the link.

Thanks for following up. Well if it is possible (= not too much effort) to add the option that in digital PDFs links are hidden behind text, this would be great I think. Of course, it always depends on the use of links, what text people want to use, and if the URL will get lost when printing.
In our specific case we want to link dois, so the text would still do the trick but it would be nice to have it clickable. But with the help of your explanation above, "the data is available on [Zenodo] (URL)" is totally fine for us.

Up to you if you add the hidden URL option or not.

Well if it is possible (= not too much effort) to add the option that in digital PDFs links are hidden behind text, this would be great I think.

That's a reasonable request, and shouldn't be hard to do. Currently the URLs are displayed via this CSS trick:

a[href^="http"]:not([class="uri"])::after {
content: " (" attr(href) ")";

So you can actually override this CSS rule by:

a[href^="http"]:not([class="uri"])::after {
  content: none;
}

If you do not know how to provide custom CSS to pagedown, here is the documentation: https://pagedown.rbind.io/#the-css-overriding-mechanism

Perfect, this is exactly what I needed! Many thanks!