From bc5c1272055f22dd6d83ece8180f4f42154c8aaf Mon Sep 17 00:00:00 2001 From: Scott Lee Date: Mon, 22 Nov 2021 00:19:52 +0900 Subject: [PATCH 1/2] change plugin url Signed-off-by: Scott Lee --- lib/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index 82cfee17..e47796fa 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' }, }, From eb3fc0e26205bada24ae91e01eb366b2e71bd440 Mon Sep 17 00:00:00 2001 From: Scott Lee Date: Mon, 22 Nov 2021 00:20:29 +0900 Subject: [PATCH 2/2] remove html tag for show command Signed-off-by: Scott Lee --- lib/commands/show.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/commands/show.js b/lib/commands/show.js index 93f643e2..adcca726 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) {