Skip to content

Commit c9e7b50

Browse files
machourHoussein Djirdeh
authored andcommitted
feat(markdown): Add support for quoted emails (#501)
* feat(markdown): Add support for quoted emails * fix: use paddingHorizontal instead of Left and Right
1 parent b4e05a2 commit c9e7b50

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"react-native": "0.48.1",
6262
"react-native-actionsheet": "^2.2.0",
6363
"react-native-code-push": "^5.0.0-beta",
64+
"react-native-collapsible": "^0.9.0",
6465
"react-native-communications": "^2.2.1",
6566
"react-native-config": "^0.6.0",
6667
"react-native-cookies": "^3.2.0",

src/components/github-htmlview.component.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import SyntaxHighlighter from 'react-native-syntax-highlighter';
66
import { github as GithubStyle } from 'react-syntax-highlighter/dist/styles';
77
import entities from 'entities';
88

9-
import { ImageZoom } from 'components';
9+
import { ImageZoom, ToggleView } from 'components';
1010
import { colors, fonts, normalize } from 'config';
1111

1212
const textStyle = Platform.select({
@@ -65,6 +65,16 @@ const styles = {
6565
a: linkStyle,
6666
};
6767

68+
const quotedEmailToggleStyle = {
69+
backgroundColor: colors.greyMid,
70+
paddingHorizontal: 4,
71+
alignSelf: 'flex-start',
72+
height: 15,
73+
lineHeight: 12,
74+
marginBottom: 6,
75+
marginTop: 3,
76+
};
77+
6878
const styleSheet = StyleSheet.create(styles);
6979

7080
const { width } = Dimensions.get('window');
@@ -176,6 +186,11 @@ export class GithubHtmlView extends Component {
176186
/<li class="task-list-item">(<span[^>]*>)?<input checked="" class="task-list-item-checkbox" disabled="" id="" type="checkbox"> ?\.? ?/g,
177187
'$1✅ '
178188
)
189+
// Quoted email reply
190+
.replace(
191+
/<span class="email-hidden-toggle"><a href="#"><\/a><\/span>/g,
192+
''
193+
)
179194
// Remove links & spans around images
180195
.replace(/<a[^>]+><img([^>]+)><\/a>/g, '<img$1>')
181196
.replace(/<span[^>]*><img([^>]+)><\/span>/g, '<img$1>')
@@ -246,6 +261,33 @@ export class GithubHtmlView extends Component {
246261
hr: (node, index, siblings, parent, defaultRenderer) => (
247262
<View key={index} style={{ ...hrStyle }} />
248263
),
264+
div: (node, index, siblings, parent, defaultRenderer) => {
265+
if (node.attribs.class) {
266+
const className = node.attribs.class;
267+
268+
if (className.includes('email-hidden-reply')) {
269+
return defaultRenderer(onlyTagsChildren(node), node);
270+
}
271+
272+
if (className.includes('email-quoted-reply')) {
273+
return (
274+
<ToggleView
275+
TouchableView={<Text style={quotedEmailToggleStyle}></Text>}
276+
>
277+
{renderers.blockquote(
278+
node,
279+
index,
280+
siblings,
281+
parent,
282+
defaultRenderer
283+
)}
284+
</ToggleView>
285+
);
286+
}
287+
}
288+
289+
return undefined;
290+
},
249291
img: (node, index, siblings, parent, defaultRenderer) => {
250292
if (hasAncestor(node, ['ol', 'ul', 'span'])) {
251293
return (

src/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ export * from './image-zoom.component';
2828
export * from './button.component';
2929
export * from './notification-icon.component';
3030
export * from './badge.component';
31+
export * from './toggle-view.component';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { Component } from 'react';
2+
import { TouchableOpacity, View, Text } from 'react-native';
3+
import Collapsible from 'react-native-collapsible';
4+
5+
export class ToggleView extends Component {
6+
props: {
7+
children: any,
8+
TouchableView: any,
9+
};
10+
11+
state: {
12+
collapsed: boolean,
13+
};
14+
15+
constructor() {
16+
super();
17+
18+
this.state = {
19+
collapsed: true,
20+
};
21+
}
22+
23+
_toggle() {
24+
this.setState({ collapsed: !this.state.collapsed });
25+
}
26+
27+
render() {
28+
return (
29+
<View>
30+
<TouchableOpacity onPress={() => this._toggle()}>
31+
{this.props.TouchableView}
32+
</TouchableOpacity>
33+
<Collapsible collapsed={this.state.collapsed}>
34+
{this.props.children}
35+
</Collapsible>
36+
</View>
37+
);
38+
}
39+
}
40+
41+
ToggleView.defaultProps = {
42+
TouchableView: <Text></Text>,
43+
};

yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5355,6 +5355,12 @@ react-native-code-push@^5.0.0-beta:
53555355
plist "1.2.0"
53565356
xcode "0.9.2"
53575357

5358+
react-native-collapsible@^0.9.0:
5359+
version "0.9.0"
5360+
resolved "https://registry.yarnpkg.com/react-native-collapsible/-/react-native-collapsible-0.9.0.tgz#207849faa15493820d19fa6a5e58f7c7b6c1b910"
5361+
dependencies:
5362+
prop-types "^15.5.10"
5363+
53585364
react-native-communications@^2.2.1:
53595365
version "2.2.1"
53605366
resolved "https://registry.yarnpkg.com/react-native-communications/-/react-native-communications-2.2.1.tgz#7883b56b20a002eeb790c113f8616ea8692ca795"

0 commit comments

Comments
 (0)