-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarkdown.tsx
58 lines (49 loc) · 1.34 KB
/
Markdown.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { ReactNode, Fragment } from "react"
import { Text, ScrollView } from "react-native"
import type { TextStyle } from "react-native"
import { Renderer, useMarkdown } from "react-native-marked"
import type { RendererInterface } from "react-native-marked"
import { Heading, Paragraph, Stack } from "tamagui"
class CustomRenderer extends Renderer implements RendererInterface {
constructor() {
super()
}
heading(
text: string | ReactNode[],
styles?: TextStyle,
depth?: number
): ReactNode {
return (
<Heading key={this.getKey()} style={styles}>
{text}
</Heading>
)
}
text(text: string | ReactNode[], styles?: TextStyle): ReactNode {
return (
<Paragraph key={this.getKey()} style={styles}>
{text}
</Paragraph>
)
}
codespan(text: string, _styles?: TextStyle): ReactNode {
return (
<Text key={this.getKey()} style={{ backgroundColor: "#ff0000" }}>
{text}
</Text>
)
}
}
const renderer = new CustomRenderer()
const Markdown = () => {
const elements = useMarkdown("## Heading2", { renderer })
return (
<Stack borderWidth="$1" borderColor="red">
{elements.map((element, index) => {
console.log(element)
return <Fragment key={`demo_${index}`}>{element}</Fragment>
})}
</Stack>
)
}
export default Markdown