diff --git a/lib/commands/show.js b/lib/commands/show.js
index 56b9341e..a256ea21 100644
--- a/lib/commands/show.js
+++ b/lib/commands/show.js
@@ -1,6 +1,8 @@
'use strict';
var util = require('util');
+var cheerio = require('cheerio');
+var he = require('he');
var _ = require('underscore');
var childProcess = require('child_process');
@@ -89,6 +91,19 @@ function genFileName(problem, opts) {
}
}
+// removes html tags from problem description before printing it to the terminal
+function cleanProblemDesc(desc){
+ // Replace with '^' as the power operator
+ desc = desc.replace(/<\/sup>/gm, '').replace(//gm, '^');
+ desc = he.decode(cheerio.load(desc).root().text());
+ // NOTE: wordwrap internally uses '\n' as EOL, so here we have to
+ // remove all '\r' in the raw string.
+ desc = desc.replace(/\r\n/g, '\n').replace(/^ /mg, '');
+ // const wrap = require('wordwrap')(79);
+ // desc = wrap(desc);
+ return desc;
+}
+
function showProblem(problem, argv) {
const taglist = [problem.category]
.concat(problem.companies || [])
@@ -168,7 +183,7 @@ function showProblem(problem, argv) {
log.printf('* Source Code: %s', chalk.yellow.underline(filename));
log.info();
- log.info(problem.desc);
+ log.info(cleanProblemDesc(problem.desc));
}
cmd.handler = function(argv) {