Skip to content

Commit f07dd02

Browse files
Use markdown to style sentence
1 parent 4fe1ed2 commit f07dd02

File tree

6 files changed

+601
-16
lines changed

6 files changed

+601
-16
lines changed

i18n/oceans.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"mostImportantParts": "These were the most important fish parts:",
6565
"clickIndividualFish": "Click individual fish to see their information.",
6666
"mostImportantPartsInDetermining": "These were the most important fish parts in determining whether this fish was",
67+
"mostImportantPartsInDeterminingFullSentence": "These were the most important fish parts in determining whether this fish was “*{word}*“ or “**{notWord}**“.",
6768
"or": "or",
6869
"newWord": "New Word",
6970
"finish": "Finish",

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"react-dom": "~15.4.0"
4040
},
4141
"devDependencies": {
42+
"@code-dot-org/redactable-markdown": "^0.4.0",
4243
"@tensorflow-models/knn-classifier": "~1.1.0",
4344
"@tensorflow-models/mobilenet": "^2.0.4",
4445
"@tensorflow/tfjs": "^1.3.1",
@@ -79,6 +80,9 @@
7980
"react-addons-test-utils": "~15.4.0",
8081
"react-dom": "~15.4.0",
8182
"react-test-renderer": "~15.4.0",
83+
"rehype-react": "^4.0.1",
84+
"remark-parse": "^7.0.2",
85+
"remark-rehype": "^5.0.0",
8286
"sinon": "^7.5.0",
8387
"style-loader": "^1.0.0",
8488
"svm": "uponthesun/svmjs",

src/oceans/ui.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pondTextMarkdown p {
2+
margin: 0
3+
}
4+
5+
#pondTextMarkdown strong {
6+
color: #eb5757;
7+
font-weight: normal;
8+
}
9+
10+
#pondTextMarkdown em {
11+
color: #56c568;
12+
font-style: normal;
13+
}
14+
15+

src/oceans/ui.jsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {
3232
faTrash
3333
} from '@fortawesome/free-solid-svg-icons';
3434
import I18n from './i18n';
35+
import Markdown from '@ml/utils/Markdown';
36+
import './ui.css';
3537

3638
const styles = {
3739
body: {
@@ -390,7 +392,7 @@ const styles = {
390392
pointerEvents: 'none'
391393
},
392394
pondPanelPreText: {
393-
marginBottom: '5%'
395+
marginBottom: '5%',
394396
},
395397
pondPanelRow: {
396398
position: 'relative',
@@ -1180,18 +1182,18 @@ class PondPanel extends React.Component {
11801182
>
11811183
{state.pondExplainFishSummary && (
11821184
<div>
1183-
<div style={styles.pondPanelPreText}>
1184-
{I18n.t('mostImportantPartsInDetermining')}
1185-
{' “'}
1186-
<span style={{color: colors.green}}>
1187-
{state.word.toLowerCase()}
1188-
</span>
1189-
{'”'} {I18n.t('or')}
1190-
{' “'}
1191-
<span style={{color: colors.red}}>
1192-
{I18n.t('notWord', {word: state.word}).toLowerCase()}
1193-
</span>
1194-
{'”'}.
1185+
<div style={styles.pondPanelPreText} id='pondTextMarkdown'>
1186+
<Markdown
1187+
markdown={I18n.t(
1188+
'mostImportantPartsInDeterminingFullSentence',
1189+
{
1190+
word: state.word.toLowerCase(),
1191+
notWord: I18n.t('notWord', {
1192+
word: state.word
1193+
}).toLowerCase()
1194+
}
1195+
)}
1196+
/>
11951197
</div>
11961198
{state.pondExplainFishSummary.slice(0, 4).map((f, i) => (
11971199
<div key={i}>

src/utils/Markdown.jsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Implementation of this Markdown component is based off of the implementation
3+
* of SafeMarkdown in the main code-dot-org repo.
4+
*
5+
*/
6+
import PropTypes from 'prop-types';
7+
import React from 'react';
8+
9+
import remarkRehype from 'remark-rehype';
10+
import rehypeReact from 'rehype-react';
11+
import Parser from '@code-dot-org/redactable-markdown';
12+
13+
const markdownProcessor = Parser.create()
14+
.getParser()
15+
.use(remarkRehype)
16+
.use(rehypeReact, {createElement: React.createElement});
17+
18+
export default class Markdown extends React.Component {
19+
static propTypes = {
20+
markdown: PropTypes.string.isRequired
21+
};
22+
23+
render() {
24+
return markdownProcessor.processSync(this.props.markdown).contents;
25+
}
26+
}

0 commit comments

Comments
 (0)