import React from 'react' import { View, Text, ScrollView, StyleSheet } from 'react-native' import { COLORS } from '../constants/Config' interface Props { content: string; style?: object } export default function MarkdownViewer({ content, style }: Props) { const lines = content.split('\n') return ( {lines.map((line, i) => { if (line.startsWith('### ')) return {line.slice(4)} if (line.startsWith('## ')) return {line.slice(3)} if (line.startsWith('# ')) return {line.slice(2)} if (line.startsWith('---')) return if (line.startsWith('> ')) return {line.slice(2)} if (line.startsWith('- ') || line.startsWith('* ')) return {' • '}{renderInline(line.slice(2))} if (/^\d+\. /.test(line)) { const [num, ...rest] = line.split('. ') return {` ${num}. `}{renderInline(rest.join('. '))} } if (line.startsWith('```')) return {line.slice(3)} if (line === '') return return {renderInline(line)} })} ) } function renderInline(text: string): string { return text .replace(/\*\*(.+?)\*\*/g, '$1') .replace(/`(.+?)`/g, '$1') .replace(/_(.+?)_/g, '$1') } const s = StyleSheet.create({ wrap: { flex: 1 }, h1: { fontSize: 20, fontWeight: '800', color: COLORS.text, marginVertical: 8 }, h2: { fontSize: 17, fontWeight: '700', color: COLORS.text, marginVertical: 6 }, h3: { fontSize: 15, fontWeight: '700', color: COLORS.primary, marginVertical: 4 }, body: { fontSize: 14, color: COLORS.text, lineHeight: 22, marginVertical: 1 }, li: { fontSize: 14, color: COLORS.text, lineHeight: 22 }, hr: { height: 1, backgroundColor: COLORS.border, marginVertical: 8 }, blockquote: { borderLeftWidth: 3, borderLeftColor: COLORS.accent, paddingLeft: 10, marginVertical: 4 }, bqText: { fontSize: 13, color: COLORS.muted, fontStyle: 'italic' }, codeBlock: { backgroundColor: '#1E293B', borderRadius: 6, padding: 10, marginVertical: 6 }, code: { fontSize: 12, color: '#E2E8F0', fontFamily: 'monospace' }, })