Skip to content

Commit d65d74b

Browse files
authored
Merge pull request #35 from RonasIT/PRD-2152-incorrect-chat-block-color-fix
PRD-2152: CodeBlock background color fix
2 parents cb4f617 + b9a85f8 commit d65d74b

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

libs/mobile/shared/features/markdown-view/src/lib/component.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import markdownItMath from 'markdown-it-math/no-default-renderer';
33
import { colorScheme } from 'nativewind';
44
import React, { PropsWithChildren, ReactElement, ReactNode, useCallback, useMemo } from 'react';
55
import { Linking } from 'react-native';
6+
import FitImage from 'react-native-fit-image';
67
import Markdown, { ASTNode, MarkdownProps, RenderRules } from 'react-native-markdown-display';
78
import { CitationPrefix } from '@open-webui-react-native/mobile/chat/features/use-citations';
89
import { CodeBlock } from '@open-webui-react-native/mobile/shared/ui/code-block';
@@ -39,7 +40,7 @@ export function AppMarkdownView({
3940
onCitationPress,
4041
isContentReady,
4142
textColor: elementTextColor,
42-
...restProps
43+
children,
4344
}: AppMarkdownViewProps): ReactElement {
4445
const { isDarkColorScheme } = useColorScheme();
4546
const textColor = elementTextColor || (isDarkColorScheme ? colors.darkTextPrimary : colors.textPrimary);
@@ -53,7 +54,7 @@ export function AppMarkdownView({
5354
) => {
5455
return (
5556
<CodeBlock
56-
fenceStyle={[inheritedStyles, styles.fence]}
57+
fenceStyle={[inheritedStyles, markdownStyles.fence]}
5758
key={`code-block-${node.key}`}
5859
sourceInfo={node.sourceInfo}
5960
content={node.content}
@@ -209,6 +210,18 @@ export function AppMarkdownView({
209210
</AppText>
210211
),
211212
table: renderTable,
213+
//NOTE: A props object containing a "key" prop is being spread into JSX error fix
214+
image: (node: ASTNode, children, parent, styles) => {
215+
const uri = node.attributes?.src;
216+
217+
if (!uri) return null;
218+
219+
return <FitImage
220+
key={`image-${node.key}`}
221+
source={{ uri }}
222+
style={styles.image}
223+
resizeMode='contain' />;
224+
},
212225
};
213226
}, [fence, onCitationPress, isContentReady, renderTable]);
214227

@@ -220,9 +233,9 @@ export function AppMarkdownView({
220233
code_inline: { backgroundColor: isDarkColorScheme ? colors.gray700 : colors.gray75 },
221234
}}
222235
rules={markdownRules}
223-
{...restProps}
224-
markdownit={markdownItInstance}
225-
/>
236+
markdownit={markdownItInstance}>
237+
{children}
238+
</Markdown>
226239
);
227240
}
228241

@@ -289,4 +302,9 @@ const markdownStyles = createStyles({
289302
backgroundColor: colorScheme.get() === 'dark' ? colors.gray700 : colors.gray75,
290303
textDecorationLine: 'none',
291304
},
305+
fence: {
306+
backgroundColor: colorScheme.get() === 'dark' ? colors.gray700 : colors.gray75,
307+
borderRadius: 8,
308+
padding: 12,
309+
},
292310
});

0 commit comments

Comments
 (0)