Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/view/frontend/web/js/toolbar/audits.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ import { audits, auditGroups } from "./audits/index.js";
// time to finish after synchronous mutations (typically 1–2 frames = 16ms).
const AUDIT_SETTLE_DELAY_MS = 200;

/**
* Make a selector safe for an inline code span inside a Markdown table cell.
*
* @param {string} selector
* @returns {string}
*/
function escapeMdCode(selector) {
// Backslashes stay as-is: they are literal inside code spans. Only the table
// delimiter needs escaping.
return selector
.replace(/`/g, "'")
.split("|")
.join("\\|")
.replace(/\s+/g, " ");
}

export const auditMethods = {
/**
* Toggles an audit on/off and updates the menu item state.
Expand Down Expand Up @@ -353,7 +369,7 @@ export const auditMethods = {
lines.push("| Selector | Severity |");
lines.push("|----------|----------|");
findings.forEach(({ selector, severity }) => {
lines.push(`| \`${selector}\` | ${severity} |`);
lines.push(`| \`${escapeMdCode(selector)}\` | ${severity} |`);
});
} else {
// Page-level audit: badge only, no element selectors
Expand Down
Loading