Skip to content
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

Markdown implementation #1486

Merged
merged 22 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9f2312d
First draft of Markdown implementation for desktop
josephlacey Apr 27, 2023
deac8d4
First draft of Markdown implementation for mobile
josephlacey Apr 27, 2023
720cb06
Adding horizontal rule back in. Some minor styling changes to lists
josephlacey Apr 28, 2023
4637a62
Overhauling of desktop markdown styling
josephlacey May 8, 2023
833e587
Merge branch 'develop' into feature/1088
josephlacey May 11, 2023
256f8d2
Codeblock styling changes to Desktop Markdown rendering
josephlacey May 13, 2023
97af2a5
Link styling changes to Mobile Markdown rendering
josephlacey May 13, 2023
684ea75
Desktop Markdown linting fixes
josephlacey May 15, 2023
7363051
Migration to a new React Native library, related code changes
josephlacey May 15, 2023
d702011
Mobile Markdown styling cleanup. Adding included Linkify feature.
josephlacey May 15, 2023
a55bc2c
Readding Headings to Desktop Markdown. Tweak to custom image handling
josephlacey May 16, 2023
d05f502
Migrating Typography to processing rule for Markdown paragraph. Styli…
josephlacey May 17, 2023
515025f
More desktop Markdown styling
josephlacey May 17, 2023
b2791b7
Removing previously alternate Markdown rendering package
josephlacey May 19, 2023
1ef01da
Merge remote-tracking branch 'upstream/develop' into feature/1088
josephlacey Jun 8, 2023
ab9d4a4
Switching to a more TypeScript-friendly react-native-markdown-display…
josephlacey Jun 9, 2023
cc21817
Adding related package-lock.json
josephlacey Jun 9, 2023
05024bb
Adding types to mobile Markdown renderinng rule customizations
josephlacey Jun 9, 2023
75735a0
Merge remote-tracking branch 'upstream/develop' into feature/1088
josephlacey Jun 15, 2023
2bc137b
Updating Cypress snapshots to reflect italics with Markdown implement…
josephlacey Jun 15, 2023
c270f77
Fixing minor styling issue with Markdown links
josephlacey Jun 15, 2023
8d156ce
Fixing TypeScript linting error.
josephlacey Jun 15, 2023
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@
"get-port": "^5.1.1",
"keymirror": "0.1.1",
"pkijs": "^3.0.8",
"react-markdown": "^8.0.7",
"react-qr-code": "^2.0.11",
"remark-gfm": "^3.0.1",
"socket.io-client": "4.6.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { Typography, styled } from '@mui/material'
import classNames from 'classnames'
import React, { ReactNode } from 'react'
import Linkify from 'react-linkify'
import ReactMarkdown from 'react-markdown'
import remarkGfm from 'remark-gfm'
import theme from '../../../theme'

const PREFIX = 'TextMessage'

const classes = {
message: `${PREFIX}message`,
pending: `${PREFIX}pending`,
link: `${PREFIX}link`
blockquote: `${PREFIX}blockquote`,
code: `${PREFIX}code`,
pre: `${PREFIX}pre`,
hr: `${PREFIX}hr`,
link: `${PREFIX}link`,
ol: `${PREFIX}list`,
ul: `${PREFIX}ul`,
table: `${PREFIX}table`,
tableHeaderCell: `${PREFIX}tableHeaderCell`,
tableRowCell: `${PREFIX}tableRowCell`
}

