Skip to content

Commit

Permalink
fix: apply font to MarkdownView
Browse files Browse the repository at this point in the history
  • Loading branch information
farmerpaul committed Feb 28, 2025
1 parent c6fb1d7 commit a556fa0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/shared/ui/MarkdownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Markdown, {
MarkdownIt,
} from 'react-native-markdown-display';

import { defaultFont, elFont } from '../config/theme/tamagui.config';
import { useFontLanguage } from '../hooks/useFontLanguage';
import { preprocessImageLinks } from '../lib/markdown/rules';

const markdownItInstance = MarkdownIt({
Expand All @@ -21,7 +23,7 @@ const markdownItInstance = MarkdownIt({

type Props = {
content: string;
markdownStyle?: StyleSheet.NamedStyles<any>;
markdownStyle: StyleSheet.NamedStyles<any>;
rules?: RenderRules;
};

Expand All @@ -32,12 +34,22 @@ declare module 'react-native-markdown-display' {
}

export const MarkdownView: FC<Props> = ({ content, markdownStyle, rules }) => {
const fontLanguage = useFontLanguage();

const style: StyleSheet.NamedStyles<any> = {
...markdownStyle,
text: {
...markdownStyle.text,
fontFamily: fontLanguage === 'el' ? elFont.family : defaultFont.family,
},
};

return (
<Markdown
rules={rules}
mergeStyle
markdownit={markdownItInstance}
style={markdownStyle}
style={style}
>
{preprocessImageLinks(content)}
</Markdown>
Expand Down

0 comments on commit a556fa0

Please sign in to comment.