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, 14:30 UTC
fix(web,mobile): markdown previews no longer show YAML frontmatter as a giant heading (#25804)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 27, 2026 at 01:22 UTC
f81c4cd79f9afb4beef535d5453c280b831caf31
6 files changed
+50
-3
apps/mobile/src/features/files/FileMarkdownPreview.tsx
+2
-1
@@ -2,6 +2,7 @@ import { settlePromise } from "@t3tools/client-runtime/state/runtime";
2
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
3
import { resolveMobileMarkdownMediaSource } from "../../lib/markdownMediaSource";
4
import { getBrowseDirectoryPath } from "@t3tools/client-runtime/state/projects";
5
+import { maskMarkdownFrontmatter } from "@t3tools/shared/markdownFrontmatter";
6
import { useState } from "react";
7
import { StackActions, useNavigation } from "@react-navigation/native";
8
import { RefreshControl, ScrollView, View } from "react-native";
@@ -235,7 +236,7 @@ export function FileMarkdownPreview(props: {
236
>
237
<View className="mx-auto w-full max-w-[760px]">
238
<SelectableMarkdownText
238
- markdown={props.markdown}
239
+ markdown={maskMarkdownFrontmatter(props.markdown)}
240
fileEmbedLabel={(href) =>
241
markdownFileEmbedLabel(
242
href,
apps/web/src/components/files/AttachmentFilePreview.tsx
+6
-1
@@ -16,6 +16,7 @@ import { lazy, Suspense, useEffect, useRef, useState } from "react";
16
17
import { useAssetUrlRefresh } from "~/assets/assetUrls";
18
import ChatMarkdown from "~/components/ChatMarkdown";
19
+import { maskMarkdownFrontmatter } from "@t3tools/shared/markdownFrontmatter";
20
import { MorphIcon } from "~/components/MorphIcon";
21
import { ScrollArea } from "~/components/ui/scroll-area";
22
import { toastManager } from "~/components/ui/toast";
@@ -281,7 +282,11 @@ export function AttachmentFilePreview(props: {
282
</Suspense>
283
) : kind === "markdown" && rendered ? (
284
<ScrollArea className="min-h-0 flex-1">
284
- <ChatMarkdown text={content.text} cwd={undefined} className="mx-auto max-w-4xl px-6 py-5" />
285
+ <ChatMarkdown
286
+ text={maskMarkdownFrontmatter(content.text)}
287
+ cwd={undefined}
288
+ className="mx-auto max-w-4xl px-6 py-5"
289
+ />
290
</ScrollArea>
291
) : (
292
<ReadOnlySourcePreview name={props.name} text={content.text} />
apps/web/src/components/files/FileMarkdownPreview.tsx
+2
-1
@@ -2,6 +2,7 @@ import type { ScopedThreadRef } from "@t3tools/contracts";
2
3
import ChatMarkdown from "~/components/ChatMarkdown";
4
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
5
+import { maskMarkdownFrontmatter } from "@t3tools/shared/markdownFrontmatter";
6
7
export function FileMarkdownPreview(props: {
8
readonly cwd: string;
@@ -24,7 +25,7 @@ export function FileMarkdownPreview(props: {
25
26
return (
27
<ChatMarkdown
27
- text={props.text}
28
+ text={maskMarkdownFrontmatter(props.text)}
29
cwd={props.cwd}
30
imageBaseDir={imageBaseDir}
31
threadRef={props.threadRef}
packages/shared/package.json
+4
@@ -447,6 +447,10 @@
447
"types": "./src/markdownGithubAlerts.ts",
448
"import": "./src/markdownGithubAlerts.ts"
449
},
450
+ "./markdownFrontmatter": {
451
+ "types": "./src/markdownFrontmatter.ts",
452
+ "import": "./src/markdownFrontmatter.ts"
453
+ },
454
"./markdownListIndentation": {
455
"types": "./src/markdownListIndentation.ts",
456
"import": "./src/markdownListIndentation.ts"
packages/shared/src/markdownFrontmatter.test.ts
new
+25
@@ -0,0 +1,25 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+
3
+import { maskMarkdownFrontmatter } from "./markdownFrontmatter.ts";
4
+
5
+describe("maskMarkdownFrontmatter", () => {
6
+ it("blanks leading frontmatter without moving later offsets", () => {
7
+ const markdown = "---\r\nname: skill\r\n---\r\n# Skill\n- [ ] item\n";
8
+ const masked = maskMarkdownFrontmatter(markdown);
9
+
10
+ expect(masked).toBe(" \r\n \r\n \r\n# Skill\n- [ ] item\n");
11
+ expect(masked.indexOf("[ ]")).toBe(markdown.indexOf("[ ]"));
12
+ });
13
+
14
+ it("handles a byte order mark, CR line endings, and a ... closing fence", () => {
15
+ expect(maskMarkdownFrontmatter("\uFEFF---\na: 1\n---\n# Body")).toBe(" \n \n \n# Body");
16
+ expect(maskMarkdownFrontmatter("---\ra: 1\r...\r# Body")).toBe(" \r \r \r# Body");
17
+ expect(maskMarkdownFrontmatter("---\n---\n# Body")).toBe(" \n \n# Body");
18
+ });
19
+
20
+ it("leaves unterminated or non-leading fences alone", () => {
21
+ expect(maskMarkdownFrontmatter("---\na: 1\n")).toBe("---\na: 1\n");
22
+ expect(maskMarkdownFrontmatter("# A\n---\nb\n---\n")).toBe("# A\n---\nb\n---\n");
23
+ expect(maskMarkdownFrontmatter("---\na: 1\n----\n")).toBe("---\na: 1\n----\n");
24
+ });
25
+});
packages/shared/src/markdownFrontmatter.ts
new
+11
@@ -0,0 +1,11 @@
1
+const LEADING_FRONTMATTER =
2
+ /^\uFEFF?---[ \t]*(?:\r\n|\r|\n)(?:[\s\S]*?(?:\r\n|\r|\n))?(?:---|\.\.\.)[ \t]*(?=\r\n|\r|\n|$)/;
3
+
4
+/**
5
+ * Blanks a leading YAML frontmatter block so rendered previews skip it instead
6
+ * of showing a rule and a setext heading. Masked characters become spaces and
7
+ * line breaks stay, so source offsets (task checkbox edits) stay valid.
8
+ */
9
+export function maskMarkdownFrontmatter(markdown: string): string {
10
+ return markdown.replace(LEADING_FRONTMATTER, (block) => block.replace(/[^\r\n]/g, " "));
11
+}