test
npm install react-native-code-highlighter!GitHub




Code/Syntax highlighter for React Native. Inspired by react-native-syntax-highlighter, using react-syntax-highlighter
#### NPM
``sh`
npm install react-native-code-highlighter react-syntax-highlighter
#### Yarn
`sh`
yarn add react-native-code-highlighter react-syntax-highlighter
> Additional for typescript
#### NPM
`sh`
npm install --save-dev @types/react-syntax-highlighter
#### Yarn
`sh`
yarn add -D @types/react-syntax-highlighter
| Prop | Description | Type | Optional |
| ------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | -------- |
| hljsStyle | Highlight.js style imported from react-syntax-highlighter/dist/esm/styles/hljs | { [key: string]: React.CSSProperties } | false |color
| textStyle | Style for the text text components. Note: property will be overridden | StyleProp | true |horizontal
| scrollViewProps | Props for the underlying scroll view. is ignored | ScrollViewProps | true |containerStyle
| containerStyle | Deprecated. for the underlying ScrollView. Use scrollViewProps.contentContainerStyle instead | StyleProp | true |language
| react-syntax-highlighter Props | Props supported by react-syntax-highlighter. i.e. | | |
`tsx
import React from "react";
import { StyleSheet } from "react-native";
import CodeHighlighter from "react-native-code-highlighter";
import { atomOneDarkReasonable } from "react-syntax-highlighter/dist/esm/styles/hljs";
const CODE_STR = var hello = "world";
export default function HighlightComponent() {
return (
containerStyle={styles.codeContainer}
textStyle={styles.text}
language="typescript"
>
{CODE_STR}
);
}
const styles = StyleSheet.create({
codeContainer: {
padding: 16,
minWidth: "100%",
},
text: {
fontSize: 16,
},
});
``
> CodeSandbox: https://codesandbox.io/s/react-native-code-highligher-knfsyx?file=/src/App.js
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
---
- create-react-native-library
- react-syntax-highlighter
- trim-newlines
- css-to-react-native