Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit eb3fc0e

Browse files
committed
remove html tag for show command
Signed-off-by: Scott Lee <soulindarkness@gmail.com>
1 parent bc5c127 commit eb3fc0e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/commands/show.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22
var util = require('util');
33

4+
var cheerio = require('cheerio');
5+
var he = require('he');
46
var _ = require('underscore');
57
var childProcess = require('child_process');
68

@@ -95,6 +97,19 @@ function genFileName(problem, opts) {
9597
}
9698
}
9799

100+
// removes html tags from problem description before printing it to the terminal
101+
function cleanProblemDesc(desc){
102+
// Replace <sup/> with '^' as the power operator
103+
desc = desc.replace(/<\/sup>/gm, '').replace(/<sup>/gm, '^');
104+
desc = he.decode(cheerio.load(desc).root().text());
105+
// NOTE: wordwrap internally uses '\n' as EOL, so here we have to
106+
// remove all '\r' in the raw string.
107+
desc = desc.replace(/\r\n/g, '\n').replace(/^ /mg, '⁠');
108+
// const wrap = require('wordwrap')(79);
109+
// desc = wrap(desc);
110+
return desc;
111+
}
112+
98113
function showProblem(problem, argv) {
99114
const taglist = [problem.category]
100115
.concat(problem.companies || [])
@@ -174,7 +189,7 @@ function showProblem(problem, argv) {
174189
log.printf('* Source Code: %s', chalk.yellow.underline(filename));
175190

176191
log.info();
177-
log.info(problem.desc);
192+
log.info(cleanProblemDesc(problem.desc));
178193
}
179194

180195
cmd.handler = function(argv) {

0 commit comments

Comments
 (0)