diff --git a/src/hooks/problem.ts b/src/hooks/problem.ts index 1a1a84118..1628fafc7 100644 --- a/src/hooks/problem.ts +++ b/src/hooks/problem.ts @@ -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( @@ -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) => { diff --git a/src/pipes/problem.ts b/src/pipes/problem.ts new file mode 100644 index 000000000..a179a6ca6 --- /dev/null +++ b/src/pipes/problem.ts @@ -0,0 +1,4 @@ +// Remove the first H1 title from the markdown content +export const TrimMarkdownTitlePipe = (content: string): string => { + return content.replace(/^# .*\n/, ""); +};