Skip to content

Commit

Permalink
fix: 修复代码高亮异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yhf2000 committed Sep 20, 2024
1 parent dae7bfa commit c7afb43
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Component/submission/Processing/Processing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {TestCaseProp} from "../TestCase";
import {connect} from "react-redux";
import {withRouter} from "react-router";
import {
langMap,
fileExtList2Lang,
RunningResultType,
RunningStateType,
StateList,
Expand Down Expand Up @@ -229,7 +229,7 @@ const Processing = (props: IProcessingProp & any) => {
content: (
<>
{!isValueEmpty(sf?.code) && sf?.judgeTemplateTitle !== undefined && (
<CodeHighlight code={sf?.code} lang={langMap[sf.judgeTemplateTitle]}/>
<CodeHighlight code={sf?.code} lang={fileExtList2Lang(sf.judgeTemplate.acceptFileExtensions)}/>
)}
{isValueEmpty(sf?.zipFileId) && isValueEmpty(sf?.code) && (
props.t("codeIsNotPublic")
Expand Down
56 changes: 44 additions & 12 deletions src/Type/ISubmission.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {JudgeTemplate} from "./IProblem";

export type TestCaseType =
"Pending" | "Running" | "Accepted" |
"WrongAnswer" | "TimeLimitExceeded" | "MemoryLimitExceeded" |
Expand Down Expand Up @@ -51,17 +53,38 @@ export const StateList =
"PresentationError", "SystemError", "Queueing", "Compiling", "Judging", "End", "Cancelled"]


export const langMap: any = {
"C++11": "cpp",
"C++14": "cpp",
"C++17": "cpp",
"C++20": "cpp",
"C11": "c",
"Java8": "java",
"Java11": "java",
"Python3.6": "python",
"Python3.11": "python",
"cpp11": "cpp"
// export const langMap: any = {
// "C++11": "cpp",
// "C++14": "cpp",
// "C++17": "cpp",
// "C++20": "cpp",
// "C11": "c",
// "Java8": "java",
// "Java11": "java",
// "Python3.6": "python",
// "Python3.11": "python",
// "cpp11": "cpp"
// }

export const ext2lang: any = {
"cpp": "cpp", ".cpp": "cpp",
"cc": "cpp", ".cc": "cpp",
"c++": "cpp", ".c++": "cpp",
"c": "c", ".c": "c",
"java": "java", ".java": "java",
"py": "python", ".py": "python",
"py3": "python", ".py3": "python",
"py2": "python", ".py2": "python",
}

export const fileExtList2Lang: any = (extList: string[]) => {
// 找到第一个合法的语言
for (let ext of extList) {
if (ext2lang[ext]) {
return ext2lang[ext]
}
}
return "cpp"
}

export interface checkPointType {
Expand All @@ -71,6 +94,14 @@ export interface checkPointType {
Memory: number
}

export interface JudgeTemplateType {
id: string
type: number
title: string
comment: string
acceptFileExtensions: string[]
}

export interface submissionInfoType {
timeLimit?: number
memoryLimit?: number
Expand All @@ -88,6 +119,7 @@ export interface submissionInfoType {
judgeTemplateId: string
judgeTemplateTitle: string
judgeTemplateType: number
judgeTemplate: JudgeTemplateType
problemCode: string
problemId: string
problemTitle: string
Expand Down Expand Up @@ -139,5 +171,5 @@ export interface SubmissionState {
TopSubmissionId?: string
TopSubmissionInfo?: TopSubmissionInfoType
SubmissionModalVis: boolean
submissionListInfo: {[key: string]: any}
submissionListInfo: { [key: string]: any }
}

0 comments on commit c7afb43

Please sign in to comment.