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
5 changes: 5 additions & 0 deletions apps/mobile/src/features/threads/ThreadFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: {
readonly onUseArtifactTemplate?: ((template: CodexArtifactTemplate) => void) | undefined;
readonly renderImage: MarkdownImageRenderer;
readonly skills?: ReadonlyArray<SelectableMarkdownSkill> | undefined;
readonly streaming?: boolean | undefined;
}) {
const models = useModelMentions(props.environmentId, props.markdown);
const liveMarkdown = useLiveThreadLinkLabels(props.markdown, props.environmentId);
Expand All @@ -1166,6 +1167,7 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: {
renderImage={props.renderImage}
skills={props.skills}
models={models}
streaming={props.streaming}
/>
);
});
Expand All @@ -1179,6 +1181,7 @@ function AssistantMarkdownBlocks(props: {
readonly renderImage: MarkdownImageRenderer;
readonly skills?: ReadonlyArray<SelectableMarkdownSkill> | undefined;
readonly models: ReturnType<typeof useModelMentions>;
readonly streaming?: boolean | undefined;
}) {
const blocks = useMemo(
() =>
Expand Down Expand Up @@ -1222,6 +1225,7 @@ function AssistantMarkdownBlocks(props: {
textStyle={props.markdownStyles.nativeTextStyle}
{...props.linkHandlers}
renderImage={props.renderImage}
streaming={props.streaming}
/>
);
});
Expand Down Expand Up @@ -2232,6 +2236,7 @@ function renderFeedEntry(
onUseArtifactTemplate={props.onUseArtifactTemplate}
renderImage={props.renderMarkdownImage}
skills={props.skills}
streaming={message.streaming}
/>
</MarkdownImageAvailableWidthContext>
) : null}
Expand Down
43 changes: 31 additions & 12 deletions apps/mobile/src/lib/markdownDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,25 +285,35 @@ export function markdownWithHtml(markdown: string): string {
// Start only at the beginning of a backtick run to avoid retrying every suffix.
const INLINE_CODE_SPAN = /(?<!`)`+([^`\r\n]+)`+/g;

export function markdownWithInlineFileLinks(markdown: string, fileLink: RegExp): string {
return transformNativeMarkdown(markdown, fileLink, false);
/**
* File links are rewritten only when some inline-code span of the document looks like a path.
* That is a decision about the whole document, so a caller converting it in pieces passes it on.
*/
export function markdownMayLinkFiles(markdown: string, fileLink: RegExp): boolean {
for (const [, code] of markdown.matchAll(INLINE_CODE_SPAN)) {
if (fileLink.test(code!.trim())) return true;
}
return false;
}

export function markdownWithInlineFileLinks(
markdown: string,
fileLink: RegExp,
linkFiles?: boolean,
): string {
return transformNativeMarkdown(markdown, fileLink, false, linkFiles);
}

function transformNativeMarkdown(
markdown: string,
fileLink: RegExp | undefined,
tableBreaks: boolean,
linkFilesOverride?: boolean,
): string {
const breakTables = tableBreaks && mayHaveTableUnderText(markdown);
let linkFiles = false;
if (fileLink) {
for (const [, code] of markdown.matchAll(INLINE_CODE_SPAN)) {
if (fileLink.test(code!.trim())) {
linkFiles = true;
break;
}
}
}
const linkFiles = fileLink
? (linkFilesOverride ?? markdownMayLinkFiles(markdown, fileLink))
: false;
if (!linkFiles && !breakTables) return markdown;
const edits: MarkdownEdit[] = [];
const fileEdits: MarkdownEdit[] = [];
Expand Down Expand Up @@ -439,7 +449,16 @@ export function parseMarkdownDocument(markdown: string): Root {
}

export function markdownForNativeRendering(markdown: string, fileLink: RegExp): string {
return transformNativeMarkdown(markdownForNativeParsing(markdown), fileLink, true);
return markdownRenderParsed(markdownForNativeParsing(markdown), fileLink);
}

/** What `markdownForNativeRendering` does after `markdownForNativeParsing`. */
export function markdownRenderParsed(
parsed: string,
fileLink: RegExp,
linkFiles?: boolean,
): string {
return transformNativeMarkdown(parsed, fileLink, true, linkFiles);
}

/** Native media slots only cover standalone images; nested file embeds must become links. */
Expand Down
Loading
Loading