Skip to content

Commit 38e34ec

Browse files
authored
Fix format-links object entries adding a duplicate link (#15312)
A `format-links` entry like `{format: typst, text: PDF}` added the renamed link, then the default link for every rendered format was added as well, because only plain string entries stop the default links. Each renamed format showed twice: once with the custom text, once with its default name. Rendered formats already linked by a `{format}` entry are now skipped when the default links are added. Other rendered formats keep their default link, and plain string entries still make `format-links` an explicit list. Counting `{format}` entries like plain strings would also fix the duplicates, but it drops the link to every rendered format not listed. A GitHub code search found a public document that would lose its whole "Other Formats" section that way, so that option was not taken. Fixes #9606
1 parent 286c5d6 commit 38e34ec

5 files changed

Lines changed: 88 additions & 1 deletion

File tree

‎news/changelog-1.12.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All changes included in 1.12:
1616

1717
### `html`
1818

19+
- ([#9606](https://github.com/quarto-dev/quarto-cli/issues/9606)): Fix `format-links` entries written as `{format, text}` adding a second, default link for the same format instead of renaming its link.
1920
- ([#15269](https://github.com/quarto-dev/quarto-cli/pull/15269)): Fix `link-external-newwindow` overriding a `target` set explicitly on a link. (author: @mcanouil)
2021

2122
### `pdf`

‎src/format/html/format-html-links.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ export function alternateLinks(
112112
};
113113
};
114114

115+
// Formats renamed by a `{format, text}` entry, so no default link is added for them
116+
const renamedFormats = new Set<RenderedFormat>();
117+
115118
let count = 1;
116119
for (const userLink of userLinks || []) {
117120
if (typeof userLink === "string") {
@@ -132,6 +135,7 @@ export function alternateLinks(
132135
f.format.identifier[kTargetFormat] === thatLink.format
133136
);
134137
if (rf) {
138+
renamedFormats.add(rf);
135139
// Just push through
136140
alternateLinks.push(
137141
alternateLinkForFormat(rf, count, thatLink.text, thatLink.icon),
@@ -159,7 +163,10 @@ export function alternateLinks(
159163
if (!userLinksHasFormat) {
160164
formats.forEach((renderedFormat) => {
161165
const baseFormat = renderedFormat.format.identifier["base-format"];
162-
if (!kExcludeFormatUnlessExplicit.includes(baseFormat || "html")) {
166+
if (
167+
!kExcludeFormatUnlessExplicit.includes(baseFormat || "html") &&
168+
!renamedFormats.has(renderedFormat)
169+
) {
163170
alternateLinks.push(alternateLinkForFormat(renderedFormat, count));
164171
}
165172
count++;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: "format-links with only an explicit href link"
3+
format:
4+
html:
5+
format-links:
6+
- text: Quarto
7+
href: https://quarto.org/
8+
icon: globe
9+
typst: default
10+
docx: default
11+
_quarto:
12+
tests:
13+
html:
14+
ensureHtmlElementCount:
15+
selectors:
16+
- '.quarto-alternate-formats a'
17+
- '.quarto-alternate-formats a[href="https://quarto.org/"]'
18+
- '.quarto-alternate-formats a[href="9606-href.pdf"]'
19+
- '.quarto-alternate-formats a[href="9606-href.docx"]'
20+
counts: [3, 1, 1, 1]
21+
---
22+
23+
`format-links` has a single `{text, href}` link, which names no format.
24+
It is added on top of the default links, so Typst and docx keep theirs (#9606).
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: "format-links renaming only some formats"
3+
format:
4+
html:
5+
format-links:
6+
- format: typst
7+
text: PDF
8+
icon: file-pdf
9+
typst: default
10+
docx: default
11+
_quarto:
12+
tests:
13+
html:
14+
ensureHtmlElementCount:
15+
selectors:
16+
- '.quarto-alternate-formats a'
17+
- '.quarto-alternate-formats a[href="9606-partial.pdf"]'
18+
- '.quarto-alternate-formats a[href="9606-partial.docx"]'
19+
counts: [2, 1, 1]
20+
ensureHtmlElementContents:
21+
selectors: ['.quarto-alternate-formats a[href="9606-partial.pdf"]']
22+
matches: ['^PDF$']
23+
---
24+
25+
`format-links` renames the Typst link with a `{format, text, icon}` object and does not mention docx.
26+
The Typst link is renamed, with no second default link for it, and docx keeps its default link (#9606).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: "format-links with only `{format, text}` entries"
3+
format:
4+
html:
5+
format-links:
6+
- format: typst
7+
text: PDF
8+
icon: file-pdf
9+
- format: docx
10+
text: Word
11+
icon: file-word
12+
typst: default
13+
docx: default
14+
_quarto:
15+
tests:
16+
html:
17+
ensureHtmlElementCount:
18+
selectors:
19+
- '.quarto-alternate-formats a'
20+
- '.quarto-alternate-formats a[href="9606.pdf"]'
21+
- '.quarto-alternate-formats a[href="9606.docx"]'
22+
counts: [2, 1, 1]
23+
ensureHtmlElementContents:
24+
selectors: ['.quarto-alternate-formats a[href="9606.docx"]']
25+
matches: ['^Word$']
26+
---
27+
28+
`format-links` lists every format as a `{format, text, icon}` object and has no plain string entry.
29+
Listing a format this way renames its link: "Other Formats" shows only PDF and Word, not the default Typst and MS Word links as well (#9606).

0 commit comments

Comments
 (0)