diff --git a/src/webview/leetCodePreviewProvider.ts b/src/webview/leetCodePreviewProvider.ts index 78b4099..8d73c1f 100644 --- a/src/webview/leetCodePreviewProvider.ts +++ b/src/webview/leetCodePreviewProvider.ts @@ -147,34 +147,37 @@ class LeetCodePreviewProvider extends LeetCodeWebview { // await commands.executeCommand("workbench.action.toggleSidebarVisibility"); // } - private parseDescription(descString: string, problem: IProblem): IDescription { - const [ - /* title */, , - url, , - /* tags */, , - /* langs */, , - category, - difficulty, - likes, - dislikes, - /* accepted */, - /* submissions */, - /* testcase */, , - ...body - ] = descString.split("\n"); + private parseDescription(descString, problem) { + // Parse body by looking for the first html tag + const bodyStartIdx = descString.search(/<.*>/); + const bodyRaw = descString.substring(bodyStartIdx); + + const { name: title, tags, companies } = problem; return { - title: problem.name, - url, - tags: problem.tags, - companies: problem.companies, - category: category.slice(2), - difficulty: difficulty.slice(2), - likes: likes.split(": ")[1].trim(), - dislikes: dislikes.split(": ")[1].trim(), - body: body.join("\n").replace(/
[\r\n]*([^]+?)[\r\n]*<\/pre>/g, ""), + title, + tags, + companies, + url: descString.match(/https:.*leetcode.*/)?.[0] || "??", + // Category is the first element in list + category: descString.match(/\*.*/)?.[0]?.slice(2) || "??", + // Difficulty is the first element in list with a percentage sign + difficulty: descString.match(/.*\%.*/)?.[0]?.slice(2) || "??", + likes: + descString + .match(/Likes.*?\n/)?.[0] + ?.split(": ")[1] + ?.trim() || "0", + dislikes: + descString + .match(/Dislikes.*?\n/)?.[0] + ?.split(": ")[1] + ?.trim() || "0", + body: bodyRaw.replace( + /$1
[\r\n]*([^]+?)[\r\n]*<\/pre>/g, + "" + ), }; - } - + } private getDiscussionLink(url: string): string { const endPoint: string = getLeetCodeEndpoint(); if (endPoint === Endpoint.LeetCodeCN) {$1
pFad - Phonifier reborn Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: