diff --git a/index.js b/index.js
index bb3eefe..a40a37c 100644
--- a/index.js
+++ b/index.js
@@ -1,7 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types'
import {
- TouchableOpacity,
Text,
View,
Image,
@@ -22,19 +21,24 @@ class Markdown extends Component {
renderImage: PropTypes.func,
renderLink: PropTypes.func,
renderListBullet: PropTypes.func,
+ renderInline: PropTypes.bool,
}
static defaultProps = {
debug: false,
useDefaultStyles: true,
parseInline: false,
- markdownStyles: {}
+ markdownStyles: {},
+ renderInline: false
}
constructor(props) {
super(props);
- const rules = SimpleMarkdown.defaultRules;
+ let rules = {
+ ...SimpleMarkdown.defaultRules,
+ ...this.props.rules
+ };
this.parser = SimpleMarkdown.parserFor(rules);
this.reactOutput = SimpleMarkdown.reactFor(SimpleMarkdown.ruleOutput(rules, 'react'));
const blockSource = this.props.children + '\n\n';
@@ -181,9 +185,9 @@ class Markdown extends Component {
}
return(
- Linking.openURL(node.props.href).catch(() => {})}>
+ Linking.openURL(node.props.href).catch(() => {})}>
{children}
-
+
);
}
@@ -216,8 +220,15 @@ class Markdown extends Component {
);
} else {
+ const additionalProps = {}
+ if (this.props.renderInline) {
+ additionalProps = {
+ ellipsizeMode:'tail',
+ numberOfLines: 1,
+ }
+ }
return(
-
+
{nodes}
);
@@ -231,6 +242,22 @@ class Markdown extends Component {
}
}
+ renderCustom(node) {
+ return React.Children.only(node.props.children);
+ }
+
+ renderCode(node, key, extras) {
+ const {styles} = this.state;
+
+ let style = (extras && extras.style) ? [styles.code].concat(extras.style) : styles.code;
+
+ return(
+
+ {node.props.children}
+
+ );
+ }
+
renderNode(node, key, index, extras) {
if (node == null || node == "null" || node == "undefined" || node == "") {
return null;
@@ -238,7 +265,6 @@ class Markdown extends Component {
const {styles} = this.state;
-
switch(node.type) {
case 'h1': return this.renderText(node, key, Utils.concatStyles(extras, styles.h1));
case 'h2': return this.renderText(node, key, Utils.concatStyles(extras, styles.h2));
@@ -258,6 +284,8 @@ class Markdown extends Component {
case 'em': return this.renderText(node, key, Utils.concatStyles(extras, styles.em));
case 'u': return this.renderText(node, key, Utils.concatStyles(extras, styles.u));
case 'blockquote': return this.renderBlockQuote(node, key);
+ case 'code': return this.renderCode(node, key, extras);
+ case 'custom': return this.renderCustom(node, key);
case undefined: return this.renderText(node, key, extras);
default: if (this.props.debug) console.log('Node type '+node.type+' is not supported'); return null;
}
diff --git a/package.json b/package.json
index 82f19dc..52697be 100644
--- a/package.json
+++ b/package.json
@@ -22,4 +22,4 @@
"peerDependencies": {
"react-native": "*"
}
-}
\ No newline at end of file
+}
diff --git a/styles.js b/styles.js
index b2780b2..a7e62c6 100644
--- a/styles.js
+++ b/styles.js
@@ -104,6 +104,9 @@ const defaultStyles = {
flex: 1,
minWidth: 200,
height: 200
+ },
+ code: {
+ backgroundColor: '#cccccc'
}
};