feat(share): display an icon for attachment download

This commit is contained in:
Elian Doran 2025-12-28 21:03:30 +02:00
parent 1ae11ce3a5
commit 082040c6e1
No known key found for this signature in database
2 changed files with 13 additions and 6 deletions

View File

@ -1,7 +1,8 @@
import { describe, it, expect } from "vitest";
import { getContent, renderCode, type Result } from "./content_renderer.js";
import { trimIndentation } from "@triliumnext/commons";
import { describe, expect,it, vi } from "vitest";
import { buildShareNote, buildShareNotes } from "../test/shaca_mocking.js";
import { getContent, renderCode, type Result } from "./content_renderer.js";
describe("content_renderer", () => {
beforeAll(() => {
@ -84,7 +85,7 @@ describe("content_renderer", () => {
<span class="hljs-tag">&lt;/<span class="hljs-name">BuilderRow</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">t</span>&gt;</span></code>
</pre>
`)
`);
});
describe("Reference links", () => {
@ -106,7 +107,7 @@ describe("content_renderer", () => {
expect(result.content).toStrictEqual(trimIndentation`\
<h1>Test</h1>
<p>
<a class="reference-link attachment-link role-file" href="api/attachments/q14s2Id7V6pp/download">5863845791835102555.mp4</a>
<a class="reference-link attachment-link role-file" href="api/attachments/q14s2Id7V6pp/download"><span><span class="tn-icon bx bx-download"></span>5863845791835102555.mp4</span></a>
&nbsp;
</p>
`);
@ -170,7 +171,7 @@ describe("content_renderer", () => {
const result = getContent(note);
expect(result.content).toStrictEqual(trimIndentation`\
<p>
<a class="reference-link type-text" href="./MSkxxCFbBsYP"><span><span class="bx bx-note"></span>The quick &lt;strong&gt;brown&lt;/strong&gt; fox</span></a>
<a class="reference-link type-text" href="./MSkxxCFbBsYP"><span><span class="tn-icon bx bx-note"></span>The quick &lt;strong&gt;brown&lt;/strong&gt; fox</span></a>
</p>
`);
});

View File

@ -413,7 +413,13 @@ function handleAttachmentLink(linkEl: HTMLElement, href: string, getNote: GetNot
function cleanUpReferenceLinks(linkEl: HTMLElement, getNote: GetNoteFunction) {
// Note: this method is basically a reimplementation of getReferenceLinkTitleSync from the link service of the client.
const href = linkEl.getAttribute("href") ?? "";
if (linkEl.classList.contains("attachment-link")) return;
// Handle attachment reference links
if (linkEl.classList.contains("attachment-link")) {
const title = linkEl.innerText;
linkEl.innerHTML = `<span><span class="tn-icon bx bx-download"></span>${utils.escapeHtml(title)}</span>`;
return;
}
const noteId = href.split("/").at(-1);
const note = noteId ? getNote(noteId) : undefined;