Skip to content

Commit 4f3363b

Browse files
committed
bump(*): bump version (@1.0.60-rc.0)
- Add mailto support - Add link support - @linonetwo - Add listItemText support - @chandlervdw - Add video support - Add GIF support - Add url support
1 parent 330a1dd commit 4f3363b

File tree

4 files changed

+41
-23
lines changed

4 files changed

+41
-23
lines changed

README.md

+17-6
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@ import Markdown from 'react-native-simple-markdown'
2121
const MyAwesomeApp = () => {
2222
return (
2323
<Markdown styles={styles}>
24-
#Who is the best dev in town?
24+
#Markdown in react-native is so cool!
2525
{'\n\n'}
26-
Probably **the one** reading this lines 😏…
26+
You can **emphasize** what you want, or just _suggest it_ 😏…
27+
{'\n\n'}
28+
You can even [link your website](http://charlesmangwa.surge.sh) or if you prefer: [email sombedy](mailto:charlesmangwa@gmail.com)
29+
{'\n\n'}
30+
Spice it up with some GIF 💃:
31+
{'\n\n'}
32+
![Some GIF](https://media.giphy.com/media/dkGhBWE3SyzXW/giphy.gif)
33+
{'\n\n'}
34+
And even add a cool video 😎!
35+
{'\n\n'}
36+
[![A cool video](https://img.youtube.com/vi/dQw4w9WgXcQ/0.jpg)](http://www.youtube.com/watch?v=dQw4w9WgXcQ)
2737
</Markdown>
2838
)
2939
}
@@ -75,7 +85,10 @@ Example:
7585
- `hr` (`<View>`)
7686
- `heading` (`<Text>`) - Also `heading1` through `heading6`
7787
- `inlineCode` (`<Text>`)
88+
- `image` (`<Image>`) - Supports `.jpg`, `.png`, `.gif`, etc
89+
- `link` (`Text`)
7890
- `list` (`<View>`) - Also `listItem` (`<View>`), `listItemBullet` (`<Text>`), `listItemNumber` (`<Text>`) and `listItemText` (`<Text>`)
91+
- `mailTo` (`Text`)
7992
- `paragraph` (`<View>`)
8093
- `plainText` (`<Text>`) - Use for styling text without any associated styles
8194
- `strong` (`<Text>`)
@@ -88,7 +101,8 @@ Example:
88101
- `text` (`<Text>`) - Inherited by all text based elements
89102
- `u` (`<View>`)
90103
- `url` (`<Text>`)
91-
- `view` (`<View>`) - This is the container `View` that the Markdown is rendered in.
104+
- `video` (`<Image>`)
105+
- `view` (`<View>`) - This is the `View` container where the Markdown is render.
92106
93107
##### WIP
94108
@@ -97,9 +111,6 @@ _Most of these elements can be used, but I'm still working on some improvements.
97111
- `autolink` (`<Text>`)
98112
- `blockQuote` (`<Text>`)
99113
- `codeBlock` (`<View>`)
100-
- `image` (`<Image>`) - Usable but need to herit image size
101-
- `link` (`<Text>`)
102-
- `mailto` (`<Text>`)
103114
- `newline` (`<Text>`)
104115
105116
## Credits

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"type": "git",
55
"url": "https://github.com/CharlesMangwa/react-native-simple-markdown.git"
66
},
7-
"version": "1.0.54",
8-
"description": "A component for rendering Markdown in React Native with native components.",
7+
"version": "1.0.60-rc.0",
8+
"description": "Render Markdown in React Native with native components (iOS & Android)",
99
"main": "index.js",
1010
"author": "Charles Mangwa <charlesmangwa@gmail.com> (http://charlesmangwa.surge.sh)",
1111
"dependencies": {

rules.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { createElement } from 'react'
2-
import { Image, Text, View } from 'react-native'
2+
import { Image, Text, View, Linking } from 'react-native'
33
import SimpleMarkdown from 'simple-markdown'
44
import _ from 'lodash'
55

@@ -9,7 +9,7 @@ export default (styles) => ({
99
state.withinText = true
1010
return createElement(Text, {
1111
key: state.key,
12-
style: styles.autolink,
12+
style: styles.link,
1313
onPress: _.noop
1414
}, output(node.content, state))
1515
}
@@ -77,7 +77,7 @@ export default (styles) => ({
7777
return createElement(Image, {
7878
key: state.key,
7979
source: { uri: node.target },
80-
style: styles.image
80+
style: node.target.match(/youtube/) ? styles.video : styles.image
8181
})
8282
}
8383
},
@@ -93,9 +93,13 @@ export default (styles) => ({
9393
link: {
9494
react: (node, output, state) => {
9595
state.withinText = true
96+
const openUrl = (url) => {
97+
Linking.openURL(url).catch(error => console.warn('An error occurred: ', error))
98+
}
9699
return createElement(Text, {
100+
style: node.target.match(/@/) ? styles.mailTo : styles.link,
97101
key: state.key,
98-
style: styles.autolink
102+
onPress: () => openUrl(node.target)
99103
}, output(node.content, state))
100104
}
101105
},
@@ -118,16 +122,6 @@ export default (styles) => ({
118122
return createElement(View, { key: state.key, style: styles.list }, items)
119123
}
120124
},
121-
mailto: {
122-
react: (node, output, state) => {
123-
state.withinText = true
124-
return createElement(Text, {
125-
key: state.key,
126-
style: styles.mailto,
127-
onPress: _.noop
128-
}, output(node.content, state))
129-
}
130-
},
131125
newline: {
132126
react: (node, output, state) => {
133127
return createElement(Text, {
@@ -206,10 +200,13 @@ export default (styles) => ({
206200
url: {
207201
react: (node, output, state) => {
208202
state.withinText = true
203+
const openUrl = (url) => {
204+
Linking.openURL(url).catch(error => console.warn('An error occurred: ', error))
205+
}
209206
return createElement(Text, {
210207
key: state.key,
211208
style: styles.url,
212-
onPress: _.noop
209+
onPress: openURL(node.target)
213210
}, output(node.content, state))
214211
}
215212
}

styles.js

+10
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ const styles = {
4949
fontFamily: 'Courier',
5050
fontWeight: 'bold',
5151
},
52+
link: {
53+
textDecorationLine: 'underline',
54+
},
5255
list: {},
5356
listItem: {
5457
flexDirection: 'row',
@@ -61,6 +64,9 @@ const styles = {
6164
listItemNumber: {
6265
fontWeight: 'bold',
6366
},
67+
mailTo: {
68+
textDecorationLine: 'underline',
69+
},
6470
paragraph: {
6571
marginTop: 10,
6672
marginBottom: 10,
@@ -113,6 +119,10 @@ const styles = {
113119
borderColor: '#222222',
114120
borderBottomWidth: 1,
115121
},
122+
video: {
123+
width: 300,
124+
height: 300,
125+
}
116126
}
117127

118128
export default styles

0 commit comments

Comments
 (0)