Fix iOS markdown image rendering

This commit is contained in:
Mohamed Boudra
2026-06-05 14:11:17 +07:00
parent e961ceef98
commit 45cca8a406
7 changed files with 76 additions and 6 deletions
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";
import { markdownNodeContainsType } from "./markdown-ast";
describe("markdownNodeContainsType", () => {
it("matches the node itself", () => {
expect(markdownNodeContainsType({ type: "image", children: [] }, "image")).toBe(true);
});
it("matches descendants", () => {
const paragraph = {
type: "paragraph",
children: [
{ type: "text", children: [] },
{
type: "link",
children: [{ type: "image", children: [] }],
},
],
};
expect(markdownNodeContainsType(paragraph, "image")).toBe(true);
});
it("returns false when the type is absent", () => {
const paragraph = {
type: "paragraph",
children: [
{ type: "text", children: [] },
{ type: "strong", children: [{ type: "text", children: [] }] },
],
};
expect(markdownNodeContainsType(paragraph, "image")).toBe(false);
});
});
+12
View File
@@ -0,0 +1,12 @@
export interface MarkdownAstNodeWithChildren {
type: string;
children: MarkdownAstNodeWithChildren[];
}
export function markdownNodeContainsType(node: MarkdownAstNodeWithChildren, type: string): boolean {
if (node.type === type) {
return true;
}
return node.children.some((child) => markdownNodeContainsType(child, type));
}