@devries-cameron20 / t3code Mirror · read-only / commits / b5644426bf
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 04:30 UTC

perf(mobile): assemble HTML replacements in one pass (#25278)

Alex Southwell committed Nov 5, 2026 at 18:31 UTC b5644426bf49d3ac20ab2c38b5c0bf5e0a939490
2 files changed +30 -3
apps/mobile/src/lib/markdownDocument.ts
+1 -3
@@ -279,9 +279,7 @@ export function markdownWithHtml(markdown: string): string {
279 }
280 };
281 visit(parser.parse(markdown), false, false);
282 - for (const edit of edits.reverse())
283 - markdown = markdown.slice(0, edit.start) + edit.content + markdown.slice(edit.end);
284 - return markdown;
282 + return applyMarkdownEdits(markdown, edits);
283 }
284
285 // Start only at the beginning of a backtick run to avoid retrying every suffix.
apps/mobile/src/lib/markdownHtml.test.ts
+29
@@ -116,6 +116,35 @@ describe("HTML in native Markdown", () => {
116 it("keeps anchor text unlinked for unsafe hrefs", () => {
117 expect(markdownWithHtml('Run <a href="javascript:alert(1)">this</a> now')).toBe("Run this now");
118 });
119 +
120 + it("keeps anchor labels and escaped bangs intact across nested formatting and table cells", () => {
121 + const markdown =
122 + '> **!<a href="https://x.test">[one]</a>** and <span>tail</span>\n\n| A |\n| - |\n| !<a href="https://x.test">x[y]</a><br><img src="x.png"> |';
123 + expect(markdownWithHtml(markdown)).toBe(
124 + "> **\\![\\[one\\]](<https://x.test>)** and tail\n\n| A |\n| - |\n| \\![x\\[y\\]](<https://x.test>) ![](<x.png>) |",
125 + );
126 + expect(
127 + markdownWithHtml(
128 + String.raw`Before \!<a href="https://x.test">escaped</a> \\!<a href="mailto:a@b">even</a>`,
129 + ),
130 + ).toBe(String.raw`Before \![escaped](<https://x.test>) \\\![even](<mailto:a@b>)`);
131 + });
132 +
133 + it("converts separated HTML without changing code examples or an unfinished tag", () => {
134 + const literal = '`<br>`\n\n```html\n<img src="literal.png">\n```\n\n<broken';
135 + expect(markdownWithHtml(literal)).toBe(literal);
136 + const rows = Array.from(
137 + { length: 100 },
138 + (_, index) => `row ${index} <span>text</span><br>!<a href="https://x.test/${index}">go</a>`,
139 + );
140 + const expected = Array.from(
141 + { length: 100 },
142 + (_, index) => `row ${index} text \n\\![go](<https://x.test/${index}>)`,
143 + );
144 + expect(markdownWithHtml(rows.join("\n\n") + "\n\n" + literal)).toBe(
145 + expected.join("\n\n") + "\n\n" + literal,
146 + );
147 + });
148 });
149
150 describe("file embeds in native thread and file Markdown", () => {