Skip to content

Commit d758c29

Browse files
authored
feat: optimize inline latex display for android (#11)
1 parent bdc1a2b commit d758c29

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

react-native/src/chat/component/CustomMarkdownRenderer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ const customStyles = StyleSheet.create({
575575
width: '100%',
576576
},
577577
inlineMath: {
578-
marginTop: 2,
578+
marginTop: Platform.OS === 'android' ? 0 : 2,
579+
maxHeight: 24,
579580
},
580581
displayMathView: {
581582
marginVertical: 0,

react-native/src/chat/component/CustomTokenizer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CustomToken, MarkedLexer, MarkedTokenizer } from 'react-native-marked';
2+
import { Platform } from 'react-native';
23

34
export class CustomTokenizer extends MarkedTokenizer<CustomToken> {
45
list(this: MarkedTokenizer<CustomToken>, src: string) {
@@ -27,8 +28,12 @@ export class CustomTokenizer extends MarkedTokenizer<CustomToken> {
2728
const match = inlineMatch || displayMatch;
2829
if (match && match.length > 1) {
2930
const text = match[1].trim();
30-
const isDisplayMode = !!displayMatch;
31-
31+
let isDisplayMode = !!displayMatch;
32+
if (isDisplayMode && Platform.OS === 'android') {
33+
if (!src.includes('\n\n') && src.includes('\n')) {
34+
isDisplayMode = false;
35+
}
36+
}
3237
const token: CustomToken = {
3338
type: 'custom',
3439
raw: match[0],

0 commit comments

Comments
 (0)