0.1.2 • Published 3 years ago

@ozymandiasthegreat/react-native-markdown v0.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

npm bundle size npm GitHub issues GitHub GitHub Repo stars

@ozymandiasthegreat/react-native-markdown

Render markdown formatted strings to native components. Uses @expo/html-elements to render semantic elements on the web. Developed and tested with Expo Go

remark /unified is used for parsing. Includes remark-gfm plugin by default, but you can customize parser plugins.

Uses react-native-render-html to display inline HTML as native elements.

Uses react-native-syntax-highlighter to syntax-highlight code blocks.

Screenshots

API

Example

import { atomDark } from "react-syntax-highlighter/styles/prism";
import { Markdown } from "@ozymandiasthegreat/react-native-markdown";

export default function App() {
	return (
		<SafeAreaView style={{ flex: 1 }}>
			<ScrollView>
				<Markdown
					source={{ markdown: "# Heading" }}
					codeStyle={{ theme: atomDark }}
				/>
			</ScrollView>
		</SafeAreaView>
	);
}

Props

Note Style props DO NOT accept StyleSheet's

PropTypeRequiredDefaultValue
sourceobjectyes{ markdown: undefined, ast: undefined }Markdown string to render as { markdown } or remark produced ast as { ast }
styleViewStyleno{ flex: 1, alignSelf: "center", width: 800, padding: 25 }The style for the container element (<Article />)
pStyleTextStyleno{ color: "#212121", fontFamily: fontMap?.normal || "serif", fontSize: 16 }Paragraph style
hStyleTextStyleno{ fontFamily: fontMap?.bold || "sans-serif" }Heading style
hSizeStepnumberno2How much to increase heading font size per level
aStyleTextStyleno{ color: "#4fc3f7", textDecorationLine: "underline" }Anchor (link) style
codeStyleobjectno{ fontFamily: fontMap?.monospace || "monospace", fontSize: (pStyle.fontSize || 16) * 0.95 }Valid props are: { fontFamily?: string, fontSize?: number, theme?: react-syntax-highlighter prism theme }
tableStyleobjectno{ color: color(pStyle.color as string, 0.75), width: "80%", borderWidth: 1, paddingVertical: 5, paddingHorizontal: 10 }Valid props are { color: string, width: string | number, borderWidth: number, paddingVertical: number, paddingHorizontal: number } Note that color here refers to border color. Padding is applied to each cell.
fontMapobjectno{ normal: undefined, bold: undefined, italic: undefined, monospace: undefined }A mapping of font families to use across the document
htmlFallbackFontsobjectnoundefinedA mapping of font families to use in HTML when font is not specified, check react-native-render-html docs for more information, as this prop is passed through as is.