Skip to content

remove html tag shown in problem description (in terminal) #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/commands/show.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -89,6 +91,19 @@ function genFileName(problem, opts) {
}
}

// removes html tags from problem description before printing it to the terminal
function cleanProblemDesc(desc){
// Replace <sup/> with '^' as the power operator
desc = desc.replace(/<\/sup>/gm, '').replace(/<sup>/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 || [])
Expand Down Expand Up @@ -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) {
Expand Down