diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx
index a6eb2c569..66ceb2395 100644
--- a/gui/src/components/markdown/StyledMarkdownPreview.tsx
+++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx
@@ -296,14 +296,16 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
code: ({ node, ...codeProps }) => {
const content = getCodeChildrenContent(codeProps.children);
- if (content && previousFileContextItemsRef.current) {
+ if (content) {
// Insert file links for matching previous context items
- const ctxItem = previousFileContextItemsRef.current.find((item) =>
- item.uri!.value!.includes(content),
- );
- if (ctxItem) {
- const rif = ctxItemToRifWithContents(ctxItem);
- return ;
+ if (previousFileContextItemsRef.current?.length) {
+ const ctxItem = previousFileContextItemsRef.current.find((item) =>
+ item.uri!.value!.endsWith(content),
+ );
+ if (ctxItem) {
+ const rif = ctxItemToRifWithContents(ctxItem);
+ return ;
+ }
}
// Insert symbols for exact matches