|
1 | 1 | import { BlockContent, DefinitionContent, List, ListItem } from "mdast"; |
2 | | -import { Fragment, ReactNode } from "react"; |
| 2 | +import { Fragment, ReactNode, useMemo } from "react"; |
3 | 3 | import { Text, View } from "react-native"; |
4 | 4 |
|
5 | 5 | import { useMarkdownContext } from "../context"; |
@@ -29,20 +29,30 @@ export const ListItemRenderer = ({ |
29 | 29 | const { renderers, styles } = useMarkdownContext(); |
30 | 30 | const { BlockContentRenderer, DefinitionContentRenderer } = renderers; |
31 | 31 |
|
32 | | - const markerStyle = mergeStyles(styles.paragraph, { |
33 | | - marginRight: 5, |
34 | | - }); |
35 | | - |
36 | 32 | const list = parent?.type === "list" ? (parent as List) : null; |
37 | 33 | const itemNumber = (list?.start ?? 1) + (index ?? 0); |
38 | 34 |
|
| 35 | + const markerStyle = useMemo(() => { |
| 36 | + const defaultStyle = mergeStyles(styles.paragraph, { |
| 37 | + fontWeight: "500", |
| 38 | + }); |
| 39 | + const firstItem = node.children[0]; |
| 40 | + if (!firstItem) return defaultStyle; |
| 41 | + if (firstItem.type === "heading") { |
| 42 | + return styles.heading?.(firstItem.depth); |
| 43 | + } |
| 44 | + return defaultStyle; |
| 45 | + }, [styles, node]); |
| 46 | + |
39 | 47 | return ( |
40 | 48 | <View style={{ flexDirection: "row" }}> |
41 | | - {list?.ordered ? ( |
42 | | - <Text style={markerStyle}>{itemNumber}.</Text> |
43 | | - ) : ( |
44 | | - <Text style={markerStyle}>•</Text> |
45 | | - )} |
| 49 | + <View style={{ marginRight: 5 }}> |
| 50 | + {list?.ordered ? ( |
| 51 | + <Text style={markerStyle}>{itemNumber}.</Text> |
| 52 | + ) : ( |
| 53 | + <Text style={markerStyle}>•</Text> |
| 54 | + )} |
| 55 | + </View> |
46 | 56 | <View style={styles.listItem}> |
47 | 57 | {node.children.map((child, idx) => ( |
48 | 58 | <Fragment key={idx}> |
|
0 commit comments