From c054614c6f0052531f1418149b1c8184d746a8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:21:10 +0100 Subject: [PATCH 01/14] fix: escape every character in HTML attribute values --- news/changelog-1.12.md | 6 ++++++ src/core/html.ts | 4 ++-- tests/unit/core/html-encode.test.ts | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/unit/core/html-encode.test.ts diff --git a/news/changelog-1.12.md b/news/changelog-1.12.md index 22c6b6c7d10..a06b5627b67 100644 --- a/news/changelog-1.12.md +++ b/news/changelog-1.12.md @@ -11,6 +11,12 @@ All changes included in 1.12: - ([#15168](https://github.com/quarto-dev/quarto-cli/issues/15168)): Fix definitions, examples and exercises being set in italics in Typst output with the default `theorem-appearance: simple`. Their body is now upright, as in LaTeX output, while theorems, lemmas, corollaries, propositions and conjectures keep an italic body. (author: @mcanouil) - ([#15251](https://github.com/quarto-dev/quarto-cli/pull/15251)): Fix algorithm blocks (`#alg-`) being set in italics with `theorem-appearance: simple` and using the colours of theorems with `theorem-appearance: fancy`. They now look like definitions, examples and exercises. (author: @mcanouil) +## Projects + +### `website` + +- ([#12276](https://github.com/quarto-dev/quarto-cli/discussions/12276)): Fix listing `image-alt` values containing quotes or `&` rendering broken or double-escaped alt text. (author: @mcanouil) + ## Commands ### `quarto preview` diff --git a/src/core/html.ts b/src/core/html.ts index dfbc87bcf18..4835210be5c 100644 --- a/src/core/html.ts +++ b/src/core/html.ts @@ -40,16 +40,16 @@ const kTagBrackets: Record = { }; const kAttrReplacements: Record = { + "&": "&", '"': """, "'": "'", ...kTagBrackets, - "&": "&", }; export function encodeAttributeValue(value: unknown) { if (typeof (value) === "string") { let result: string = value as string; Object.keys(kAttrReplacements).forEach((key) => { - result = result.replace(key, kAttrReplacements[key]); + result = result.replaceAll(key, kAttrReplacements[key]); }); return result; } else { diff --git a/tests/unit/core/html-encode.test.ts b/tests/unit/core/html-encode.test.ts new file mode 100644 index 00000000000..0e9267e0e85 --- /dev/null +++ b/tests/unit/core/html-encode.test.ts @@ -0,0 +1,18 @@ +/* + * html-encode.test.ts + * + * Copyright (C) 2026 Posit Software, PBC + */ + +import { assertEquals } from "testing/asserts"; +import { unitTest } from "../../test.ts"; +import { encodeAttributeValue } from "../../../src/core/html.ts"; + +unitTest("encodeAttributeValue escapes every quote once", async () => { + assertEquals( + encodeAttributeValue('_blank" onmouseover="x'), + "_blank" onmouseover="x", + ); + assertEquals(encodeAttributeValue("a & b & c"), "a & b & c"); + assertEquals(encodeAttributeValue("<'>"), "<'>"); +}); From 3308633450be704867f318f2ae8b4cf5ec3e8c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:35:32 +0100 Subject: [PATCH 02/14] feat: add target and rel to website listings --- .../website/listing/website-listing-read.ts | 9 +- .../website/listing/website-listing-shared.ts | 6 + .../listing/website-listing-template.ts | 19 ++- .../website/listing/item-default.ejs.md | 12 +- .../projects/website/listing/item-grid.ejs.md | 4 +- .../website/listing/listing-table.ejs.md | 3 + src/resources/schema/definitions.yml | 24 +++ .../listings/link-target/.gitignore | 3 + .../listings/link-target/_quarto.yml | 10 ++ .../listings/link-target/absent.qmd | 16 ++ .../playwright/listings/link-target/grid.qmd | 22 +++ .../listings/link-target/hostile.qmd | 14 ++ .../playwright/listings/link-target/index.qmd | 22 +++ .../listings/link-target/local-post.qmd | 5 + .../playwright/listings/link-target/table.qmd | 23 +++ .../tests/html-listing-link-target.spec.ts | 152 ++++++++++++++++++ 16 files changed, 330 insertions(+), 14 deletions(-) create mode 100644 tests/docs/playwright/listings/link-target/.gitignore create mode 100644 tests/docs/playwright/listings/link-target/_quarto.yml create mode 100644 tests/docs/playwright/listings/link-target/absent.qmd create mode 100644 tests/docs/playwright/listings/link-target/grid.qmd create mode 100644 tests/docs/playwright/listings/link-target/hostile.qmd create mode 100644 tests/docs/playwright/listings/link-target/index.qmd create mode 100644 tests/docs/playwright/listings/link-target/local-post.qmd create mode 100644 tests/docs/playwright/listings/link-target/table.qmd create mode 100644 tests/integration/playwright/tests/html-listing-link-target.spec.ts diff --git a/src/project/types/website/listing/website-listing-read.ts b/src/project/types/website/listing/website-listing-read.ts index 1737deabcf7..40212f94269 100644 --- a/src/project/types/website/listing/website-listing-read.ts +++ b/src/project/types/website/listing/website-listing-read.ts @@ -15,10 +15,7 @@ import { relative, } from "../../../../deno_ral/path.ts"; import { cloneDeep, orderBy, uniq } from "../../../../core/lodash.ts"; -import { - existsSync, - safeExistsFileSync, -} from "../../../../deno_ral/fs.ts"; +import { existsSync, safeExistsFileSync } from "../../../../deno_ral/fs.ts"; import { Format, Metadata } from "../../../../config/types.ts"; import { @@ -72,11 +69,13 @@ import { kListing, kMaxDescLength, kPageSize, + kRel, kSortAsc, kSortDesc, kSortUi, kTableHover, kTableStriped, + kTarget, Listing, ListingDehydrated, ListingDescriptor, @@ -600,7 +599,7 @@ function hydrateListing( // If the items have come from metadata, we should just show // all the columns in the table. Otherwise, we should use the // document default columns - const undisplayable = ["path"]; + const undisplayable = ["path", kTarget, kRel]; return itemFields.filter((field) => { return !undisplayable.includes(field); }); diff --git a/src/project/types/website/listing/website-listing-shared.ts b/src/project/types/website/listing/website-listing-shared.ts index a4fbbf8d7b0..d1ece1701e2 100644 --- a/src/project/types/website/listing/website-listing-shared.ts +++ b/src/project/types/website/listing/website-listing-shared.ts @@ -90,6 +90,10 @@ export const kDefaultMaxDescLength = 175; export const kTableStriped = "table-striped"; export const kTableHover = "table-hover"; +// Link attributes +export const kTarget = "target"; +export const kRel = "rel"; + // Items to include export const kInclude = "include"; export const kExclude = "exclude"; @@ -173,6 +177,8 @@ export interface Listing extends ListingDehydrated { [kFilterUi]: boolean; [kSortUi]: boolean; [kImagePlaceholder]?: string; + [kTarget]?: string; + [kRel]?: string; sort?: ListingSort[]; template?: string; diff --git a/src/project/types/website/listing/website-listing-template.ts b/src/project/types/website/listing/website-listing-template.ts index e06b99998b4..1072eb98d08 100644 --- a/src/project/types/website/listing/website-listing-template.ts +++ b/src/project/types/website/listing/website-listing-template.ts @@ -31,8 +31,10 @@ import { kMaxDescLength, kMaxItems, kPageSize, + kRel, kSortAsc, kSortDesc, + kTarget, Listing, ListingItem, ListingSort, @@ -311,6 +313,8 @@ export interface ReshapedListing extends Listing { utilities: Record; } +const kSameContextTargets = ["_self", "_parent", "_top"]; + // Options may also need computation / resolution before being handed // off to the template. This function will do any computation on the options // so they're ready for the template @@ -394,6 +398,19 @@ export function reshapeListing( utilities.fieldName = (field: string) => { return reshaped[kFieldDisplayNames][field] || field; }; + const targetAttrs = (item: ListingItem) => { + const asValue = (value: unknown) => + typeof value === "string" && value !== "" ? value : undefined; + const target = asValue(item[kTarget]) ?? asValue(listing[kTarget]); + const explicitRel = asValue(item[kRel]) ?? asValue(listing[kRel]); + const rel = explicitRel ?? + (target && !kSameContextTargets.includes(target.toLowerCase()) + ? "noopener" + : undefined); + return (target ? ` target="${encodeAttributeValue(target)}"` : "") + + (rel ? ` rel="${encodeAttributeValue(rel)}"` : ""); + }; + utilities.targetAttrs = targetAttrs; utilities.outputLink = ( item: ListingItem, field: string, @@ -404,7 +421,7 @@ export function reshapeListing( const value = val || item[field] || " "; const path = item.path; if (path && value !== undefined && fieldLinks.includes(field)) { - return `${value}`; } else { diff --git a/src/resources/projects/website/listing/item-default.ejs.md b/src/resources/projects/website/listing/item-default.ejs.md index c309964a887..45d1e47c32c 100644 --- a/src/resources/projects/website/listing/item-default.ejs.md +++ b/src/resources/projects/website/listing/item-default.ejs.md @@ -8,7 +8,7 @@ const imageHeight = listing['image-height']; // Fields that don't have a known place to be displayed in this template const otherFields = fields.filter(field => { -return !["title", "image", "image-alt", "date", "author", "subtitle", "description", "reading-time", "categories"].includes(field); +return !["title", "image", "image-alt", "date", "author", "subtitle", "description", "reading-time", "categories", "target", "rel"].includes(field); }); // Capture the item number for utility functions that need it @@ -54,7 +54,7 @@ print(`