Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions apps/mobile/src/lib/markdownDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,14 @@ function markdownHtmlTags(content: string): RegExpExecArray[] {
codeRanges.push({ start: opening.index, end: closing.index + closing[0].length });
index = closingIndex;
}
return tags.filter(
(tag) => !codeRanges.some((range) => tag.index >= range.start && tag.index < range.end),
);
let codeRangeIndex = 0;
return tags.filter((tag) => {
while (codeRanges[codeRangeIndex] && tag.index >= codeRanges[codeRangeIndex]!.end) {
codeRangeIndex += 1;
}
const range = codeRanges[codeRangeIndex];
return !range || tag.index < range.start;
});
}

/**
Expand Down
22 changes: 22 additions & 0 deletions apps/mobile/src/lib/markdownHtml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,28 @@ describe("HTML in native Markdown", () => {
});
});

it("keeps code literal across many ranges while converting HTML between and after them", () => {
const blocks = Array.from(
{ length: 100 },
(_, index) => `\`<img src="literal-${index}.png">\` <img src="image-${index}.png">`,
);
const expected = Array.from(
{ length: 100 },
(_, index) => `\`<img src="literal-${index}.png">\` ![](<image-${index}.png>)`,
);
expect(markdownHtmlContent(blocks.join("\n") + "<br>after")).toBe(
expected.join("\n") + " \nafter",
);
});

it("keeps tags after an unclosed fence literal even when later inline ranges overlap it", () => {
const content =
'<div>before</div>\n```html\n<img src="one.png">\n`<img src="two.png">`\n<img src="three.png">';
expect(markdownHtmlContent(content)).toBe(
'\n\nbefore\n\n\n```html\n<img src="one.png">\n`<img src="two.png">`\n<img src="three.png">',
);
});

describe("file embeds in native thread and file Markdown", () => {
const input = {
environmentId: EnvironmentId.make("environment-1"),
Expand Down
Loading