Browse Source

Preserve color on compiler output

pull/6/head
Menci 8 years ago
parent
commit
dd8519106a
  1. 1
      modules/judge.js
  2. 3
      package.json
  3. 5
      utility.js
  4. 2
      views/judge_detail.ejs

1
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

3
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"
}
}

5
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);
}
};

2
views/judge_detail.ejs

@ -28,7 +28,7 @@
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%- judge.code %></code></pre></div>
<% if (judge.result.compiler_output && judge.result.status === 'Compile Error') { %>
<h3 class="ui header">编译信息</h3>
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%= judge.result.compiler_output %></code></pre></div>
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%- judge.result.compiler_output %></code></pre></div>
<% } else { %>
<div class="ui styled fluid accordion">
<% for (let i = 0; i < judge.result.case_num; i++) { %>

Loading…
Cancel
Save