From 30768e6a4d4486e2a38fa342c72b8accefb92f2b Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 13 Dec 2017 15:35:19 -0200 Subject: [PATCH 1/5] Custom rules enabled --- index.js | 11 +++++++++-- package.json | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index bb3eefe..53c6b67 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,10 @@ class Markdown extends Component { constructor(props) { super(props); - const rules = SimpleMarkdown.defaultRules; + const 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'; @@ -170,6 +173,10 @@ class Markdown extends Component { } } + renderCustom(node) { + return React.Children.only(node.props.children); + } + renderLink(node, key) { const {styles} = this.state; @@ -238,7 +245,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 +264,7 @@ 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 '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 +} From 9fa34558350fa1bdccb1dc2e228b041ad2ca783d Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 13 Dec 2017 15:46:44 -0200 Subject: [PATCH 2/5] Code enabled --- index.js | 13 +++++++++++++ styles.js | 3 +++ 2 files changed, 16 insertions(+) diff --git a/index.js b/index.js index 53c6b67..71ad3f3 100644 --- a/index.js +++ b/index.js @@ -238,6 +238,18 @@ class Markdown extends Component { } } + 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; @@ -264,6 +276,7 @@ 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); 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/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' } }; From ed1afe45f870524f6c23a4ca1df97770f0979c74 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 13 Dec 2017 16:10:53 -0200 Subject: [PATCH 3/5] Refactor --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 71ad3f3..eb1ca6e 100644 --- a/index.js +++ b/index.js @@ -173,10 +173,6 @@ class Markdown extends Component { } } - renderCustom(node) { - return React.Children.only(node.props.children); - } - renderLink(node, key) { const {styles} = this.state; @@ -238,6 +234,10 @@ class Markdown extends Component { } } + renderCustom(node) { + return React.Children.only(node.props.children); + } + renderCode(node, key, extras) { const {styles} = this.state; @@ -276,7 +276,7 @@ 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); + 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; From 600a79faf4fdac2c21cfebeb01f96b997674dabe Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 15 Feb 2018 17:50:40 -0200 Subject: [PATCH 4/5] renderInline prop --- index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index eb1ca6e..9837a9d 100644 --- a/index.js +++ b/index.js @@ -22,20 +22,22 @@ 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); @@ -219,8 +221,15 @@ class Markdown extends Component { ); } else { + const additionalProps = {} + if (this.props.renderInline) { + additionalProps = { + ellipsizeMode:'tail', + numberOfLines: 1, + } + } return( - + {nodes} ); From 1cf9d2bd9683576af0bb09d80ffa286c4dc03f82 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 27 Apr 2018 15:57:18 -0300 Subject: [PATCH 5/5] TouchableOpacity inside of Text element causes crash on Android --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 9837a9d..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, @@ -186,9 +185,9 @@ class Markdown extends Component { } return( - Linking.openURL(node.props.href).catch(() => {})}> + Linking.openURL(node.props.href).catch(() => {})}> {children} - + ); }