quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.91k stars 322 forks source link

`format-links` should support `target` attributes, and in general same attributes option as `other-links` #10730

Open cderv opened 1 month ago

cderv commented 1 month ago

Discussed in https://github.com/quarto-dev/quarto-cli/discussions/10729

Originally posted by **aghaynes** September 6, 2024 ### Description In a quarto website, I'd like to provide PDF versions of the various pages, which works great by setting ``` format: html: default pdf: default ``` But I would like the PDF to open in a new window (or even appear as a download), which i would normally do with `target="_blank"`. According to the [quarto website](https://quarto.org/docs/output-formats/html-multi-format.html), it's possible to use `format-links` to customise the links, including any of the options from [https://quarto.org/docs/output-formats/html-basics.html#code-links-and-other-links](the code links section). Unfortunately, I've been unable to get the target option to work. I've tried all four variants that come to mind (`"blank"`, `"_blank"`, `blank` and `_blank`), but none seem to work for the PDF, nor generic links. I also don't see the target attribute in the generated HTML code... Am I missing something, or is it ignoring the additional attributes? I don't see the target attribute in the generated HTML code... The target does work with other-links though via `target: _blank`... ````qmd --- title: "x" format: html: default typst: default format-links: - html - format: typst text: PDF icon: file-pdf target: _blank - text: Other Link href: https://quarto.org/ icon: hand-thumbs-down target: _blank other-links: - text: Another Link href: https://quarto.org/ icon: hand-thumbs-up target: _blank --- This is a Quarto website. To learn more about Quarto websites visit . ```{r} 1 + 1 ``` ```` Thanks for any suggestions!
cderv commented 1 month ago

In our doc, we say the following (https://quarto.org/docs/output-formats/html-multi-format.html#specifying-formats-to-link)

You can also provide format-links items using the same options as Code Links and Other Links.

However, it seems not all option are supported, especially target options. image

It seems we indeed make a difference on what is supported by each type of element https://github.com/quarto-dev/quarto-cli/blob/7a0131d23e5525629de83959cd2d585f28603a92/src/config/types.ts#L737-L758

We currently only handle rel and target for other-links https://github.com/quarto-dev/quarto-cli/blob/7a0131d23e5525629de83959cd2d585f28603a92/src/format/html/format-html-bootstrap.ts#L581-L594

We can probably add target (e.g. to set target = "_blank") when customizing format-links