irongit

A Neovim plugin enabling you to solve LeetCode problems.

feat: better highlight

kawreauthored
parent 2bfa34acommit f7d58cb6a735eb69f3cc1fb00a7272520c6079dcBrowse files

5 files changed, +13 -21

+4-10lua/leetcode/parser/html.lua
@@ -232,8 +232,7 @@ end
232232 function Html:normalize()
233233 log.debug(self.str)
234234
235- self.str = self
236- .str
235+ self.str = self.str
237236 :gsub("​", "")
238237 :gsub("\r\n", "\n")
239238 :gsub("\t*<(/?li)>", "<%1>")
@@ -242,12 +241,8 @@ function Html:normalize()
242241 :gsub("<strong>(Input:?%s*)</strong>", "<input>%1</input>")
243242 :gsub("<strong>(Output:?%s*)</strong>", "<output>%1</output>")
244243 :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>")
251246 :gsub(
252247 "<p><strong[^>]*>(Example%s*%d*:?)%s*</strong></p>\n*",
253248 "\n\n<example>󰛨 %1</example>\n\n"
@@ -263,8 +258,7 @@ function Html:normalize()
263258 :gsub("\t", "&lctab;")
264259 :gsub("%s", "&nbsp;")
265260 :gsub("<[^>]*>", function(match) return match:gsub("&nbsp;", " ") 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;"
268262 end
269263
270264 -- Trim excessive lines
+1-0lua/leetcode/theme/default.lua
@@ -44,6 +44,7 @@ M.get = function()
4444 example = { fg = hl("DiagnosticHint").fg },
4545 constraints = { fg = hl("DiagnosticInfo").fg },
4646 header = { fg = hl("SpecialChar").fg, bold = true },
47+ followup = { fg = hl("Number").fg, bold = true },
4748
4849 indent = { fg = hl("Comment").fg },
4950 link = { fg = hl("Function").fg, underline = true },
+1-0lua/leetcode/theme/init.lua
@@ -24,6 +24,7 @@ local highlights = {
2424 input = "header",
2525 output = "header",
2626 explanation = "header",
27+ followup = "followup",
2728
2829 -- pre = "",
2930 -- span = "",
+5-8lua/leetcode/ui/hints.lua → lua/leetcode/ui/info.lua
@@ -45,7 +45,7 @@ function Info:mount()
4545 end
4646
4747 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))
4949 else
5050 table.insert(
5151 nodes,
@@ -58,9 +58,6 @@ function Info:mount()
5858 for _, q in ipairs(self.parent.q.similar) do
5959 local line = NuiLine()
6060
61- local lock = not config.auth.is_premium and q.paid_only and "" or " "
62- line:append(lock .. " ", "leetcode_medium")
63-
6461 local hl = {
6562 ["Easy"] = "leetcode_easy",
6663 ["Medium"] = "leetcode_medium",
@@ -69,15 +66,15 @@ function Info:mount()
6966 line:append("󱓻 ", hl[q.difficulty])
7067 line:append(q.title)
7168
69+ local lock = not config.auth.is_premium and q.paid_only and "  Premium" or ""
70+ line:append(lock, "leetcode_medium")
71+
7272 table.insert(sim_questions, NuiTree.Node({ text = line, question = q }))
7373 end
7474 if not vim.tbl_isempty(sim_questions) then
7575 table.insert(
7676 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)
8178 )
8279 else
8380 table.insert(
+2-3lua/leetcode/ui/question.lua
@@ -4,8 +4,7 @@ local Description = require("leetcode.ui.description")
44 local api_question = require("leetcode.api.question")
55 local Console = require("leetcode.ui.console")
66 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")
98
109 ---@class lc.Question
1110 ---@field file Path
@@ -63,7 +62,7 @@ function Question:mount()
6362
6463 self.description = Description:init(self)
6564 self.console = Console:init(self)
66- self.hints = Hints:init(self)
65+ self.hints = Info:init(self)
6766
6867 return self
6968 end