Skip to content

Commit

Permalink
Force trim markdown H1 for problem description
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Sep 28, 2024
1 parent f3fef00 commit ade53a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hooks/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as ProblemServiceModel from "@/models/service/problem";
import * as ProblemService from "@/apis/problem";
import { useDispatch } from "react-redux";
import { AddMessageSagaPattern } from "@/store/sagas/message";
import { TrimMarkdownTitlePipe } from "@/pipes/problem";

export const useProblem = (slug: string, fallback?: () => void) => {
const [problem, setProblem] = useState<ProblemServiceModel.Problem | null>(
Expand All @@ -18,6 +19,7 @@ export const useProblem = (slug: string, fallback?: () => void) => {
useEffect(() => {
ProblemService.getProblem(slug)
.then((res) => {
res.description = TrimMarkdownTitlePipe(res.description);
setProblem(res);
})
.catch((err) => {
Expand Down
4 changes: 4 additions & 0 deletions src/pipes/problem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Remove the first H1 title from the markdown content
export const TrimMarkdownTitlePipe = (content: string): string => {
return content.replace(/^# .*\n/, "");
};

0 comments on commit ade53a4

Please sign in to comment.