Skip to content

Commit 3b270c1

Browse files
committed
feat: Added support for HTML entites
Both &<name>; and &<name> are supported
1 parent ab0e54e commit 3b270c1

File tree

4 files changed

+363
-17
lines changed

4 files changed

+363
-17
lines changed

lua/markview.lua

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,14 +1165,22 @@ markview.configuration = {
11651165
}
11661166
},
11671167
html = {
1168-
default = {
1169-
conceal = false
1168+
tags = {
1169+
enable = true,
1170+
1171+
default = {
1172+
conceal = false
1173+
},
1174+
1175+
config = {
1176+
p = { conceal = true, hl = "Title" },
1177+
u = { conceal = true, hl = "Underlined" },
1178+
i = { conceal = true, hl = "Italic" }
1179+
}
11701180
},
11711181

1172-
types = {
1173-
p = { conceal = true, hl = "Title" },
1174-
u = { conceal = true, hl = "Underlined" },
1175-
i = { conceal = true, hl = "Italic" }
1182+
entites = {
1183+
enable = true
11761184
}
11771185
},
11781186

lua/markview/entites.lua

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
local entites = {};
2+
3+
entites.lookup = {
4+
Aacute = "Á",
5+
aacute = "á",
6+
Acirc = "Â",
7+
acirc = "â",
8+
acute = "´",
9+
AElig = "Æ",
10+
aelig = "æ",
11+
Agrave = "À",
12+
agrave = "à",
13+
alefsym = "",
14+
Alpha = "Α",
15+
alpha = "α",
16+
amp = "&",
17+
["and"] = "",
18+
ang = "",
19+
Aring = "Å",
20+
aring = "å",
21+
asymp = "",
22+
Atilde = "Ã",
23+
atilde = "ã",
24+
Auml = "Ä",
25+
auml = "ä",
26+
bdquo = "",
27+
Beta = "Β",
28+
beta = "β",
29+
brvbar = "¦",
30+
bull = "",
31+
cap = "",
32+
Ccedil = "Ç",
33+
ccedil = "ç",
34+
cedil = "¸",
35+
cent = "¢",
36+
Chi = "Χ",
37+
chi = "χ",
38+
circ = "ˆ",
39+
clubs = "",
40+
congc = "",
41+
copy = "©",
42+
crarr = "",
43+
cup = "",
44+
curren = "¤",
45+
Dagger = "",
46+
dagger = "",
47+
dArr = "",
48+
darr = "",
49+
deg = "°",
50+
Delta = "Δ",
51+
delta = "δ",
52+
diams = "",
53+
divide = "÷",
54+
Eacute = "É",
55+
eacute = "é",
56+
Ecirc = "Ê",
57+
ecirc = "ê",
58+
Egrave = "È",
59+
egrave = "è",
60+
empty = "",
61+
Epsilon = "Ε",
62+
epsilon = "ε",
63+
equiv = "",
64+
Eta = "Η",
65+
eta = "η",
66+
ETH = "Ð",
67+
eth = "ð",
68+
Euml = "Ë",
69+
euml = "ë",
70+
euro = "",
71+
exists = "",
72+
fnof = "ƒ",
73+
forall = "",
74+
frac12 = "½",
75+
frac14 = "¼",
76+
frac34 = "¾",
77+
frasl = "",
78+
Gamma = "Γ",
79+
gamma = "γ",
80+
ge = "",
81+
gt = ">",
82+
harr = "",
83+
hArr = "",
84+
hearts = "",
85+
hellip = "",
86+
Iacute = "Í",
87+
iacute = "í",
88+
Icirc = "Î",
89+
icirc = "î",
90+
iexcl = "¡",
91+
Igrave = "Ì",
92+
igrave = "ì",
93+
image = "",
94+
infin = "",
95+
int = "",
96+
Iota = "Ι",
97+
iota = "ι",
98+
iquest = "¿",
99+
isin = "",
100+
Iuml = "Ï",
101+
iuml = "ï",
102+
Kappa = "Κ",
103+
kappa = "κ",
104+
Lambda = "Λ",
105+
lambda = "λ",
106+
lang = "",
107+
laquo = "«",
108+
lArr = "",
109+
larr = "",
110+
lceil = "",
111+
ldquo = "",
112+
le = "",
113+
lfloor = "",
114+
lowast = "",
115+
loz = "",
116+
-- lrm = "‎",
117+
lsaquo = "",
118+
lsquo = "",
119+
lt = "<",
120+
macr = "¯",
121+
mdash = "",
122+
micro = "µ",
123+
middot = "·",
124+
minus = "",
125+
Mu = "Μ",
126+
mu = "μ",
127+
nabla = "",
128+
nbsp = " ",
129+
ndash = "",
130+
ne = "",
131+
ni = "",
132+
["not"] = "¬",
133+
notin = "",
134+
nsub = "",
135+
Ntilde = "Ñ",
136+
ntilde = "ñ",
137+
Nu = "Ν",
138+
nu = "ν",
139+
Oacute = "Ó",
140+
oacute = "ó",
141+
Ocirc = "Ô",
142+
ocirc = "ô",
143+
OElig = "Œ",
144+
oelig = "œ",
145+
Ograve = "Ò",
146+
ograve = "ò",
147+
Omeg = "Ω",
148+
omega = "ω",
149+
Omicron = "Ο",
150+
omicron = "ο",
151+
oline = "",
152+
["or"] = "",
153+
Oslash = "Ø",
154+
oslash = "ø",
155+
Otilde = "Õ",
156+
otilde = "õ",
157+
Ouml = "Ö",
158+
ouml = "ö",
159+
para = "",
160+
part = "",
161+
permil = "",
162+
perp = "",
163+
Phi = "Φ",
164+
phi = "φ",
165+
Pi = "Π",
166+
pi = "π",
167+
piv = "ϖ",
168+
plusmn = "±",
169+
pound = "£",
170+
Prime = "",
171+
prime = "",
172+
prod = "",
173+
prop = "",
174+
Psi = "Ψ",
175+
psi = "ψ",
176+
quot = "\"",
177+
radic = "",
178+
rang = "",
179+
raquo = "»",
180+
rArr = "",
181+
rarr = "",
182+
rceil = "",
183+
rdquo = "",
184+
real = "",
185+
reg = "®",
186+
rflo = "",
187+
Rho = "Ρ",
188+
rho = "ρ",
189+
-- rlm = "‏",
190+
rsaquo = "",
191+
rsquo = "",
192+
sbquo = "",
193+
Scaron = "Š",
194+
scaron = "š",
195+
sdot = "",
196+
sect = "§",
197+
shy = "­",
198+
Sigma = "Σ",
199+
sigma = "σ",
200+
sigmaf = "ς",
201+
sim = "",
202+
spades = "",
203+
sub = "",
204+
sube = "",
205+
sum = "",
206+
sup = "",
207+
sup1 = "¹",
208+
sup2 = "²",
209+
sup3 = "³",
210+
supe = "",
211+
szlig = "ß",
212+
Tau = "Τ",
213+
tau = "τ",
214+
there4 = "",
215+
Theta = "Θ",
216+
theta = "θ",
217+
thetasym = "ϑ",
218+
thinsp = "",
219+
THORN = "Þ",
220+
thorn = "þ",
221+
tilde = "˜",
222+
times = "×",
223+
trade = "",
224+
Uacute = "Ú",
225+
uacute = "ú",
226+
uArr = "",
227+
uarr = "",
228+
Ucirc = "Û",
229+
ucirc = "û",
230+
Ugrave = "Ù",
231+
ugrave = "ù",
232+
uml = "¨",
233+
upsih = "ϒ",
234+
Upsilon = "Υ",
235+
upsilon = "υ",
236+
Uuml = "Ü",
237+
uuml = "ü",
238+
weierp = "",
239+
Xi = "Ξ",
240+
xi = "ξ",
241+
Yacute = "Ý",
242+
yacute = "ý",
243+
yen = "¥",
244+
yuml = "ÿ",
245+
Yuml = "Ÿ",
246+
Zeta = "Ζ",
247+
zeta = "ζ",
248+
-- zwj = "‍",
249+
-- zwnj = "‌"
250+
}
251+
252+
entites.get = function (string)
253+
return entites.lookup[string], vim.fn.strdisplaywidth(entites.lookup[string]);
254+
end
255+
256+
return entites;

lua/markview/parser.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ parser.md_inline = function (buffer, TStree, from, to)
430430
] @link)
431431
432432
((code_span) @code)
433+
434+
((entity_reference) @entity)
433435
]]);
434436

435437
-- The last 2 _ represent the metadata & query
@@ -511,6 +513,19 @@ parser.md_inline = function (buffer, TStree, from, to)
511513
row_start = row_start,
512514
row_end = row_end,
513515

516+
col_start = col_start,
517+
col_end = col_end
518+
})
519+
elseif capture_name == "entity" then
520+
table.insert(parser.parsed_content, {
521+
node = capture_node,
522+
type = "html_entity",
523+
524+
text = capture_text,
525+
526+
row_start = row_start,
527+
row_end = row_end,
528+
514529
col_start = col_start,
515530
col_end = col_end
516531
})
@@ -521,8 +536,6 @@ end
521536
parser.html = function (buffer, TStree, from, to)
522537
local scanned_queies = vim.treesitter.query.parse("html", [[
523538
((element) @elem)
524-
525-
;((entity_reference) @entity)
526539
]]);
527540

528541
for capture_id, capture_node, _, _ in scanned_queies:iter_captures(TStree:root(), buffer, from, to) do

0 commit comments

Comments
 (0)