This commit is contained in:
Mateusz Tylka 2023-02-03 11:53:13 +01:00
commit ae71eeaf64
3 changed files with 53 additions and 18 deletions

17
package-lock.json generated
View File

@ -14,6 +14,7 @@
"axios": "^0.27.2", "axios": "^0.27.2",
"keycloak-js": "^19.0.1", "keycloak-js": "^19.0.1",
"markdown": "^0.5.0", "markdown": "^0.5.0",
"marked": "^4.2.12",
"prop-types": "^15.8.1", "prop-types": "^15.8.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
@ -11725,6 +11726,17 @@
"node": "*" "node": "*"
} }
}, },
"node_modules/marked": {
"version": "4.2.12",
"resolved": "https://registry.npmjs.org/marked/-/marked-4.2.12.tgz",
"integrity": "sha512-yr8hSKa3Fv4D3jdZmtMMPghgVt6TWbk86WQaWhDloQjRSQhMMYCAro7jP7VDJrjjdV8pxVxMssXS8B8Y5DZ5aw==",
"bin": {
"marked": "bin/marked.js"
},
"engines": {
"node": ">= 12"
}
},
"node_modules/mdn-data": { "node_modules/mdn-data": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.4.tgz", "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.4.tgz",
@ -25423,6 +25435,11 @@
"nopt": "~2.1.1" "nopt": "~2.1.1"
} }
}, },
"marked": {
"version": "4.2.12",
"resolved": "https://registry.npmjs.org/marked/-/marked-4.2.12.tgz",
"integrity": "sha512-yr8hSKa3Fv4D3jdZmtMMPghgVt6TWbk86WQaWhDloQjRSQhMMYCAro7jP7VDJrjjdV8pxVxMssXS8B8Y5DZ5aw=="
},
"mdn-data": { "mdn-data": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.4.tgz", "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.4.tgz",

View File

@ -12,6 +12,7 @@
"axios": "^0.27.2", "axios": "^0.27.2",
"keycloak-js": "^19.0.1", "keycloak-js": "^19.0.1",
"markdown": "^0.5.0", "markdown": "^0.5.0",
"marked": "^4.2.12",
"prop-types": "^15.8.1", "prop-types": "^15.8.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",

View File

@ -1,22 +1,33 @@
import React from 'react'; import React from 'react';
import {FlexColumn} from '../../utils/containers'; import {FlexColumn} from '../../utils/containers';
import {Body, H2, Medium} from '../../utils/fonts'; import {Body, H2} from '../../utils/fonts';
import Media from 'react-media'; import Media from 'react-media';
import theme from '../../utils/theme'; import theme from '../../utils/theme';
import getChallengeFullDescription from '../../api/getChallengeFullDescription'; import getChallengeFullDescription from '../../api/getChallengeFullDescription';
import {markdown} from 'markdown'; // import {markdown} from 'markdown';
import styled from 'styled-components'; import styled from 'styled-components';
import InfoList from '../generic/InfoList'; import InfoList from '../generic/InfoList';
import Loading from '../generic/Loading'; import Loading from '../generic/Loading';
import PropsTypes from 'prop-types'; import PropsTypes from 'prop-types';
import MiniChallenge from '../challenges_list/MiniChallenge'; import MiniChallenge from '../challenges_list/MiniChallenge';
import { marked } from 'marked';
const ReadmeStyle = styled(Body)` const ReadmeStyle = styled(Body)`
* {
font-weight: inherit;
}
h2 {
font-family: 'Kanit', sans-serif;
margin: 32px 0;
}
h3 { h3 {
font-family: 'Kanit', sans-serif; font-family: 'Kanit', sans-serif;
font-weight: 400; font-weight: inherit;
font-size: 18px; font-size: 18px;
line-height: 22px; line-height: 22px;
margin: 24px 0;
@media (min-width: ${({theme}) => theme.overMobile}) { @media (min-width: ${({theme}) => theme.overMobile}) {
font-size: 22px; font-size: 22px;
@ -62,13 +73,19 @@ const Readme = (props) => {
}, [props.challengeName]); }, [props.challengeName]);
const parseMarkdownResponse = (response) => { const parseMarkdownResponse = (response) => {
let result = markdown.toHTML(response); let result = marked.parse(response);
let regex = /<h1>[^<>]*<\/h1>/g; let regex = /<h3 /g;
result = result.replace(regex, ''); result = result.replace(regex, '<h4 ');
regex = /<h2>/g; regex = /<\/h3>/g;
result = result.replace(regex, '<h3>'); result = result.replace(regex, '</h4>');
regex = /<h2 /g;
result = result.replace(regex, '<h3 ');
regex = /<\/h2>/g; regex = /<\/h2>/g;
result = result.replace(regex, '</h3>'); result = result.replace(regex, '</h3>');
regex = /<h1 /g;
result = result.replace(regex, '<h2 ');
regex = /<\/h1>/g;
result = result.replace(regex, '</h2>');
return result; return result;
}; };
@ -82,15 +99,15 @@ const Readme = (props) => {
<InfoList iconsSize='24px' metric={props.metric} deadline={props.deadline}/> <InfoList iconsSize='24px' metric={props.metric} deadline={props.deadline}/>
</FlexColumn> </FlexColumn>
<FlexColumn alignmentX='flex-start' maxWidth='260px'> <FlexColumn alignmentX='flex-start' maxWidth='260px'>
<H2 as='h2'> {/* <H2 as='h2'>
Description Description
</H2> </H2> */}
<ReadmeStyle as={fullDescription ? 'article' : 'p'} dangerouslySetInnerHTML={{ <ReadmeStyle as={fullDescription ? 'article' : 'p'} dangerouslySetInnerHTML={{
__html: fullDescription __html: fullDescription
? parseMarkdownResponse(fullDescription) : props.description ? parseMarkdownResponse(fullDescription) : props.description
}}/> }}/>
</FlexColumn> </FlexColumn>
<FlexColumn gap='16px' alignmentX='flex-start' maxWidth='260px'> {/* <FlexColumn gap='16px' alignmentX='flex-start' maxWidth='260px'>
<H2 as='h2'> <H2 as='h2'>
Baseline Baseline
</H2> </H2>
@ -106,7 +123,7 @@ const Readme = (props) => {
</Medium> </Medium>
</Body> </Body>
</FlexColumn> </FlexColumn>
</FlexColumn> </FlexColumn> */}
</FlexColumn> </FlexColumn>
); );
}; };
@ -120,15 +137,15 @@ const Readme = (props) => {
</H2> </H2>
<InfoList iconsSize='32px' metric={props.metric} deadline={props.deadline}/> <InfoList iconsSize='32px' metric={props.metric} deadline={props.deadline}/>
</FlexColumn> </FlexColumn>
<FlexColumn alignmentX='flex-start' width='80%' maxWidth='1000px'> <FlexColumn alignmentX='flex-start' width='80%' maxWidth='1200px'>
<H2 as='h2'> {/* <H2 as='h2'>
Description Description
</H2> </H2> */}
<ReadmeStyle as={fullDescription ? 'article' : 'p'} dangerouslySetInnerHTML={{ <ReadmeStyle as={fullDescription ? 'section' : 'p'} dangerouslySetInnerHTML={{
__html: fullDescription ? parseMarkdownResponse(fullDescription) : props.description __html: fullDescription ? parseMarkdownResponse(fullDescription) : props.description
}}/> }}/>
</FlexColumn> </FlexColumn>
<FlexColumn gap='16px' alignmentX='flex-start' width='80%' maxWidth='1000px'> {/* <FlexColumn gap='16px' alignmentX='flex-start' width='80%' maxWidth='1000px'>
<H2 as='h2'> <H2 as='h2'>
Baseline Baseline
</H2> </H2>
@ -144,7 +161,7 @@ const Readme = (props) => {
</Medium> </Medium>
</Body> </Body>
</FlexColumn> </FlexColumn>
</FlexColumn> </FlexColumn> */}
</FlexColumn> </FlexColumn>
); );
}; };