From 58d21d48116856957822df8b747c6b7bd116f071 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 13:11:02 -0500 Subject: [PATCH 01/46] Don't wrap text unexpectedly for block items Fixes #18 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b933978..3f43b2e 100644 --- a/index.js +++ b/index.js @@ -207,7 +207,7 @@ class Markdown extends Component { else { return ( - {nodes} + {nodes} ); } From 52a63e06ea5b220d24d76f472bb4a6c995068ea7 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 13:22:33 -0500 Subject: [PATCH 02/46] 1.2.0-fix.0 --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6a85cfd..1a49b50 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { - "name": "react-native-easy-markdown", - "version": "1.2.0", + "name": "@titanvest/react-native-easy-markdown", + "version": "1.2.0-fix.0", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "index.js", - "repository": "https://github.com/lappalj4/react-native-easy-markdown", + "repository": "https://github.com/TitanInvest/react-native-easy-markdown", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, @@ -22,4 +22,4 @@ "peerDependencies": { "react-native": "*" } -} \ No newline at end of file +} From ecdb1dd696f20ea6136ec85fedd3f4a9cd92dbd1 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 13:27:30 -0500 Subject: [PATCH 03/46] remove classProperties that don't work with create-react-app --- Utils.js | 11 +++++------ index.js | 34 +++++++++++++++++----------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Utils.js b/Utils.js index 1842e02..a07aa1b 100644 --- a/Utils.js +++ b/Utils.js @@ -1,7 +1,6 @@ -class Utils { - +const Utils = { // Was causing crashes with RN > 0.55, removed for now. - // + // // static isTextOnly(nodes) { // if (nodes.length) { // for (let i = 0; i < nodes.length; i++) { @@ -18,7 +17,7 @@ class Utils { // return true; // } - static concatStyles(extras, newStyle) { + concatStyles: concatStyles(extras, newStyle) { let newExtras; if (extras) { newExtras = JSON.parse(JSON.stringify(extras)); @@ -34,9 +33,9 @@ class Utils { }; } return newExtras; - } + }, - static logDebug(nodeTree, level = 0) { + logDebug: logDebug(nodeTree, level = 0) { for (let i = 0; i < nodeTree.length; i++) { const node = nodeTree[i]; diff --git a/index.js b/index.js index 3f43b2e..98945d6 100644 --- a/index.js +++ b/index.js @@ -14,23 +14,6 @@ import styles from './styles'; import Utils from './Utils'; class Markdown extends Component { - static propTypes = { - debug: PropTypes.bool, - parseInline: PropTypes.bool, - markdownStyles: PropTypes.object, - useDefaultStyles: PropTypes.bool, - renderImage: PropTypes.func, - renderLink: PropTypes.func, - renderListBullet: PropTypes.func, - } - - static defaultProps = { - debug: false, - useDefaultStyles: true, - parseInline: false, - markdownStyles: {} - } - constructor(props) { super(props); @@ -268,4 +251,21 @@ class Markdown extends Component { } } +Markdown.propTypes = { + debug: PropTypes.bool, + parseInline: PropTypes.bool, + markdownStyles: PropTypes.object, + useDefaultStyles: PropTypes.bool, + renderImage: PropTypes.func, + renderLink: PropTypes.func, + renderListBullet: PropTypes.func, +}; + +Markdown.defaultProps = { + debug: false, + useDefaultStyles: true, + parseInline: false, + markdownStyles: {} +}; + export default Markdown; From 951e048798de3b824eece36f1dd8c48f7c8a67df Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 13:27:45 -0500 Subject: [PATCH 04/46] 1.2.0-fix.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a49b50..da7b784 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.0", + "version": "1.2.0-fix.1", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 4e877afafc0c09a5d97588b9e24ac8b9621e5fba Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 13:42:05 -0500 Subject: [PATCH 05/46] babel build --- .babelrc | 3 +++ .gitignore | 1 + .npmignore | 2 ++ Utils.js | 4 ++-- entry.js | 2 ++ package.json | 6 ++++++ 6 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .babelrc create mode 100644 .npmignore create mode 100644 entry.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..a9ce136 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["react-native"] +} diff --git a/.gitignore b/.gitignore index fd4f2b0..77058f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules .DS_Store +/lib diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..fd4f2b0 --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +node_modules +.DS_Store diff --git a/Utils.js b/Utils.js index a07aa1b..709f2f7 100644 --- a/Utils.js +++ b/Utils.js @@ -17,7 +17,7 @@ const Utils = { // return true; // } - concatStyles: concatStyles(extras, newStyle) { + concatStyles: function concatStyles(extras, newStyle) { let newExtras; if (extras) { newExtras = JSON.parse(JSON.stringify(extras)); @@ -35,7 +35,7 @@ const Utils = { return newExtras; }, - logDebug: logDebug(nodeTree, level = 0) { + logDebug: function logDebug(nodeTree, level = 0) { for (let i = 0; i < nodeTree.length; i++) { const node = nodeTree[i]; diff --git a/entry.js b/entry.js new file mode 100644 index 0000000..ba6f941 --- /dev/null +++ b/entry.js @@ -0,0 +1,2 @@ +module.exports = require('./lib/index.js'); + diff --git a/package.json b/package.json index da7b784..73af199 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "main": "index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", "scripts": { + "build": "babel index.js styles.js Utils.js -d lib", + "prepare": "npm run build", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [ @@ -21,5 +23,9 @@ }, "peerDependencies": { "react-native": "*" + }, + "devDependencies": { + "babel-cli": "^6.26.0", + "babel-preset-react-native": "^4.0.1" } } From 499a70a69653d87b2bc7352e35bd7a38a29fe3b5 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 13:42:22 -0500 Subject: [PATCH 06/46] 1.2.0-fix.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 73af199..b24bc2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.1", + "version": "1.2.0-fix.2", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From e7e54ebc0ec98958d56ee9b8e68f47ad99ba3941 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 13:44:40 -0500 Subject: [PATCH 07/46] missing entry --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b24bc2b..e4fd913 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@titanvest/react-native-easy-markdown", "version": "1.2.0-fix.2", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", - "main": "index.js", + "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", "scripts": { "build": "babel index.js styles.js Utils.js -d lib", From f7d0bc009440c1b074a0f630760c941884be970e Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 13:44:50 -0500 Subject: [PATCH 08/46] 1.2.0-fix.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e4fd913..685c3f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.2", + "version": "1.2.0-fix.3", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From b03ccd0ebe9d06d2729e28319f738811a1ec698a Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 14:15:10 -0500 Subject: [PATCH 09/46] apply style to text in renderBlock --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 98945d6..b6feba0 100644 --- a/index.js +++ b/index.js @@ -190,7 +190,7 @@ class Markdown extends Component { else { return ( - {nodes} + {nodes} ); } From 15ebf6a53ae4f99206d7ccb8eceaf1b4bd3d41ae Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 14:15:31 -0500 Subject: [PATCH 10/46] 1.2.0-fix.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 685c3f8..796a4c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.3", + "version": "1.2.0-fix.4", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 77499da8fabc44e111a9962d737b8b0e774d90ca Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 14:47:10 -0500 Subject: [PATCH 11/46] make textAlign work by wrapping --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index b6feba0..8806715 100644 --- a/index.js +++ b/index.js @@ -190,7 +190,10 @@ class Markdown extends Component { else { return ( - {nodes} + {/* If you want to set a text only property, like textAlign, we must wrap it twice.*/} + + {nodes} + ); } From b2137072a1e59f175447b2154a3d80bf0794f3e8 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 4 Dec 2018 14:47:24 -0500 Subject: [PATCH 12/46] 1.2.0-fix.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 796a4c3..daee6a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.4", + "version": "1.2.0-fix.5", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From f69f0671148d77fd6fff72bae0776928a3f3c61b Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Mon, 14 Jan 2019 15:49:33 -0500 Subject: [PATCH 13/46] remove styling on block --- index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/index.js b/index.js index 8806715..f2d93fa 100644 --- a/index.js +++ b/index.js @@ -190,10 +190,7 @@ class Markdown extends Component { else { return ( - {/* If you want to set a text only property, like textAlign, we must wrap it twice.*/} - - {nodes} - + {nodes} ); } From de321945e5a89266c355ca63936b0c297d05d191 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Mon, 14 Jan 2019 15:49:47 -0500 Subject: [PATCH 14/46] 1.2.0-fix.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index daee6a1..14ba2f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.5", + "version": "1.2.0-fix.6", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 3077a915cc3b362a2994dd8b32366984d073d0b0 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Mon, 14 Jan 2019 16:55:40 -0500 Subject: [PATCH 15/46] bring back isTextOnly to fix block quotes --- Utils.js | 30 ++++++++++++++---------------- index.js | 25 ++++++++++++++++--------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/Utils.js b/Utils.js index 709f2f7..1277c5c 100644 --- a/Utils.js +++ b/Utils.js @@ -1,21 +1,19 @@ const Utils = { - // Was causing crashes with RN > 0.55, removed for now. - // - // static isTextOnly(nodes) { - // if (nodes.length) { - // for (let i = 0; i < nodes.length; i++) { - // if (nodes[i] && - // nodes[i].hasOwnProperty('type') && - // nodes[i].type.hasOwnProperty('displayName')) { - // if (nodes[i].type.displayName !== 'Text') { - // return false; - // } - // } + isTextOnly(nodes) { + if (nodes.length) { + for (let i = 0; i < nodes.length; i++) { + if (nodes[i] && + nodes[i].hasOwnProperty('type') && + nodes[i].type.hasOwnProperty('displayName')) { + if (nodes[i].type.displayName !== 'Text') { + return false; + } + } - // } - // } - // return true; - // } + } + } + return true; + }, concatStyles: function concatStyles(extras, newStyle) { let newExtras; diff --git a/index.js b/index.js index f2d93fa..4f7cc75 100644 --- a/index.js +++ b/index.js @@ -179,15 +179,22 @@ class Markdown extends Component { } const nodes = this.renderNodes(node.props.children, key, extras); - if (isBlockQuote) { - style.push(styles.blockQuote) - return ( - - {nodes} - - ); - } - else { + if (Utils.isTextOnly(nodes)) { + if (isBlockQuote) { + style.push(styles.blockQuote) + return( + + {nodes} + + ); + } else { + return( + + {nodes} + + ); + } + } else { return ( {nodes} From b493143662047ef766507ce3827e0afd6376e69f Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Mon, 14 Jan 2019 16:55:44 -0500 Subject: [PATCH 16/46] 1.2.0-fix.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 14ba2f9..56dd662 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.6", + "version": "1.2.0-fix.7", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From eb68c642396f086450c0c8f3cdde4e695fe19edc Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Mon, 14 Jan 2019 17:06:18 -0500 Subject: [PATCH 17/46] bring back correct text wrapping --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4f7cc75..cdc06e8 100644 --- a/index.js +++ b/index.js @@ -190,7 +190,11 @@ class Markdown extends Component { } else { return( - {nodes} + + + {nodes} + + ); } From 32e56b398e6bce506266cd7fb6889cafc92b20d6 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Mon, 14 Jan 2019 17:06:34 -0500 Subject: [PATCH 18/46] 1.2.0-fix.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 56dd662..1d1d011 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.7", + "version": "1.2.0-fix.8", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From e7cf39d4ac33cd2735fc53dafe74babbf73e4cc9 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 15 Jan 2019 18:06:34 -0500 Subject: [PATCH 19/46] flexShrink listItem --- styles.js | 1 + 1 file changed, 1 insertion(+) diff --git a/styles.js b/styles.js index 6b841af..1c9ea38 100644 --- a/styles.js +++ b/styles.js @@ -79,6 +79,7 @@ const defaultStyles = { }, listItemContent: { flexDirection: 'row', + flexShrink: 1, justifyContent: 'flex-start', alignItems: 'flex-start', }, From e1b198cb3cf1f5c004bfcd7322b0418c0675c7b3 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 15 Jan 2019 18:06:49 -0500 Subject: [PATCH 20/46] 1.2.0-fix.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1d1d011..db66725 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.8", + "version": "1.2.0-fix.9", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 51c6373aad3221bcc905d1be5d7d14b0a6281551 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 15 Jan 2019 23:25:07 -0500 Subject: [PATCH 21/46] log isTextOnly --- Utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Utils.js b/Utils.js index 1277c5c..ee78d9e 100644 --- a/Utils.js +++ b/Utils.js @@ -1,5 +1,6 @@ const Utils = { isTextOnly(nodes) { + console.log('isTextOnly', nodes); if (nodes.length) { for (let i = 0; i < nodes.length; i++) { if (nodes[i] && From 169290e572f0c7dbf097efb444e3a9c0c0a45962 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 15 Jan 2019 23:25:26 -0500 Subject: [PATCH 22/46] 1.2.0-fix.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index db66725..e6f908b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.9", + "version": "1.2.0-fix.10", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From da6617481527ed611f44c572142ca436a0ecac39 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Wed, 16 Jan 2019 00:00:35 -0500 Subject: [PATCH 23/46] more logging --- Utils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Utils.js b/Utils.js index ee78d9e..a8995fd 100644 --- a/Utils.js +++ b/Utils.js @@ -7,12 +7,14 @@ const Utils = { nodes[i].hasOwnProperty('type') && nodes[i].type.hasOwnProperty('displayName')) { if (nodes[i].type.displayName !== 'Text') { + console.log('returning false', nodes[i].type.displayName) return false; } } } } + console.log('returning true'); return true; }, From 66f1e46f7b8b37d178fbca4e994ce2bd992d0e5c Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Wed, 16 Jan 2019 00:01:46 -0500 Subject: [PATCH 24/46] 1.2.0-fix.11 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e6f908b..486e3f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.10", + "version": "1.2.0-fix.11", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From e7a1b80cbdb8bfa3e947b6408e826b5f04ebebf1 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Wed, 16 Jan 2019 00:20:37 -0500 Subject: [PATCH 25/46] Revert "bring back isTextOnly to fix block quotes" This reverts commit 3077a915cc3b362a2994dd8b32366984d073d0b0. --- index.js | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index cdc06e8..f2d93fa 100644 --- a/index.js +++ b/index.js @@ -179,26 +179,15 @@ class Markdown extends Component { } const nodes = this.renderNodes(node.props.children, key, extras); - if (Utils.isTextOnly(nodes)) { - if (isBlockQuote) { - style.push(styles.blockQuote) - return( - - {nodes} - - ); - } else { - return( - - - - {nodes} - - - - ); - } - } else { + if (isBlockQuote) { + style.push(styles.blockQuote) + return ( + + {nodes} + + ); + } + else { return ( {nodes} From 42c5630d29401bea8dac81fd4296344c7c29ce50 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Wed, 16 Jan 2019 00:22:18 -0500 Subject: [PATCH 26/46] 1.2.0-fix.12 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 486e3f9..f49c860 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.11", + "version": "1.2.0-fix.12", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 5fb552b452404684bcfd52a7bdd16d2a73c01d63 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Thu, 17 Jan 2019 11:17:23 -0500 Subject: [PATCH 27/46] wrap text blocks in Text, not View --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index f2d93fa..56bfe34 100644 --- a/index.js +++ b/index.js @@ -187,6 +187,11 @@ class Markdown extends Component { ); } + else if (Utils.isTextOnly(nodes)) { + return ( + {nodes} + ); + } else { return ( From 81cfcc8af2c22af30281a3d1ec7d2e66ec11aeda Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Thu, 17 Jan 2019 11:17:40 -0500 Subject: [PATCH 28/46] 1.2.0-fix.13 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f49c860..1f6ec8f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.12", + "version": "1.2.0-fix.13", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 309feb8f86e9518896f0513e164ee57ad277317a Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Thu, 17 Jan 2019 11:44:57 -0500 Subject: [PATCH 29/46] better isTextOnly check --- Utils.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Utils.js b/Utils.js index a8995fd..96065bd 100644 --- a/Utils.js +++ b/Utils.js @@ -1,20 +1,30 @@ const Utils = { isTextOnly(nodes) { - console.log('isTextOnly', nodes); - if (nodes.length) { - for (let i = 0; i < nodes.length; i++) { - if (nodes[i] && - nodes[i].hasOwnProperty('type') && - nodes[i].type.hasOwnProperty('displayName')) { - if (nodes[i].type.displayName !== 'Text') { - console.log('returning false', nodes[i].type.displayName) + try { + if (nodes.length) { + for (let i = 0; i < nodes.length; i++) { + if (nodes[i] && + typeof nodes[i].hasOwnProperty === 'function' && + nodes[i].hasOwnProperty('type') && + typeof nodes[i].type.hasOwnProperty === 'function' && + ( + nodes[i].type.hasOwnProperty('displayName') || + nodes[i].type.hasOwnProperty('name') + ) + ) { + if (nodes[i].type.displayName !== 'Text' && nodes[i].type.name !== 'Text') { + return false; + } + } else { return false; } } - } + } catch(e) { + return false; } - console.log('returning true'); + + // It's a miracle, I guess we're text only return true; }, From 5217d4851164e0e4458fd778baf19c6ce4fb591e Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Thu, 17 Jan 2019 11:45:12 -0500 Subject: [PATCH 30/46] 1.2.0-fix.14 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f6ec8f..c9a105f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.13", + "version": "1.2.0-fix.14", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 14cb2333ad14784f6bc30a8cf24a9869971d6d37 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Thu, 17 Jan 2019 12:02:46 -0500 Subject: [PATCH 31/46] fix wrapping on list items with text only --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 56bfe34..233aaa2 100644 --- a/index.js +++ b/index.js @@ -113,12 +113,14 @@ class Markdown extends Component { let children = this.renderNodes(node.props.children, key, extras); + const ItemWrapper = Utils.isTextOnly(children) ? Text : View; + return ( {this.props.renderListBullet ? this.props.renderListBullet(extras.ordered, index) : this.renderListBullet(extras.ordered, index)} - + {children} - + ); } From 878edd7bbe8acb886b678fa211660d546eb07aa5 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Thu, 17 Jan 2019 12:03:05 -0500 Subject: [PATCH 32/46] 1.2.0-fix.15 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c9a105f..08d91e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.14", + "version": "1.2.0-fix.15", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 6f7b6ba8ff254fdf01c5a8430cc22dab0ede5dd6 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 22 Jan 2019 13:38:24 -0500 Subject: [PATCH 33/46] use SafeWrapper for renderLink --- index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 233aaa2..5eb4376 100644 --- a/index.js +++ b/index.js @@ -113,14 +113,14 @@ class Markdown extends Component { let children = this.renderNodes(node.props.children, key, extras); - const ItemWrapper = Utils.isTextOnly(children) ? Text : View; + const SafeWrapper = Utils.isTextOnly(children) ? Text : View; return ( {this.props.renderListBullet ? this.props.renderListBullet(extras.ordered, index) : this.renderListBullet(extras.ordered, index)} - + {children} - + ); } @@ -154,10 +154,12 @@ class Markdown extends Component { return this.props.renderLink(node.props.href, node.props.title, children); } + const SafeWrapper = Utils.isTextOnly(children) ? Text : TouchableOpacity; + return ( - Linking.openURL(node.props.href).catch(() => { })}> + Linking.openURL(node.props.href).catch(() => { })}> {children} - + ); } From 98b8ea8ec66f0c8785adb36598baf3fa747f785e Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 22 Jan 2019 13:40:07 -0500 Subject: [PATCH 34/46] 1.2.0-fix.16 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 08d91e3..1f01b18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.15", + "version": "1.2.0-fix.16", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 4f7e81d351c8b3f85fcdf380fdde5d859498508d Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Tue, 19 Feb 2019 15:32:03 -0500 Subject: [PATCH 35/46] v1.3.0 --- README.md | 8 ++++++-- package.json | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d7f51f4..ca05dd0 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ You can supply the component with your own ```markdownStyles``` prop to override | imageWrapper | `` | Wrapper around images, for easier layouting | | image | `` | Image component | -See [default styles](https://github.com/lappalj4/react-native-easy-markdown/blob/master/styles.js) for reference. +See [default styles](https://github.com/TitanInvest/react-native-easy-markdown/blob/master/styles.js) for reference. # Caveats @@ -123,6 +123,10 @@ See [default styles](https://github.com/lappalj4/react-native-easy-markdown/blob # Change Log +**1.3.0** +* Fix text wrapping unexpectedly +* Bring back Utils.isTextOnly to prevent Views nested in Texts +* New maintainer: TitanInvest **1.2.0** * Fixed crash on RN > 0.55 (#17) @@ -178,7 +182,7 @@ Possible features to implement: # License (MIT) -Copyright 2017 Juuso Lappalainen +Copyright 2019 Juuso Lappalainen, Zach Ivester Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/package.json b/package.json index 1f01b18..6c00c0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@titanvest/react-native-easy-markdown", - "version": "1.2.0-fix.16", + "name": "react-native-easy-markdown", + "version": "1.3.0", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", @@ -16,7 +16,10 @@ "parse", "parser" ], - "author": "Juuso Lappalainen", + "contributors": [ + "Juuso Lappalainen", + "Zach Ivester " + ], "license": "MIT", "dependencies": { "simple-markdown": "^0.1.1" From eb9259b1f9d6366c9346bbc5b5c088eec73cc49f Mon Sep 17 00:00:00 2001 From: David Ewen Date: Wed, 3 Jul 2019 03:34:52 +0800 Subject: [PATCH 36/46] Fix unexpected default style mutation Fix issue where when useDefaultStyles is true and markdownStyles is also supplied the defaultStyles are permanently mutated for all instances of the component. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 5eb4376..b7d09d2 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ class Markdown extends Component { const outputResult = this.reactOutput(parseTree); const defaultStyles = this.props.useDefaultStyles && styles ? styles : {}; - const _styles = StyleSheet.create(Object.assign(defaultStyles, this.props.markdownStyles)); + const _styles = StyleSheet.create(Object.assign({}, defaultStyles, this.props.markdownStyles)); this.state = { syntaxTree: outputResult, From 40da078a26fda544057eb45e0eb9527f36475f4a Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Mon, 19 Aug 2019 17:18:41 -0400 Subject: [PATCH 37/46] simple-markdown@0.4.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6c00c0b..320512e 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ ], "license": "MIT", "dependencies": { - "simple-markdown": "^0.1.1" + "simple-markdown": "^0.4.4" }, "peerDependencies": { "react-native": "*" From c0a836522d0bffa626cff5af6c550c8d987c9b46 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Mon, 19 Aug 2019 17:19:32 -0400 Subject: [PATCH 38/46] 1.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 320512e..1d23e40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-easy-markdown", - "version": "1.3.0", + "version": "1.4.0", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 844fe139143edfd5c8fae0daf740253568d62d72 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Mon, 19 Aug 2019 17:23:31 -0400 Subject: [PATCH 39/46] 1.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1d23e40..51ff838 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-easy-markdown", - "version": "1.4.0", + "version": "1.4.1", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 61c193c92f486f3045de3d5ff26367dbf2b38c79 Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Wed, 21 Aug 2019 11:45:08 -0400 Subject: [PATCH 40/46] update README change log --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index ca05dd0..7ae0fe1 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,12 @@ See [default styles](https://github.com/TitanInvest/react-native-easy-markdown/b # Change Log +**1.4.1** +* Fix an unexpected mutation of default styles when specifying `markdownStyles` + +**1.4.0** +* Update simple-markdown dependency to `0.4.4` for XSS vulnerability + **1.3.0** * Fix text wrapping unexpectedly * Bring back Utils.isTextOnly to prevent Views nested in Texts From a19393a00d3b4de923ecb3f6fa96917cd03379e2 Mon Sep 17 00:00:00 2001 From: Jasper Haggenburg Date: Wed, 25 Sep 2019 23:32:57 +0200 Subject: [PATCH 41/46] Add typescript definitions (#4) * Add typescript definitions * Use proper return type on render props * Export prop types --- index.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..ae2f396 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,38 @@ +import React from "react"; +import { StyleProp, TextStyle, ViewProps, ViewStyle } from "react-native"; + +export interface IProps { + debug?: boolean; + parseInline?: boolean; + useDefaultStyles?: boolean; + renderImage?: (src: string, alt: string, title: string) => React.ReactNode; + renderLink?: (href: string, title: string, children: React.ReactNode) => React.ReactNode; + renderListBullet?: (ordered: boolean, index: number) => React.ReactNode; + markdownStyles?: { + block?: StyleProp; + blockQuote?: StyleProp; + del?: StyleProp; + em?: StyleProp; + h1?: StyleProp; + h2?: StyleProp; + h3?: StyleProp; + h4?: StyleProp; + h5?: StyleProp; + h6?: StyleProp; + hr?: StyleProp; + image?: StyleProp; + imageWrapper?: StyleProp; + link?: StyleProp; + linkWrapper?: StyleProp; + list?: StyleProp; + listItem?: StyleProp; + listItemBullet?: StyleProp; + listItemContent?: StyleProp; + listItemNumber?: StyleProp; + strong?: StyleProp; + text?: StyleProp; + u?: StyleProp; + }; +} + +export default class Markdown extends React.Component {} From 571710209a7168a0e48fb678e5f82d70391af45f Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Wed, 25 Sep 2019 17:34:06 -0400 Subject: [PATCH 42/46] 1.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 51ff838..c1aaecf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-easy-markdown", - "version": "1.4.1", + "version": "1.5.0", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 9ee2f64e8567a8ed576ce1fd73f567f37f9f4b4c Mon Sep 17 00:00:00 2001 From: Zach Ivester Date: Wed, 25 Sep 2019 17:35:07 -0400 Subject: [PATCH 43/46] update README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7ae0fe1..81313f9 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,9 @@ See [default styles](https://github.com/TitanInvest/react-native-easy-markdown/b # Change Log +**1.5.0** +* Add typescript definitions + **1.4.1** * Fix an unexpected mutation of default styles when specifying `markdownStyles` From dcc76798984e2f4269d6cd9cecafaa78367daa4a Mon Sep 17 00:00:00 2001 From: Chris Rizzo Date: Wed, 26 Feb 2020 13:35:40 -0500 Subject: [PATCH 44/46] 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c1aaecf..487f039 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-easy-markdown", - "version": "1.5.0", + "version": "2.0.0", "description": "Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.", "main": "lib/index.js", "repository": "https://github.com/TitanInvest/react-native-easy-markdown", From 81e81160a1d56815baf28d2f04d2e03b19eba034 Mon Sep 17 00:00:00 2001 From: Chris Rizzo Date: Wed, 26 Feb 2020 13:36:05 -0500 Subject: [PATCH 45/46] Add support for code markdown, add optional custom renderer functions --- README.md | 84 +++++++++++++++++++++++++++++++++--------- index.d.ts | 38 ------------------- index.js | 105 ++++++++++++++++++++++++++++++++++++++--------------- styles.js | 4 ++ 4 files changed, 147 insertions(+), 84 deletions(-) delete mode 100644 index.d.ts diff --git a/README.md b/README.md index 81313f9..bb7e937 100644 --- a/README.md +++ b/README.md @@ -63,30 +63,77 @@ render() { | `style` | Style for the `````` component | object | {} | | `renderImage` | Custom renderer for images | function | none | | `renderLink` | Custom renderer for links | function | none | -| `renderListBullet` | Custom rendered for list bullets | function | none | +| `renderListBullet` | Custom renderer for list bullets | function | none | +| `renderLine` | Custom renderer for Line | function | none | +| `renderList` | Custom renderer for list | function | none | +| `renderListItem` | Custom renderer for list item | function | none | +| `renderBlockQuote` | Custom renderer for Block Quote | function | none | +| `renderBlockText` | Custom renderer for Block Text | function | none | +| `renderBlock` | Custom renderer for Block | function | none | +| `renderText` | Custom renderer for various types of text | function | none | -If you need more control over how some of the components are rendered, you may provide the custom renderers outlined above like so: +If you need more control over how some of the components are rendered, you may provide the custom renderers outlined above like so. + +Beware, these functions are experimental in nature and may not work well for all use cases. These are barebones functions that give you the needed information from markdown and allow you to choose what to render. + +In all cases, the 'children' argument refers to markdown nodes that have already been converted to JSX.Elements through the default or custom renderers. + +If using custom renders, no style logic is applied. You may opt in to any custom renderers by passing functions that match the below signatures, and it not present, `` will refer to your custom/default styles and the default legacy implementation. ``` -renderImage(src, alt, title) { - return( - - ); -} +renderImage(src, alt, title, key) + +renderLink(href, title, children, key) + +// `ordered: true` signifies this is the bullet point of a list ordered by index +renderListBullet(ordered, index) -renderLink(href, title, children) { - return( - console.log("Opening link: " + href)}> - {children} - - ); +// Responsible for the containing List element, children are the elements that represent the list items +renderList(ordered, children, key) + +// Line break custom renderer +renderLine(key) + +// example usage +renderListItem(index, ordered, children, key) { + if (!ordered) { + return { children }; + } else { + return { children } + } } -renderListBullet(ordered, index) { - return( - - ); +renderText(textType, children: React.Element | React.ReactElement[], , key) { + // Possible textTypes: h1, h2, h3, h4, h5, h6, strong, del, em, u + switch (textType) { + case 'h1' + case 'h2' + case 'h3' + case 'h4' + case 'h5' + case 'h6': + return {children} + case 'strong': + return {children} + case 'del': + return {children} + case 'em': + return {children} + case 'u: + return {children} + default: + return {children} + } } + +// Responsible for rendering the block container as well as the children +renderBlockQuote(children, key) + +// Responsible for rendering the block container as well as the children +renderBlock(children, key) + +// Responsible for any block that will only contain text elements below +renderBlockText(children, key) ``` Notice the `children` parameter passed to `renderLink`, which contains whatever children would otherwise be rendered within the link. In the default implementation, those children will be rendered within a `` but this gives you the possibility to provide your own touchable component. @@ -123,6 +170,9 @@ See [default styles](https://github.com/TitanInvest/react-native-easy-markdown/b # Change Log +**2.0.0** +* Add ability to pass custom renderers for various markdown components. + **1.5.0** * Add typescript definitions diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index ae2f396..0000000 --- a/index.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -import React from "react"; -import { StyleProp, TextStyle, ViewProps, ViewStyle } from "react-native"; - -export interface IProps { - debug?: boolean; - parseInline?: boolean; - useDefaultStyles?: boolean; - renderImage?: (src: string, alt: string, title: string) => React.ReactNode; - renderLink?: (href: string, title: string, children: React.ReactNode) => React.ReactNode; - renderListBullet?: (ordered: boolean, index: number) => React.ReactNode; - markdownStyles?: { - block?: StyleProp; - blockQuote?: StyleProp; - del?: StyleProp; - em?: StyleProp; - h1?: StyleProp; - h2?: StyleProp; - h3?: StyleProp; - h4?: StyleProp; - h5?: StyleProp; - h6?: StyleProp; - hr?: StyleProp; - image?: StyleProp; - imageWrapper?: StyleProp; - link?: StyleProp; - linkWrapper?: StyleProp; - list?: StyleProp; - listItem?: StyleProp; - listItemBullet?: StyleProp; - listItemContent?: StyleProp; - listItemNumber?: StyleProp; - strong?: StyleProp; - text?: StyleProp; - u?: StyleProp; - }; -} - -export default class Markdown extends React.Component {} diff --git a/index.js b/index.js index b7d09d2..dc39dd6 100644 --- a/index.js +++ b/index.js @@ -63,7 +63,7 @@ class Markdown extends Component { const { styles } = this.state; if (this.props.renderImage) { - return this.props.renderImage(node.props.src, node.props.alt, node.props.title); + return this.props.renderImage(node.props.src, node.props.alt, node.props.title, key); } return ( @@ -76,6 +76,10 @@ class Markdown extends Component { renderLine(node, key) { const { styles } = this.state; + if (this.props.renderLine) { + return this.props.renderLine(key); + } + return ( ); @@ -85,6 +89,11 @@ class Markdown extends Component { const { styles } = this.state; + if (this.props.renderList) { + const children = this.renderNodes(node.props.children, key, { ordered }); + return this.props.renderList(ordered, children, key); + } + return ( {this.renderNodes(node.props.children, key, { ordered })} @@ -113,6 +122,11 @@ class Markdown extends Component { let children = this.renderNodes(node.props.children, key, extras); + if (this.props.renderListItem) { + const { ordered } = extras; + return this.props.renderListItem(index, ordered, children, key); + } + const SafeWrapper = Utils.isTextOnly(children) ? Text : View; return ( @@ -125,23 +139,39 @@ class Markdown extends Component { ); } - renderText(node, key, extras) { - + renderText(node, key, extras, textType) { const { styles } = this.state; let style = (extras && extras.style) ? [styles.text].concat(extras.style) : styles.text; - if (node.props) { - return ( - - {this.renderNodes(node.props.children, key, extras)} - - ); + let text = null; + + if (node && node.props && node.props.children) { + if (Array.isArray(node.props.children)) { + + // If we have a custom renderer, we convert the child nodes to elements and pass to the consumer + let children = this.renderNodes(node.props.children, key, extras); + if (this.props.renderText) { + // Text is an array of JSX.Elements + return this.props.renderText(textType, children, key); + } else { + return ({ children }); + } + } else { + // Text is a string value + text = node.props.children; + } } else { - return ( - {node} - ); + // Node should just be a text string + text = node; + } + + if (this.props.renderText) { + return this.props.renderText(textType, text, key); } + return ( + {text} + ); } renderLink(node, key) { @@ -151,7 +181,7 @@ class Markdown extends Component { let children = this.renderNodes(node.props.children, key, extras); if (this.props.renderLink) { - return this.props.renderLink(node.props.href, node.props.title, children); + return this.props.renderLink(node.props.href, node.props.title, children, key); } const SafeWrapper = Utils.isTextOnly(children) ? Text : TouchableOpacity; @@ -181,25 +211,33 @@ class Markdown extends Component { */ delete extras.blockQuote; } - const nodes = this.renderNodes(node.props.children, key, extras); + const children = this.renderNodes(node.props.children, key, extras); if (isBlockQuote) { - style.push(styles.blockQuote) + if (this.props.renderBlockQuote) { + return this.props.renderBlockQuote(children, key) + } return ( - {nodes} + {children} ); } - else if (Utils.isTextOnly(nodes)) { + else if (Utils.isTextOnly(children)) { + if (this.props.renderBlockText) { + return this.props.renderBlockText(children, key) + } return ( - {nodes} + {children} ); } else { + if (this.props.renderBlock) { + return this.props.renderBlock(children, key); + } return ( - {nodes} + {children} ); } @@ -212,14 +250,15 @@ class Markdown extends Component { const { styles } = this.state; + if (this.props.debug) console.log('rendering node: ', node); 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)); - case 'h3': return this.renderText(node, key, Utils.concatStyles(extras, styles.h3)); - case 'h4': return this.renderText(node, key, Utils.concatStyles(extras, styles.h4)) - case 'h5': return this.renderText(node, key, Utils.concatStyles(extras, styles.h5)); - case 'h6': return this.renderText(node, key, Utils.concatStyles(extras, styles.h6)); + case 'h1': return this.renderText(node, key, Utils.concatStyles(extras, styles.h1), 'h1' ); + case 'h2': return this.renderText(node, key, Utils.concatStyles(extras, styles.h2), 'h2' ); + case 'h3': return this.renderText(node, key, Utils.concatStyles(extras, styles.h3), 'h3' ); + case 'h4': return this.renderText(node, key, Utils.concatStyles(extras, styles.h4), 'h4' ); + case 'h5': return this.renderText(node, key, Utils.concatStyles(extras, styles.h5), 'h5' ); + case 'h6': return this.renderText(node, key, Utils.concatStyles(extras, styles.h6), 'h6' ); case 'hr': return this.renderLine(node, key); case 'div': return this.renderBlock(node, key, extras); case 'ul': return this.renderList(node, key, false); @@ -227,10 +266,11 @@ class Markdown extends Component { case 'li': return this.renderListItem(node, key, index, extras); case 'a': return this.renderLink(node, key); case 'img': return this.renderImage(node, key); - case 'strong': return this.renderText(node, key, Utils.concatStyles(extras, styles.strong)); - case 'del': return this.renderText(node, key, Utils.concatStyles(extras, styles.del)); - 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 'strong': return this.renderText(node, key, Utils.concatStyles(extras, styles.strong), 'strong'); + case 'del': return this.renderText(node, key, Utils.concatStyles(extras, styles.del), 'del'); + case 'em': return this.renderText(node, key, Utils.concatStyles(extras, styles.em), 'em'); + case 'u': return this.renderText(node, key, Utils.concatStyles(extras, styles.u), 'u'); + case 'code': return this.renderText(node, key, Utils.concatStyles(extras, styles.code), 'code'); case 'blockquote': return this.renderBlockQuote(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; @@ -268,6 +308,13 @@ Markdown.propTypes = { renderImage: PropTypes.func, renderLink: PropTypes.func, renderListBullet: PropTypes.func, + renderLine: PropTypes.func, + renderList: PropTypes.func, + renderListItem: PropTypes.func, + renderText: PropTypes.func, + renderBlockQuote: PropTypes.func, + renderBlockText: PropTypes.func, + renderBlock: PropTypes.func, }; Markdown.defaultProps = { diff --git a/styles.js b/styles.js index 1c9ea38..1a20be2 100644 --- a/styles.js +++ b/styles.js @@ -46,6 +46,10 @@ const defaultStyles = { backgroundColor: '#333333', marginVertical: 8, }, + code: { + backgroundColor: '#333333', + color: 'orange', + }, text: { alignSelf: 'flex-start' }, From a52524e973839636a1bb25ba07a8d3ab15a16fcb Mon Sep 17 00:00:00 2001 From: vjain143 Date: Tue, 14 Jul 2020 22:27:39 +0100 Subject: [PATCH 46/46] Updated simple-markdown version to 0.7.2 to fix vulnerabilities --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 487f039..5db7f4e 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ ], "license": "MIT", "dependencies": { - "simple-markdown": "^0.4.4" + "simple-markdown": "^0.7.2" }, "peerDependencies": { "react-native": "*"