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

fix(app): replace remark with react-markdown #14942

Merged
merged 2 commits into from
Apr 17, 2024
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
3 changes: 1 addition & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"react-error-boundary": "^4.0.10",
"react-i18next": "13.5.0",
"react-intersection-observer": "^8.33.1",
"react-markdown": "9.0.1",
"react-redux": "8.1.2",
"react-router-dom": "5.3.4",
"react-select": "5.4.0",
Expand All @@ -57,8 +58,6 @@
"redux": "4.0.5",
"redux-observable": "1.1.0",
"redux-thunk": "2.3.0",
"remark": "9.0.0",
"remark-react": "4.0.3",
"reselect": "4.0.0",
"rxjs": "^6.5.1",
"semver": "5.5.0",
Expand Down
33 changes: 16 additions & 17 deletions app/src/molecules/ReleaseNotes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import * as React from 'react'
import remark from 'remark'
import reactRenderer from 'remark-react'
import Markdown from 'react-markdown'

import { StyledText } from '@opentrons/components'

import styles from './styles.module.css'

export interface ReleaseNotesProps {
source?: string | null
}

// ToDo (kk:09/22/2023) This component should be updated in the future
// since the package we use hasn't been updated more than 2 years.
// Also the creator recommends users to replace remark-react with rehype-react.
const renderer = remark().use(reactRenderer, {
remarkReactComponents: {
div: React.Fragment,
h2: HeaderText,
ul: React.Fragment,
li: ParagraphText,
p: ParagraphText,
a: ExternalLink,
},
})

const DEFAULT_RELEASE_NOTES = 'We recommend upgrading to the latest version.'

export function ReleaseNotes(props: ReleaseNotesProps): JSX.Element {
Expand All @@ -29,7 +17,18 @@ export function ReleaseNotes(props: ReleaseNotesProps): JSX.Element {
return (
<div className={styles.release_notes}>
{source != null ? (
renderer.processSync(source).contents
<Markdown
components={{
div: undefined,
ul: undefined,
h2: HeaderText,
li: ParagraphText,
p: ParagraphText,
a: ExternalLink,
}}
>
{source}
</Markdown>
) : (
<p>{DEFAULT_RELEASE_NOTES}</p>
)}
Expand Down
11 changes: 0 additions & 11 deletions app/typings/remark.d.ts

This file was deleted.

Loading
Loading