const StyledTypography = styled(Typography)(() => ({
Expand All @@ -24,12 +34,68 @@ const StyledTypography = styled(Typography)(() => ({
color: theme.palette.colors.lightGray
},

[`& .${classes.blockquote}`]: {
lineHeight: '1em',
whiteSpace: 'normal',
marginInlineStart: 0,
marginBlockStart: '.5em',
marginBlockEnd: '.5em',
paddingTop: '.5em',
paddingBottom: '.5em',
paddingLeft: '1em',
borderLeft: 'solid',
borderLeftWidth: '3px',
borderColor: theme.palette.colors.lightGray,
color: theme.palette.colors.lightGray
},

[`& .${classes.code}`]: {
backgroundColor: theme.palette.colors.veryLightGray,
padding: '.25em'
},

[`& .${classes.pre}`]: {
backgroundColor: theme.palette.colors.veryLightGray,
padding: '.25em'
},

[`& .${classes.hr}`]: {
marginTop: '2em'
},

[`& .${classes.link}`]: {
color: theme.palette.colors.lushSky,
cursor: 'pointer',
textDecoration: 'none',
'&:hover': {
textDecoration: 'underline'
}
},

[`& .${classes.ol}`]: {
paddingInlineStart: '15px',
whiteSpace: 'normal'
},

[`& .${classes.ul}`]: {
paddingInlineStart: '15px',
whiteSpace: 'normal',
listStyleType: 'disc'
},

[`& .${classes.table}`]: {
width: '100%'
},

[`& .${classes.tableHeaderCell}`]: {
borderBottom: 'solid',
borderBottomWidth: 1,
borderColor: theme.palette.colors.veryLightGray,
textAlign: 'center'
},

[`& .${classes.tableRowCell}`]: {
textAlign: 'center'
}
})) as typeof Typography

Expand All @@ -46,14 +112,6 @@ export const TextMessageComponent: React.FC<TextMessageComponentProps> = ({
pending,
openUrl
}) => {
const componentDecorator = (decoratedHref: string, decoratedText: string, key: number): ReactNode => {
return (
<a onClick={() => { openUrl(decoratedHref) }} className={classNames({ [classes.link]: true })} key={key}>
{decoratedText}
</a>
)
}

return (
<StyledTypography
component={'span' as any}
Expand All @@ -62,7 +120,65 @@ export const TextMessageComponent: React.FC<TextMessageComponentProps> = ({
[classes.pending]: pending
})}
data-testid={`messagesGroupContent-${messageId}`}>
<Linkify componentDecorator={componentDecorator}>{message}</Linkify>
<ReactMarkdown
remarkPlugins={[[remarkGfm, { singleTilde: false }]]}
children={message}
components={{
a: ({ node, ...props }) => (
<a
onClick={e => {
e.preventDefault()
if (props.href) openUrl(props.href)
}}
className={classNames({ [classes.link]: true })}
{...props}
/>
),
blockquote: ({ node, ...props }) => (
<blockquote className={classNames({ [classes.blockquote]: true })} {...props} />
),
code: ({ node, ...props }) => (
<code className={classNames({ [classes.code]: true })} {...props} />
),
pre: ({ node, ...props }) => (
<pre className={classNames({ [classes.pre]: true })} {...props} />
),
hr: ({ node, ...props }) => (
<hr className={classNames({ [classes.hr]: true })} {...props} />
),
img: ({ node, ...props }) => (
<p>
![{props.alt}](
<a
onClick={e => {
e.preventDefault()
if (props.src) openUrl(props.src)
}}
className={classNames({ [classes.link]: true })}
href={props.src}>
{props.src}
</a>
)
</p>
),
p: React.Fragment,
ol: ({ node, ...props }) => (
<ol className={classNames({ [classes.ol]: true })} {...props} />
),
ul: ({ node, ...props }) => (
<ul className={classNames({ [classes.ul]: true })} {...props} />
),
table: ({ node, ...props }) => (
<table className={classNames({ [classes.table]: true })} {...props} />
),
th: ({ node, ...props }) => (
<th className={classNames({ [classes.tableHeaderCell]: props.isHeader })} {...props} />
),
td: ({ node, ...props }) => (
<td className={classNames({ [classes.tableRowCell]: true })} {...props} />
)
}}
/>
</StyledTypography>
)
}
Loading