diff --git a/modules/judge.js b/modules/judge.js index d6fa6c3..89d9719 100644 --- a/modules/judge.js +++ b/modules/judge.js @@ -67,6 +67,7 @@ app.get('/judge_detail/:id', async (req, res) => { if (!await judge.isAllowedSeeCodeBy(res.locals.user)) throw 'Permission denied'; judge.code = syzoj.utils.highlight(judge.code, judge.language); + if (judge.result.compiler_output) judge.result.compiler_output = syzoj.utils.ansiToHTML(judge.result.compiler_output); res.render('judge_detail', { judge: judge diff --git a/package.json b/package.json index 2aa5c0d..918cdf3 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "homepage": "https://github.com/syzoj/syzoj#readme", "dependencies": { "adm-zip": "^0.4.7", + "ansi-to-html": "^0.4.2", "babel-cli": "^6.18.0", "babel-preset-es2017": "^6.16.0", "body-parser": "^1.15.2", @@ -41,6 +42,6 @@ "request": "^2.74.0", "sequelize": "^3.24.3", "sqlite3": "^3.1.4", - "syzoj-divine": "^1.0.0" + "syzoj-divine": "^1.0.0" } } diff --git a/utility.js b/utility.js index fda5b52..ccadc95 100644 --- a/utility.js +++ b/utility.js @@ -123,5 +123,10 @@ module.exports = { } return res.filter(x => x); + }, + ansiToHTML(s) { + let Convert = require('ansi-to-html'); + let convert = new Convert({ escapeXML: true }); + return convert.toHtml(s); } }; diff --git a/views/judge_detail.ejs b/views/judge_detail.ejs index 7f669b8..9dda142 100644 --- a/views/judge_detail.ejs +++ b/views/judge_detail.ejs @@ -28,7 +28,7 @@
<%- judge.code %>
<% if (judge.result.compiler_output && judge.result.status === 'Compile Error') { %>

编译信息

-
<%= judge.result.compiler_output %>
+
<%- judge.result.compiler_output %>
<% } else { %>
<% for (let i = 0; i < judge.result.case_num; i++) { %>