Add title attribute to anchor tags

This commit is contained in:
Sebastian Martinez
2024-03-13 17:11:58 +01:00
committed by Rūdolfs Ošiņš
parent 67eef6caa7
commit 0918d38be9
+3 -3
View File
@@ -135,16 +135,16 @@ export class Renderer extends BaseRenderer {
return this.#stripEmphasizedStyling ? text : `<em>${text}</em>`;
}
link(href: string, _title: string, text: string): string {
link(href: string, title: string | undefined | null, text: string): string {
if (href.startsWith("#")) {
// By lowercasing we avoid casing mismatches, between headings and links.
return `<a href="${href.toLowerCase()}">${text}</a>`;
return `<a ${title ? `title="${title}"` : ""} href="${href.toLowerCase()}">${text}</a>`;
} else {
href = URL.canParse(href, this.#baseUrl)
? new URL(href, this.#baseUrl).href
: href;
return `<a href="${href}">${text}</a>`;
return `<a ${title ? `title="${title}"` : ""} href="${href}">${text}</a>`;
}
}
}