Skip to content

Commit

Permalink
Merge pull request #107 from CS3219-AY2324S1/add-html-parsing
Browse files Browse the repository at this point in the history
Add html parsing
  • Loading branch information
szelongq authored Nov 14, 2023
2 parents 525d4ed + 893db09 commit 482570c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
14 changes: 14 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"axios": "^1.5.1",
"dotenv": "^16.3.1",
"firebase": "^10.4.0",
"html-entities": "^2.4.0",
"htmr": "^1.0.2",
"https-browserify": "^1.0.0",
"js-sha256": "^0.10.1",
"monaco-editor": "^0.44.0",
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/components/CollabProblemSolverLeft.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from "react";
import { Paper, Typography, Divider, CardMedia } from "@mui/material";
import { useData } from "../data/data.context";
import {parseHtmlDescription} from "../utils/utils";

function CollabProblemSolverLeft({
questionNumber,
Expand Down Expand Up @@ -43,10 +44,8 @@ function CollabProblemSolverLeft({
{question.title}
</Typography>
<Divider sx={{ marginBottom: 2, marginTop: 5 }} />
<Typography variant="body1" sx={{ marginBottom: 2, fontSize: "18px" }}>
{question.description.split("\\n").map((s, key) => {
return <p key={key}>{s}</p>;
})}
<Typography variant="body1" sx={{ marginBottom: 2, fontSize: "18px", overflowX: 'auto' }}>
{parseHtmlDescription(question.description)}
</Typography>
<Divider sx={{ marginBottom: 10 }} />
<Typography variant="h6" gutterBottom sx={{ fontSize: "18px" }}>
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/components/ProblemSolverLeft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CardMedia,
} from '@mui/material';
import { useData } from '../data/data.context';
import {parseHtmlDescription} from "../utils/utils";
// import { ClosedCaptionDisabledSharp } from '@mui/icons-material';

const ProblemSolverLeft = () => {
Expand Down Expand Up @@ -45,10 +46,8 @@ const ProblemSolverLeft = () => {
{question.title}
</Typography>
<Divider sx={{ marginBottom: 2, marginTop: 5 }} />
<Typography variant="body1" sx={{ marginBottom: 2, fontSize: '18px' }}>
{question.description.split("\\n").map((s, key) => {
return <p key={key}>{s}</p>;
})}
<Typography variant="body1" sx={{ marginBottom: 2, fontSize: '18px', overflowX: 'auto' }}>
{parseHtmlDescription(question.description)}
</Typography>
<Divider sx={{ marginBottom: 10 }} />
<Typography variant="h6" gutterBottom sx={{ fontSize: '18px' }}>
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/components/Questions/EditQuestionTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Grid from '@mui/material/Grid';
import Button from '@mui/material/Button';
import {Box} from "@mui/material";
import QuestionForm from "./QuestionForm";
import {parseHtmlDescription} from "../../utils/utils";

interface EditQuestionPreviewProps {
question: Question;
Expand Down Expand Up @@ -47,10 +48,8 @@ const EditQuestionTab: React.FC<EditQuestionPreviewProps> = ({question, onEdit,
<Typography variant="h5" gutterBottom component="div">
{question.title}
</Typography>
<Typography variant="body2" gutterBottom component="div" sx={{ whiteSpace: 'pre-line'}}>
{question.description.split("\\n").map((s, key) => {
return <p key={key}>{s}</p>;
})}
<Typography variant="body2" gutterBottom component="div">
{parseHtmlDescription(question.description)}
</Typography>
<br />
{question.constraints.length > 0 &&
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/components/Questions/QuestionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
Typography,
} from "@mui/material";
import { useData } from "../../data/data.context";
import {parseHtmlDescription} from "../../utils/utils";

interface Question {
id: string;
Expand Down Expand Up @@ -122,7 +123,7 @@ const InterviewQuestionsTable: React.FC = () => {
</MenuItem>
))}
</Select>
<div style={{ maxHeight: "300px", overflowY: "auto", width: "80%" }}>
<div style={{ maxHeight: "800px", overflowY: "auto", width: "80%" , display: "flex"}}>
<TableContainer
component={Paper}
style={{ margin: "10px", padding: "10px" }}
Expand All @@ -148,6 +149,7 @@ const InterviewQuestionsTable: React.FC = () => {
fontSize: "16px",
fontWeight: "bold",
textTransform: "initial",
textAlign: "left",
}}
>
{question.title}
Expand Down Expand Up @@ -201,7 +203,7 @@ const InterviewQuestionsTable: React.FC = () => {
<b>Difficulty:</b> {selectedQuestion.difficulty}
</Typography>
<Typography variant="body2" style={{ padding: "5px" }}>
<b>Description</b>: {selectedQuestion.description}
<b>Description</b>: {parseHtmlDescription(selectedQuestion.description)}
</Typography>
</DialogContent>
<DialogActions>
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/utils/utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {decode} from "html-entities";
import htmr from "htmr";
import {ReactNode} from "react";

export function parseHtmlDescription(description: string): ReactNode {
// Decode escaped HTML characters and add text wrap to pre tags in the question description
let decodedDescription = decode(description)
.replace(/<pre>/g, "<pre style=\"white-space: pre-wrap;\">");
return htmr(decodedDescription);
}

0 comments on commit 482570c

Please sign in to comment.