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

✨ add react-remark library, test it in SimpleMarkdownText #2875

Merged
merged 3 commits into from
Nov 7, 2023
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
2 changes: 1 addition & 1 deletion .bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"files": [
{
"path": "./dist/assets/common.mjs",
"maxSize": "1.75MB"
"maxSize": "1.83MB"
},
{
"path": "./dist/assets/owid.mjs",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"react-intersection-observer": "^9.4.0",
"react-move": "^6.5.0",
"react-recaptcha": "^2.3.10",
"react-remark": "^2.1.0",
"react-router-dom": "^5.3.1",
"react-select": "^5.7.3",
"react-tag-autocomplete": "^7.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ export const IndicatorProcessing = (props: IndicatorProcessingProps) => {
Notes on our processing step for this indicator
</h5>
<div className="variable-processing-info__description">
<p className="article-block__text">
<SimpleMarkdownText
text={props.descriptionProcessing}
/>
</p>
<SimpleMarkdownText
text={props.descriptionProcessing}
/>
</div>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ export const IndicatorSources = (props: IndicatorSourcesProps) => {
content={
<>
{source.description && (
<p className="article-block__text">
<SimpleMarkdownText
text={source.description}
/>
</p>
<SimpleMarkdownText
text={source.description}
/>
)}
{(dateAccessed || source.urlMain) && (
<div
Expand Down
24 changes: 2 additions & 22 deletions packages/@ourworldindata/components/src/SimpleMarkdownText.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import React from "react"
import { computed } from "mobx"
import {
IRToken,
parsimmonToTextTokens,
recursiveMergeTextTokens,
} from "./MarkdownTextWrap/MarkdownTextWrap.js"
import { MarkdownRoot, mdParser } from "./MarkdownTextWrap/parser.js"
import { Remark } from "react-remark"
type SimpleMarkdownTextProps = {
text: string
}
Expand All @@ -15,22 +10,7 @@ export class SimpleMarkdownText extends React.Component<SimpleMarkdownTextProps>
return this.props.text
}

@computed get ast(): MarkdownRoot["children"] {
if (!this.text) return []
const result = mdParser.markdown.parse(this.props.text)
if (result.status) {
return result.value.children
}
return []
}

@computed get tokens(): IRToken[] {
const tokens = parsimmonToTextTokens(this.ast, {})
return recursiveMergeTextTokens(tokens)
}

render(): JSX.Element | null {
const { tokens } = this
return <>{tokens.map((token, index) => token.toHTML(index))}</>
return <Remark>{this.text}</Remark>
}
}
Loading
Loading