Skip to content

feat(markdown): Add support for quoted emails #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"react-native": "0.48.1",
"react-native-actionsheet": "^2.2.0",
"react-native-code-push": "^5.0.0-beta",
"react-native-collapsible": "^0.9.0",
"react-native-communications": "^2.2.1",
"react-native-config": "^0.6.0",
"react-native-cookies": "^3.2.0",
Expand Down
44 changes: 43 additions & 1 deletion src/components/github-htmlview.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SyntaxHighlighter from 'react-native-syntax-highlighter';
import { github as GithubStyle } from 'react-syntax-highlighter/dist/styles';
import entities from 'entities';

import { ImageZoom } from 'components';
import { ImageZoom, ToggleView } from 'components';
import { colors, fonts, normalize } from 'config';

const textStyle = Platform.select({
Expand Down Expand Up @@ -65,6 +65,16 @@ const styles = {
a: linkStyle,
};

const quotedEmailToggleStyle = {
backgroundColor: colors.greyMid,
paddingHorizontal: 4,
alignSelf: 'flex-start',
height: 15,
lineHeight: 12,
marginBottom: 6,
marginTop: 3,
};

const styleSheet = StyleSheet.create(styles);

const { width } = Dimensions.get('window');
Expand Down Expand Up @@ -176,6 +186,11 @@ export class GithubHtmlView extends Component {
/<li class="task-list-item">(<span[^>]*>)?<input checked="" class="task-list-item-checkbox" disabled="" id="" type="checkbox"> ?\.? ?/g,
'$1✅ '
)
// Quoted email reply
.replace(
/<span class="email-hidden-toggle"><a href="#">…<\/a><\/span>/g,
''
)
// Remove links & spans around images
.replace(/<a[^>]+><img([^>]+)><\/a>/g, '<img$1>')
.replace(/<span[^>]*><img([^>]+)><\/span>/g, '<img$1>')
Expand Down Expand Up @@ -246,6 +261,33 @@ export class GithubHtmlView extends Component {
hr: (node, index, siblings, parent, defaultRenderer) => (
<View key={index} style={{ ...hrStyle }} />
),
div: (node, index, siblings, parent, defaultRenderer) => {
if (node.attribs.class) {
const className = node.attribs.class;

if (className.includes('email-hidden-reply')) {
return defaultRenderer(onlyTagsChildren(node), node);
}

if (className.includes('email-quoted-reply')) {
return (
<ToggleView
TouchableView={<Text style={quotedEmailToggleStyle}>…</Text>}
>
{renderers.blockquote(
node,
index,
siblings,
parent,
defaultRenderer
)}
</ToggleView>
);
}
}

return undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can not understand why undefined instead of null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From react-native-htmlview documentation:

renderNode: a custom function to render HTML nodes however you see fit. If the function returns undefined (not null), the default renderer will be used for that node.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm understood, thank you.

},
img: (node, index, siblings, parent, defaultRenderer) => {
if (hasAncestor(node, ['ol', 'ul', 'span'])) {
return (
Expand Down
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ export * from './image-zoom.component';
export * from './button.component';
export * from './notification-icon.component';
export * from './badge.component';
export * from './toggle-view.component';
43 changes: 43 additions & 0 deletions src/components/toggle-view.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { Component } from 'react';
import { TouchableOpacity, View, Text } from 'react-native';
import Collapsible from 'react-native-collapsible';

export class ToggleView extends Component {
props: {
children: any,
TouchableView: any,
};

state: {
collapsed: boolean,
};

constructor() {
super();

this.state = {
collapsed: true,
};
}

_toggle() {
this.setState({ collapsed: !this.state.collapsed });
}

render() {
return (
<View>
<TouchableOpacity onPress={() => this._toggle()}>
{this.props.TouchableView}
</TouchableOpacity>
<Collapsible collapsed={this.state.collapsed}>
{this.props.children}
</Collapsible>
</View>
);
}
}

ToggleView.defaultProps = {
TouchableView: <Text>…</Text>,
};
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5290,6 +5290,12 @@ react-native-code-push@^5.0.0-beta:
plist "1.2.0"
xcode "0.9.2"

react-native-collapsible@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/react-native-collapsible/-/react-native-collapsible-0.9.0.tgz#207849faa15493820d19fa6a5e58f7c7b6c1b910"
dependencies:
prop-types "^15.5.10"

react-native-communications@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/react-native-communications/-/react-native-communications-2.2.1.tgz#7883b56b20a002eeb790c113f8616ea8692ca795"
Expand Down