diff --git a/lib/commands/show.js b/lib/commands/show.js index 93f643e..adcca72 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'); @@ -95,6 +97,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 || []) @@ -174,7 +189,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) { diff --git a/lib/config.js b/lib/config.js index 82cfee1..e47796f 100644 --- a/lib/config.js +++ b/lib/config.js @@ -61,7 +61,7 @@ const DEFAULT_CONFIG = { verify: 'https://leetcode.com/submissions/detail/$id/check/', favorites: 'https://leetcode.com/list/api/questions', favorite_delete: 'https://leetcode.com/list/api/questions/$hash/$id', - plugin: 'https://raw.githubusercontent.com/leetcode-tools/leetcode-cli/master/lib/plugins/$name.js' + plugin: 'https://raw.githubusercontent.com/leetcode-tools/leetcode-cli-plugins/master/plugins/$name.js' }, },