Skip to content

Commit

Permalink
ability to add own rules
Browse files Browse the repository at this point in the history
  • Loading branch information
oziks committed Oct 13, 2016
1 parent f0603d3 commit ac47535
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const MyAwesomeApp = () => {
return (
<Markdown styles={styles}>
#Markdown in react-native is so cool!

You can **emphasize** what you want, or just _suggest it_ 😏…

You can even [link your website](http://charlesmangwa.surge.sh) or if you prefer: [email sombedy](mailto:[email protected])
Expand Down Expand Up @@ -78,6 +78,29 @@ Example:
</Markdown>
```
### `rules`
The Markdown will apply its rules by default. However you can pass a `rules` prop to add your own.
Exemple:
```js
<Markdown
rules={{
image: {
react: (node, output, state) => (
<MyOwnImageComponent
key={state.key}
source={{ uri: node.target }}
/>
),
},
}}
>
![Alt text](/path/to/img.jpg)
</Markdown>
```
### Features
- `br` (`<Text>`)
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import styles from './styles'
type Props = {
styles: any,
children?: string,
rules: Object,
}

type DefaultProps = Props & {
Expand All @@ -23,11 +24,12 @@ class Markdown extends Component {
static defaultProps: DefaultProps = {
styles: styles,
children: '',
rules: {},
}

renderContent = (children: string) => {
const mergedStyles = Object.assign(styles, this.props.styles)
const rules = _.merge({}, SimpleMarkdown.defaultRules, initialRules(mergedStyles))
const rules = _.merge({}, SimpleMarkdown.defaultRules, initialRules(mergedStyles), this.props.rules)
const child = Array.isArray(this.props.children)
? this.props.children.join('')
: this.props.children
Expand Down

0 comments on commit ac47535

Please sign in to comment.