Skip to content

Commit

Permalink
feat: optimize inline latex display for android (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu-xiaowei authored Dec 30, 2024
1 parent bdc1a2b commit d758c29
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion react-native/src/chat/component/CustomMarkdownRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ const customStyles = StyleSheet.create({
width: '100%',
},
inlineMath: {
marginTop: 2,
marginTop: Platform.OS === 'android' ? 0 : 2,
maxHeight: 24,
},
displayMathView: {
marginVertical: 0,
Expand Down
9 changes: 7 additions & 2 deletions react-native/src/chat/component/CustomTokenizer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CustomToken, MarkedLexer, MarkedTokenizer } from 'react-native-marked';
import { Platform } from 'react-native';

export class CustomTokenizer extends MarkedTokenizer<CustomToken> {
list(this: MarkedTokenizer<CustomToken>, src: string) {
Expand Down Expand Up @@ -27,8 +28,12 @@ export class CustomTokenizer extends MarkedTokenizer<CustomToken> {
const match = inlineMatch || displayMatch;
if (match && match.length > 1) {
const text = match[1].trim();
const isDisplayMode = !!displayMatch;

let isDisplayMode = !!displayMatch;
if (isDisplayMode && Platform.OS === 'android') {
if (!src.includes('\n\n') && src.includes('\n')) {
isDisplayMode = false;
}
}
const token: CustomToken = {
type: 'custom',
raw: match[0],
Expand Down

0 comments on commit d758c29

Please sign in to comment.