From ac47535272673297158ec3ac24ae226369778a14 Mon Sep 17 00:00:00 2001 From: Morgan Brunot Date: Thu, 13 Oct 2016 14:47:26 +0200 Subject: [PATCH] ability to add own rules --- README.md | 25 ++++++++++++++++++++++++- index.js | 4 +++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cb2e506..2e5e224 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ const MyAwesomeApp = () => { return ( #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@somebody.com) @@ -78,6 +78,29 @@ Example: ``` +### `rules` + +The Markdown will apply its rules by default. However you can pass a `rules` prop to add your own. + +Exemple: + +```js + ( + + ), + }, + }} +> + ![Alt text](/path/to/img.jpg) + +``` + ### Features - `br` (``) diff --git a/index.js b/index.js index ec65a6b..2738351 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ import styles from './styles' type Props = { styles: any, children?: string, + rules: Object, } type DefaultProps = Props & { @@ -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