A Neovim plugin enabling you to solve LeetCode problems.
feat: better highlight
5 files changed, +13 -21
+4-10lua/leetcode/parser/html.lua
| @@ -232,8 +232,7 @@ end | ||
| 232 | 232 | function Html:normalize() |
| 233 | 233 | log.debug(self.str) |
| 234 | 234 | |
| 235 | - self.str = self | |
| 236 | - .str | |
| 235 | + self.str = self.str | |
| 237 | 236 | :gsub("", "") |
| 238 | 237 | :gsub("\r\n", "\n") |
| 239 | 238 | :gsub("\t*<(/?li)>", "<%1>") |
| @@ -242,12 +241,8 @@ function Html:normalize() | ||
| 242 | 241 | :gsub("<strong>(Input:?%s*)</strong>", "<input>%1</input>") |
| 243 | 242 | :gsub("<strong>(Output:?%s*)</strong>", "<output>%1</output>") |
| 244 | 243 | :gsub("<strong>(Explanation:?%s*)</strong>", "<explanation>%1</explanation>") |
| 245 | - -- :gsub( | |
| 246 | - -- "\t*<(li[^>]*)>(.-)\t*</(li)>", | |
| 247 | - -- "<%1>%2</%3>\n" | |
| 248 | - -- ) | |
| 249 | - -- :gsub("\t*<(ul[^>]*)>(.-)\t*</(ul)>", "<%1>%2</%3>\n") | |
| 250 | - -- :gsub("\t*<(ol[^>]*)>(.-)\t*</(ol)>", "<%1>%2</%3>\n") | |
| 244 | + :gsub("<strong>(Follow-up:%s*)</strong>", "<followup>%1</followup>") | |
| 245 | + :gsub("<strong>(Note:%s*)</strong>", "<followup>%1</followup>") | |
| 251 | 246 | :gsub( |
| 252 | 247 | "<p><strong[^>]*>(Example%s*%d*:?)%s*</strong></p>\n*", |
| 253 | 248 | "\n\n<example> %1</example>\n\n" |
| @@ -263,8 +258,7 @@ function Html:normalize() | ||
| 263 | 258 | :gsub("\t", "&lctab;") |
| 264 | 259 | :gsub("%s", " ") |
| 265 | 260 | :gsub("<[^>]*>", function(match) return match:gsub(" ", " ") end) |
| 266 | - :gsub("<a[^>]*>(.-)</a>", function(match) return match:gsub("&#?%w+;", utils.entity) end) | |
| 267 | - .. "&lcend;" | |
| 261 | + :gsub("<a[^>]*>(.-)</a>", function(match) return match:gsub("&#?%w+;", utils.entity) end) .. "&lcend;" | |
| 268 | 262 | end |
| 269 | 263 | |
| 270 | 264 | -- Trim excessive lines |
+1-0lua/leetcode/theme/default.lua
| @@ -44,6 +44,7 @@ M.get = function() | ||
| 44 | 44 | example = { fg = hl("DiagnosticHint").fg }, |
| 45 | 45 | constraints = { fg = hl("DiagnosticInfo").fg }, |
| 46 | 46 | header = { fg = hl("SpecialChar").fg, bold = true }, |
| 47 | + followup = { fg = hl("Number").fg, bold = true }, | |
| 47 | 48 | |
| 48 | 49 | indent = { fg = hl("Comment").fg }, |
| 49 | 50 | link = { fg = hl("Function").fg, underline = true }, |
+1-0lua/leetcode/theme/init.lua
| @@ -24,6 +24,7 @@ local highlights = { | ||
| 24 | 24 | input = "header", |
| 25 | 25 | output = "header", |
| 26 | 26 | explanation = "header", |
| 27 | + followup = "followup", | |
| 27 | 28 | |
| 28 | 29 | -- pre = "", |
| 29 | 30 | -- span = "", |
+5-8lua/leetcode/ui/hints.lua → lua/leetcode/ui/info.lua
| @@ -45,7 +45,7 @@ function Info:mount() | ||
| 45 | 45 | end |
| 46 | 46 | |
| 47 | 47 | if not vim.tbl_isempty(topics) then |
| 48 | - table.insert(nodes, NuiTree.Node({ text = NuiText("Topics ", "leetcode_list") }, topics)) | |
| 48 | + table.insert(nodes, NuiTree.Node({ text = NuiText("Topics ", "Number") }, topics)) | |
| 49 | 49 | else |
| 50 | 50 | table.insert( |
| 51 | 51 | nodes, |
| @@ -58,9 +58,6 @@ function Info:mount() | ||
| 58 | 58 | for _, q in ipairs(self.parent.q.similar) do |
| 59 | 59 | local line = NuiLine() |
| 60 | 60 | |
| 61 | - local lock = not config.auth.is_premium and q.paid_only and "" or " " | |
| 62 | - line:append(lock .. " ", "leetcode_medium") | |
| 63 | - | |
| 64 | 61 | local hl = { |
| 65 | 62 | ["Easy"] = "leetcode_easy", |
| 66 | 63 | ["Medium"] = "leetcode_medium", |
| @@ -69,15 +66,15 @@ function Info:mount() | ||
| 69 | 66 | line:append(" ", hl[q.difficulty]) |
| 70 | 67 | line:append(q.title) |
| 71 | 68 | |
| 69 | + local lock = not config.auth.is_premium and q.paid_only and " Premium" or "" | |
| 70 | + line:append(lock, "leetcode_medium") | |
| 71 | + | |
| 72 | 72 | table.insert(sim_questions, NuiTree.Node({ text = line, question = q })) |
| 73 | 73 | end |
| 74 | 74 | if not vim.tbl_isempty(sim_questions) then |
| 75 | 75 | table.insert( |
| 76 | 76 | nodes, |
| 77 | - NuiTree.Node( | |
| 78 | - { text = NuiText("Similar Questions ", "leetcode_list") }, | |
| 79 | - sim_questions | |
| 80 | - ) | |
| 77 | + NuiTree.Node({ text = NuiText("Similar Questions ", "leetcode_ref") }, sim_questions) | |
| 81 | 78 | ) |
| 82 | 79 | else |
| 83 | 80 | table.insert( |
+2-3lua/leetcode/ui/question.lua
| @@ -4,8 +4,7 @@ local Description = require("leetcode.ui.description") | ||
| 4 | 4 | local api_question = require("leetcode.api.question") |
| 5 | 5 | local Console = require("leetcode.ui.console") |
| 6 | 6 | local utils = require("leetcode.utils") |
| 7 | -local async = require("plenary.async") | |
| 8 | -local Hints = require("leetcode.ui.hints") | |
| 7 | +local Info = require("leetcode.ui.info") | |
| 9 | 8 | |
| 10 | 9 | ---@class lc.Question |
| 11 | 10 | ---@field file Path |
| @@ -63,7 +62,7 @@ function Question:mount() | ||
| 63 | 62 | |
| 64 | 63 | self.description = Description:init(self) |
| 65 | 64 | self.console = Console:init(self) |
| 66 | - self.hints = Hints:init(self) | |
| 65 | + self.hints = Info:init(self) | |
| 67 | 66 | |
| 68 | 67 | return self |
| 69 | 68 | end |