Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8f35246

Browse files
committed
fix: sub, sup tags highlight
1 parent 81585d2 commit 8f35246

File tree

6 files changed

+17
-26
lines changed

6 files changed

+17
-26
lines changed

lua/leetcode-ui/group/tag/init.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ function Tag.normalize(text)
5959
return norm
6060
end
6161

62-
function Tag:add_indent(item)
62+
function Tag:add_indent(item, text)
6363
if item.class and item.class.name == "LeetLine" then
64-
table.insert(item._texts, 1, Indent("\t", "leetcode_indent"))
64+
table.insert(item._texts, 1, Indent(text or "\t", "leetcode_indent"))
6565
return
6666
end
6767

6868
for _, c in ipairs(item:contents()) do
69-
self:add_indent(c)
69+
self:add_indent(c, text)
7070
end
7171
end
7272

@@ -122,7 +122,7 @@ function Tag:get_el_data(node)
122122
return { tag = tag, attrs = attrs }
123123
end
124124

125-
function Tag:parse_helper() --
125+
function Tag:parse_node() --
126126
---@param child TSNode
127127
for child in self.node:iter_children() do
128128
local ntype = child:type()
@@ -212,7 +212,7 @@ function Tag:init(text, opts, node, tags) --
212212

213213
Tag.super.init(self, {}, opts)
214214

215-
self:parse_helper()
215+
self:parse_node()
216216
end
217217

218218
---@type fun(text: string, opts: lc.ui.opts, node: TSNode, tags: lc.ui.Tag[]): lc.ui.Tag

lua/leetcode-ui/group/tag/li.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function Li:init(text, opts, node, tags)
2929
end
3030

3131
local parent = self.tags[r]
32+
3233
if parent then
3334
if parent.order then
3435
self.pre = parent.order .. ". "

lua/leetcode-ui/group/tag/pre.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ local Pre = Tag:extend("LeetTagPre")
1010
function Pre:contents()
1111
local items = Pre.super.contents(self)
1212

13-
for _, value in ipairs(items) do
14-
for _, line in ipairs(value:contents()) do
15-
local indent = Line():append("\t\t", "leetcode_indent")
16-
table.insert(line._texts, 1, indent)
17-
end
13+
for _, item in ipairs(items) do
14+
self:add_indent(item, "\t\t")
1815
end
1916

2017
return items

lua/leetcode-ui/group/tag/sub.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ local log = require("leetcode.logger")
55
---@class lc.ui.Tag.sub : lc.ui.Tag
66
local Sub = Tag:extend("LeetTagSub")
77

8-
function Sub:contents()
9-
local Group = require("leetcode-ui.group")
10-
local grp = Group()
8+
function Sub:parse_node()
9+
self:append("_")
1110

12-
grp:append("_", "leetcode_alt")
13-
grp:append(self:content(), "Number")
14-
15-
return grp:contents()
11+
Sub.super.parse_node(self)
1612
end
1713

1814
---@type fun(): lc.ui.Tag.sub

lua/leetcode-ui/group/tag/sup.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
local Tag = require("leetcode-ui.group.tag")
2+
local Line = require("leetcode-ui.line")
23

34
local log = require("leetcode.logger")
45

56
---@class lc.ui.Tag.sup : lc.ui.Tag
67
local Sup = Tag:extend("LeetTagSup")
78

8-
function Sup:contents()
9-
local Group = require("leetcode-ui.group")
10-
local grp = Group()
9+
function Sup:parse_node()
10+
self:append("^")
1111

12-
grp:append("^", "leetcode_alt")
13-
grp:append(self:content(), "Number")
14-
15-
return grp:contents()
12+
Sup.super.parse_node(self)
1613
end
1714

1815
---@type fun(): lc.ui.Tag.sup

lua/leetcode/theme/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ local highlights = {
3333
-- ol = "",
3434
-- li = "",
3535
-- font = "",
36-
-- sup = "",
37-
-- sub = "",
36+
sup = "header",
37+
sub = "header",
3838
-- small = "",
3939
-- div = "",
4040
}

0 commit comments

Comments
 (0)