|
1 | 1 | 'use strict';
|
2 | 2 | var util = require('util');
|
3 | 3 |
|
| 4 | +var cheerio = require('cheerio'); |
| 5 | +var he = require('he'); |
4 | 6 | var _ = require('underscore');
|
5 | 7 | var childProcess = require('child_process');
|
6 | 8 |
|
@@ -95,6 +97,19 @@ function genFileName(problem, opts) {
|
95 | 97 | }
|
96 | 98 | }
|
97 | 99 |
|
| 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 | + |
98 | 113 | function showProblem(problem, argv) {
|
99 | 114 | const taglist = [problem.category]
|
100 | 115 | .concat(problem.companies || [])
|
@@ -174,7 +189,7 @@ function showProblem(problem, argv) {
|
174 | 189 | log.printf('* Source Code: %s', chalk.yellow.underline(filename));
|
175 | 190 |
|
176 | 191 | log.info();
|
177 |
| - log.info(problem.desc); |
| 192 | + log.info(cleanProblemDesc(problem.desc)); |
178 | 193 | }
|
179 | 194 |
|
180 | 195 | cmd.handler = function(argv) {
|
|
0 commit comments