A Neovim plugin enabling you to solve LeetCode problems.
fix: hints text
7 files changed, +130 -16
+21-0lua/leetcode-ui/group/init.lua
| @@ -11,6 +11,27 @@ local log = require("leetcode.logger") | ||
| 11 | 11 | ---@field _ lc.ui.Group.params | lines.params |
| 12 | 12 | local Group = Lines:extend("LeetGroup") |
| 13 | 13 | |
| 14 | +function Group:lines() | |
| 15 | + local tbl = {} | |
| 16 | + for _, item in ipairs(self:contents()) do | |
| 17 | + self:lines_helper(item, tbl) | |
| 18 | + end | |
| 19 | + return tbl | |
| 20 | +end | |
| 21 | + | |
| 22 | +---@private | |
| 23 | +---@param tbl table | |
| 24 | +function Group:lines_helper(item, tbl) -- | |
| 25 | + if item.class and item.class.name == "LeetLine" then | |
| 26 | + table.insert(tbl, item) | |
| 27 | + return | |
| 28 | + end | |
| 29 | + | |
| 30 | + for _, c in ipairs(item:contents()) do | |
| 31 | + self:lines_helper(c, tbl) | |
| 32 | + end | |
| 33 | +end | |
| 34 | + | |
| 14 | 35 | function Group:contents() |
| 15 | 36 | local items = utils.shallowcopy(self._.items) |
| 16 | 37 |
+1-1lua/leetcode-ui/group/tag/init.lua
| @@ -51,7 +51,7 @@ function Tag.normalize(text) | ||
| 51 | 51 | :gsub("\t", "&lctab;") |
| 52 | 52 | :gsub("%s", " ") |
| 53 | 53 | :gsub("<[^>]*>", function(match) return match:gsub(" ", " ") end) |
| 54 | - -- :gsub("<a[^>]*>(.-)</a>", function(match) return match:gsub("&#?%w+;", utils.entity) end) | |
| 54 | + :gsub("<a[^>]*>(.-)</a>", function(match) return match:gsub("&#?%w+;", utils.entity) end) | |
| 55 | 55 | |
| 56 | 56 | log.debug(text) |
| 57 | 57 | log.debug(norm:gsub("&lcnl;", "&lcnl;\n"), false) |
+45-0lua/leetcode-ui/group/tag/sub.lua
| @@ -5,6 +5,51 @@ local log = require("leetcode.logger") | ||
| 5 | 5 | ---@class lc.ui.Tag.sub : lc.ui.Tag |
| 6 | 6 | local Sub = Tag:extend("LeetTagSub") |
| 7 | 7 | |
| 8 | +local subscript = { | |
| 9 | + ["0"] = "₀", | |
| 10 | + ["1"] = "₁", | |
| 11 | + ["2"] = "₂", | |
| 12 | + ["3"] = "₃", | |
| 13 | + ["4"] = "₄", | |
| 14 | + ["5"] = "₅", | |
| 15 | + ["6"] = "₆", | |
| 16 | + ["7"] = "₇", | |
| 17 | + ["8"] = "₈", | |
| 18 | + ["9"] = "₉", | |
| 19 | + ["a"] = "ₐ", | |
| 20 | + ["b"] = "♭", | |
| 21 | + ["c"] = "꜀", | |
| 22 | + ["d"] = "ᑯ", | |
| 23 | + ["e"] = "ₑ", | |
| 24 | + ["f"] = "բ", | |
| 25 | + ["g"] = "₉", | |
| 26 | + ["h"] = "ₕ", | |
| 27 | + ["i"] = "ᵢ", | |
| 28 | + ["j"] = "ⱼ", | |
| 29 | + ["k"] = "ₖ", | |
| 30 | + ["l"] = "ₗ", | |
| 31 | + ["m"] = "ₘ", | |
| 32 | + ["n"] = "ₙ", | |
| 33 | + ["o"] = "ₒ", | |
| 34 | + ["p"] = "ₚ", | |
| 35 | + ["q"] = "ɋ", | |
| 36 | + ["r"] = "ᵣ", | |
| 37 | + ["s"] = "ₛ", | |
| 38 | + ["t"] = "ₜ", | |
| 39 | + ["u"] = "ᵤ", | |
| 40 | + ["v"] = "ᵥ", | |
| 41 | + ["w"] = "w", | |
| 42 | + ["x"] = "ₓ", | |
| 43 | + ["y"] = "y", | |
| 44 | + ["z"] = "z", | |
| 45 | +} | |
| 46 | + | |
| 47 | +-- function Sub:append(content, highlight) | |
| 48 | +-- content = content:gsub(".", function(match) return subscript[match:lower()] or match end) | |
| 49 | +-- | |
| 50 | +-- Sub.super.append(self, content, highlight) | |
| 51 | +-- end | |
| 52 | + | |
| 8 | 53 | function Sub:parse_node() |
| 9 | 54 | self:append("_") |
| 10 | 55 |
+45-0lua/leetcode-ui/group/tag/sup.lua
| @@ -6,6 +6,51 @@ local log = require("leetcode.logger") | ||
| 6 | 6 | ---@class lc.ui.Tag.sup : lc.ui.Tag |
| 7 | 7 | local Sup = Tag:extend("LeetTagSup") |
| 8 | 8 | |
| 9 | +local superscript = { | |
| 10 | + ["0"] = "⁰", | |
| 11 | + ["1"] = "¹", | |
| 12 | + ["2"] = "²", | |
| 13 | + ["3"] = "³", | |
| 14 | + ["4"] = "⁴", | |
| 15 | + ["5"] = "⁵", | |
| 16 | + ["6"] = "⁶", | |
| 17 | + ["7"] = "⁷", | |
| 18 | + ["8"] = "⁸", | |
| 19 | + ["9"] = "⁹", | |
| 20 | + ["a"] = "ᵃ", | |
| 21 | + ["b"] = "ᵇ", | |
| 22 | + ["c"] = "ᶜ", | |
| 23 | + ["d"] = "ᵈ", | |
| 24 | + ["e"] = "ᵉ", | |
| 25 | + ["f"] = "ᶠ", | |
| 26 | + ["g"] = "ᵍ", | |
| 27 | + ["h"] = "ʰ", | |
| 28 | + ["i"] = "ⁱ", | |
| 29 | + ["j"] = "ʲ", | |
| 30 | + ["k"] = "ᵏ", | |
| 31 | + ["l"] = "ˡ", | |
| 32 | + ["m"] = "ᵐ", | |
| 33 | + ["n"] = "ⁿ", | |
| 34 | + ["o"] = "ᵒ", | |
| 35 | + ["p"] = "ᵖ", | |
| 36 | + ["q"] = "ᵠ", | |
| 37 | + ["r"] = "ʳ", | |
| 38 | + ["s"] = "ˢ", | |
| 39 | + ["t"] = "ᵗ", | |
| 40 | + ["u"] = "ᵘ", | |
| 41 | + ["v"] = "ᵛ", | |
| 42 | + ["w"] = "ʷ", | |
| 43 | + ["x"] = "ˣ", | |
| 44 | + ["y"] = "ʸ", | |
| 45 | + ["z"] = "ᶻ", | |
| 46 | +} | |
| 47 | + | |
| 48 | +-- function Sup:append(content, highlight) | |
| 49 | +-- content = content:gsub(".", function(match) return superscript[match:lower()] or match end) | |
| 50 | +-- | |
| 51 | +-- Sup.super.append(self, content, highlight) | |
| 52 | +-- end | |
| 53 | + | |
| 9 | 54 | function Sup:parse_node() |
| 10 | 55 | self:append("^") |
| 11 | 56 |
+14-13lua/leetcode-ui/popup/info.lua
| @@ -4,6 +4,7 @@ local t = require("leetcode.translator") | ||
| 4 | 4 | local Line = require("leetcode-ui.line") |
| 5 | 5 | local NuiTree = require("nui.tree") |
| 6 | 6 | local SimilarQuestions = require("leetcode-ui.group.similar-questions") |
| 7 | +local Parser = require("leetcode.parser") | |
| 7 | 8 | |
| 8 | 9 | local config = require("leetcode.config") |
| 9 | 10 | local utils = require("leetcode.utils") |
| @@ -13,9 +14,9 @@ local log = require("leetcode.logger") | ||
| 13 | 14 | ---@field popup NuiPopup |
| 14 | 15 | ---@field question lc.ui.Question |
| 15 | 16 | ---@field hints table[] |
| 16 | -local InfoPopup = Popup:extend("LeetInfoPopup") | |
| 17 | +local Info = Popup:extend("LeetInfoPopup") | |
| 17 | 18 | |
| 18 | -function InfoPopup:similar_questions_node() | |
| 19 | +function Info:similar_questions_node() | |
| 19 | 20 | local nodes = SimilarQuestions:to_nodes(self.question.q.similar) |
| 20 | 21 | |
| 21 | 22 | if not vim.tbl_isempty(nodes) then |
| @@ -30,9 +31,10 @@ function InfoPopup:similar_questions_node() | ||
| 30 | 31 | end |
| 31 | 32 | end |
| 32 | 33 | |
| 33 | -function InfoPopup:hints_node() | |
| 34 | +function Info:hints_node() | |
| 34 | 35 | local hints = {} |
| 35 | 36 | for i, hint_txt in ipairs(self.hints) do |
| 37 | + log.info(self.hints) | |
| 36 | 38 | local line = Line() |
| 37 | 39 | |
| 38 | 40 | line:append(tostring(i), "leetcode_list") |
| @@ -49,7 +51,7 @@ function InfoPopup:hints_node() | ||
| 49 | 51 | end |
| 50 | 52 | end |
| 51 | 53 | |
| 52 | -function InfoPopup:topics_node() | |
| 54 | +function Info:topics_node() | |
| 53 | 55 | local topics = {} |
| 54 | 56 | for _, topic in ipairs(self.question.q.topic_tags) do |
| 55 | 57 | local line = Line() |
| @@ -67,7 +69,7 @@ function InfoPopup:topics_node() | ||
| 67 | 69 | end |
| 68 | 70 | end |
| 69 | 71 | |
| 70 | -function InfoPopup:populate() | |
| 72 | +function Info:populate() | |
| 71 | 73 | local nodes = { |
| 72 | 74 | self:hints_node(), |
| 73 | 75 | NuiTree.Node({ text = "" }), |
| @@ -89,9 +91,8 @@ function InfoPopup:populate() | ||
| 89 | 91 | else |
| 90 | 92 | if type(node.text) == "string" then |
| 91 | 93 | line:append(" ") |
| 92 | - local parser = require("leetcode.parser") | |
| 93 | - local txt = parser:parse(node.text) | |
| 94 | - if txt:contents()[1] then line:append(txt:contents()[1]) end | |
| 94 | + local txt = Parser:parse(node.text) | |
| 95 | + if txt:lines()[1] then line:append(txt:lines()[1]) end | |
| 95 | 96 | else |
| 96 | 97 | line:append(node.text) |
| 97 | 98 | end |
| @@ -119,8 +120,8 @@ function InfoPopup:populate() | ||
| 119 | 120 | end, { noremap = true, nowait = true }) |
| 120 | 121 | end |
| 121 | 122 | |
| 122 | -function InfoPopup:mount() | |
| 123 | - InfoPopup.super.mount(self) | |
| 123 | +function Info:mount() | |
| 124 | + Info.super.mount(self) | |
| 124 | 125 | |
| 125 | 126 | self:populate() |
| 126 | 127 | |
| @@ -140,8 +141,8 @@ function InfoPopup:mount() | ||
| 140 | 141 | end |
| 141 | 142 | |
| 142 | 143 | ---@param parent lc.ui.Question |
| 143 | -function InfoPopup:init(parent) | |
| 144 | - InfoPopup.super.init(self, { | |
| 144 | +function Info:init(parent) | |
| 145 | + Info.super.init(self, { | |
| 145 | 146 | position = "50%", |
| 146 | 147 | size = { |
| 147 | 148 | width = "50%", |
| @@ -173,6 +174,6 @@ function InfoPopup:init(parent) | ||
| 173 | 174 | end |
| 174 | 175 | |
| 175 | 176 | ---@type fun(parent: lc.ui.Question): lc.ui.InfoPopup |
| 176 | -local LeetInfoPopup = InfoPopup | |
| 177 | +local LeetInfoPopup = Info | |
| 177 | 178 | |
| 178 | 179 | return LeetInfoPopup |
+1-0lua/leetcode/theme/default.lua
| @@ -60,6 +60,7 @@ M.get = function() | ||
| 60 | 60 | link = { fg = hl("Function").fg, underline = true }, |
| 61 | 61 | list = { fg = hl("SpecialChar").fg }, |
| 62 | 62 | ref = { fg = hl("Tag").fg }, |
| 63 | + su = { fg = hl("Number").fg }, | |
| 63 | 64 | |
| 64 | 65 | -- calendar |
| 65 | 66 | calendar_0 = { fg = "#45475b" }, |
+3-2lua/leetcode/theme/init.lua
| @@ -26,6 +26,9 @@ local highlights = { | ||
| 26 | 26 | explanation = "header", |
| 27 | 27 | followup = "followup", |
| 28 | 28 | |
| 29 | + sup = "su", | |
| 30 | + sub = "su", | |
| 31 | + | |
| 29 | 32 | -- pre = "", |
| 30 | 33 | -- span = "", |
| 31 | 34 | -- p = "", |
| @@ -33,8 +36,6 @@ local highlights = { | ||
| 33 | 36 | -- ol = "", |
| 34 | 37 | -- li = "", |
| 35 | 38 | -- font = "", |
| 36 | - sup = "header", | |
| 37 | - sub = "header", | |
| 38 | 39 | -- small = "", |
| 39 | 40 | -- div = "", |
| 40 | 41 | } |