irongit

A Neovim plugin enabling you to solve LeetCode problems.

114 lines2.3 KBLua
1local log = require("leetcode.logger")
2local theme = require("leetcode.theme")
3
4---@class lc.Parser.Utils
5local utils = {}
6
7utils.entities = {
8 [" "] = " ",
9 ["""] = "\"",
10 ["'"] = "'",
11
12 ["→"] = "",
13 ["←"] = "",
14 ["↑"] = "↑",
15 ["↓"] = "↓",
16
17 [" "] = " ",
18 ["…"] = "…",
19 ["⌊"] = "⌊",
20 ["⌋"] = "⌋",
21 ["&"] = "&",
22 ["—"] = "—",
23 ["–"] = "–",
24
25 ["”"] = "”",
26 ["’"] = "’",
27 ["“"] = "“",
28 ["‘"] = "‘",
29
30 ["&lcpad;"] = "",
31 ["&lcnl;"] = "",
32 ["&lctab;"] = "\t",
33 ["&lcend;"] = "",
34 ["&lccode;"] = "`",
35
36 -- Math symbols
37 ["&lt;"] = "<",
38 ["&gt;"] = ">",
39 ["&plus;"] = "+",
40 ["&plusmn;"] = "±",
41 ["&times;"] = "×",
42 ["&frasl;"] = "/",
43 ["&forall;"] = "∀",
44 ["&part;"] = "∂",
45 ["&exist;"] = "∃",
46 ["&empty;"] = "∅",
47 ["&nabla;"] = "∇",
48 ["&isin;"] = "∈",
49 ["&notin;"] = "∉",
50 ["&ni;"] = "∋",
51 ["&prod;"] = "∏",
52 ["&sum;"] = "∑",
53 ["&minus;"] = "−",
54 ["&lowast;"] = "∗",
55 ["&radic;"] = "√",
56 ["&prop;"] = "∝",
57 ["&infin;"] = "∞",
58 ["&ang;"] = "∠",
59 ["&and;"] = "∧",
60 ["&or;"] = "∨",
61 ["&cap;"] = "∩",
62 ["&cup;"] = "∪",
63 ["&int;"] = "∫",
64 ["&there4;"] = "∴",
65 ["&sim;"] = "∼",
66 ["&cong;"] = "≅",
67 ["&asymp;"] = "≈",
68 ["&ne;"] = "≠",
69 ["&equiv;"] = "≡",
70 -- ["&le;"] = "<=",
71 -- ["&ge;"] = ">=",
72 ["&le;"] = "≤",
73 ["&ge;"] = "≥",
74 ["&sub;"] = "⊂",
75 ["&sup;"] = "⊃",
76 ["&nsub;"] = "⊄",
77 ["&sube;"] = "⊆",
78 ["&supe;"] = "⊇",
79 ["&oplus;"] = "⊕",
80 ["&otimes;"] = "⊗",
81 ["&perp;"] = "⊥",
82 ["&sdot;"] = "⋅",
83}
84
85---@param entity string
86---@return string
87function utils.entity(entity)
88 if utils.entities[entity] then
89 return utils.entities[entity]
90 else
91 log.error("unknown enitity: " .. entity)
92 return entity
93 end
94end
95
96---@param tag lc.ui.Tag
97---@return string
98function utils.hl(tag) --
99 local tag_names = {}
100
101 for _, v in ipairs(tag.tags) do
102 if v.name then
103 table.insert(tag_names, v.name)
104 end
105 end
106
107 if tag.name then
108 table.insert(tag_names, tag.name)
109 end
110
111 return theme.get_dynamic(tag_names)
112end
113
114return utils