Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: text formatting + clickable links
- Loading branch information
Showing
19 changed files
with
229 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
client/react-native/common/components/Library/Markdown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import MarkdownLib, { styles as libStyles } from 'react-native-markdown-renderer' | ||
import MarkdownIt from 'markdown-it' | ||
import React from 'react' | ||
import { StyleSheet, Text } from 'react-native' | ||
import { monospaceFont } from '../../constants/styling' | ||
import colors from '../../constants/colors' | ||
import { openURL } from '../../helpers/linking' | ||
|
||
export const styles = StyleSheet.create({ | ||
codeBlock: { | ||
borderRadius: 5, | ||
borderWidth: 0, | ||
backgroundColor: colors.fakeBlack, | ||
color: colors.white, | ||
padding: 4, | ||
fontFamily: monospaceFont, | ||
}, | ||
codeInline: { | ||
borderRadius: 5, | ||
borderWidth: 0, | ||
backgroundColor: colors.fakeBlack, | ||
color: colors.white, | ||
padding: 1, | ||
fontFamily: monospaceFont, | ||
}, | ||
blockquote: { | ||
paddingVertical: 0, | ||
paddingRight: 0, | ||
paddingLeft: 5, | ||
borderLeftWidth: 2, | ||
borderLeftColor: colors.blue25, | ||
margin: 0, | ||
backgroundColor: 'transparent', | ||
}, | ||
inlineCode: { | ||
borderRadius: 3, | ||
borderWidth: 1, | ||
padding: 2, | ||
fontFamily: monospaceFont, | ||
fontWeight: 'bold', | ||
}, | ||
list: {}, | ||
listItem: { | ||
flex: 1, | ||
flexWrap: 'wrap', | ||
}, | ||
listUnorderedItem: { | ||
flexDirection: 'row', | ||
justifyContent: 'flex-start', | ||
}, | ||
listUnorderedItemIcon: { | ||
marginLeft: 10, | ||
marginRight: 10, | ||
lineHeight: 20, | ||
}, | ||
listUnorderedItemText: { | ||
fontSize: 20, | ||
lineHeight: 20, | ||
}, | ||
listOrderedItem: { | ||
flexDirection: 'row', | ||
}, | ||
listOrderedItemIcon: { | ||
marginLeft: 10, | ||
marginRight: 10, | ||
lineHeight: 20, | ||
}, | ||
listOrderedItemText: { | ||
fontWeight: 'bold', | ||
lineHeight: 20, | ||
}, | ||
paragraph: { | ||
marginTop: 0, | ||
marginBottom: 0, | ||
flexWrap: 'wrap', | ||
flexDirection: 'row', | ||
alignItems: 'flex-start', | ||
justifyContent: 'flex-start', | ||
}, | ||
hardbreak: { | ||
width: '100%', | ||
height: 1, | ||
}, | ||
strong: { | ||
fontWeight: 'bold', | ||
}, | ||
text: {}, | ||
strikethrough: { | ||
textDecorationLine: 'line-through', | ||
}, | ||
link: { | ||
textDecorationLine: 'underline', | ||
}, | ||
blocklink: { | ||
flex: 1, | ||
borderColor: colors.blue, | ||
borderBottomWidth: 1, | ||
}, | ||
u: { | ||
borderBottomWidth: 1, | ||
}, | ||
}) | ||
|
||
const md = MarkdownIt({ | ||
typographer: true, | ||
linkify: true, | ||
}).disable([ | ||
'newline', | ||
'image', | ||
'link', // Avoid [https://test.com](https://olol.com) | ||
'html_inline', | ||
'table', | ||
'hr', | ||
'reference', | ||
'html_block', | ||
'heading', | ||
]) | ||
|
||
const flattenedStyles = StyleSheet.flatten([libStyles, styles]) | ||
|
||
const link = (node, children, parent, styles) => | ||
<Text key={node.key} style={styles.link} accessibilityRole='link' onPress={() => openURL(node.attributes.href)}> | ||
{children} | ||
</Text> | ||
|
||
const Markdown = ({ children, style, ...props }) => | ||
<MarkdownLib rules={{ | ||
link, | ||
}} markdownit={md} style={style || flattenedStyles} {...props}>{children}</MarkdownLib> | ||
|
||
export default Markdown | ||
Markdown.styles = styles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Linking } from 'react-native'; | ||
|
||
export const openURL = url => { | ||
if (url) { | ||
Linking.openURL(url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NativeModules } from 'react-native' | ||
|
||
const { CoreModule } = NativeModules | ||
|
||
export const openURL = url => { | ||
if (url) { | ||
CoreModule.openURL(url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.