Skip to content

Commit c819e02

Browse files
committed
fix(mobile): preserve unknown remote image embeds
1 parent 27dde81 commit c819e02

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎apps/mobile/src/lib/markdownHtml.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ describe("file embeds in native thread and file Markdown", () => {
130130
const converted = markdownWithFileEmbeds(markdownWithHtml(source), (url, standalone) =>
131131
markdownFileEmbedLabel(url, input, standalone),
132132
);
133-
expect(assets(converted.markdown)).toMatchObject([
134-
{ type: "link", url: href, children: [{ type: "text", value: name }] },
135-
]);
136-
expect(converted.fileHrefs.has(href)).toBe(true);
133+
const image = href.startsWith("https:") && /\.(unknown|tf|prisma|astro|zig)$/.test(name);
134+
if (image) expect(converted.markdown).toBe(markdownWithHtml(source));
135+
else
136+
expect(assets(converted.markdown)).toMatchObject([
137+
{ type: "link", url: href, children: [{ type: "text", value: name }] },
138+
]);
139+
expect(converted.fileHrefs.has(href)).toBe(!image);
137140
const preview = resolveMarkdownMediaPreview(href, { ...input, imageEmbed: true });
138141
if (
139142
!href.startsWith("https:") &&

‎apps/mobile/src/lib/markdownMedia.test.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe("resolveMarkdownMediaPreview", () => {
164164
["report.docx", "document"],
165165
["report.xlsx", "document"],
166166
["report.pptx", "document"],
167-
["report.unknown", "document"],
167+
["report.unknown", "image"],
168168
])("preserves direct signed embeds: %s", (name, kind) => {
169169
const href = `https://cdn.example.com/${name}?signature=a%2fb`;
170170
expect(resolveMarkdownMediaPreview(href, { ...input, imageEmbed: true })).toMatchObject({
@@ -177,11 +177,19 @@ describe("resolveMarkdownMediaPreview", () => {
177177
"https://docs.example.com/guide.html",
178178
"https://example.com/index.php?topic=files",
179179
"https://example.com/report.unknown",
180+
"https://example.com/main.tf",
181+
"https://example.com/schema.prisma",
182+
"https://example.com/chart.php?id=1",
183+
"http://example.com/chart.php?id=1",
184+
"//example.com/chart.php?id=1",
185+
"https://example.com/chart?format=png",
186+
"http://example.com/chart?format=png",
187+
"//example.com/chart?format=png",
180188
])("keeps ordinary remote links in the browser: %s", (href) => {
181189
expect(resolveMarkdownMediaPreview(href, input)).toBeNull();
182190
expect(resolveMarkdownMediaPreview(href, { ...input, imageEmbed: true })).toMatchObject({
183-
kind: "document",
184-
source: { uri: href },
191+
kind: "image",
192+
source: { uri: href.startsWith("//") ? `https:${href}` : href },
185193
});
186194
});
187195

‎apps/mobile/src/lib/markdownMedia.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export function resolveMarkdownMediaPreview(
6666
isFile &&
6767
mediaMimeTypeFromExtension(extension) === null &&
6868
(classified._tag !== "Direct" ||
69-
input.imageEmbed ||
7069
Object.hasOwn(DOCUMENT_MIME_TYPES, extension) ||
7170
audioMimeTypeFromExtension(extension) !== null)
7271
) {

0 commit comments

Comments
 (0)