Skip to content

Commit

Permalink
feat: Added support for HTML entites
Browse files Browse the repository at this point in the history
Both &<name>; and &<name> are supported
  • Loading branch information
OXY2DEV committed Aug 3, 2024
1 parent ab0e54e commit 3b270c1
Show file tree
Hide file tree
Showing 4 changed files with 363 additions and 17 deletions.
20 changes: 14 additions & 6 deletions lua/markview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1165,14 +1165,22 @@ markview.configuration = {
}
},
html = {
default = {
conceal = false
tags = {
enable = true,

default = {
conceal = false
},

config = {
p = { conceal = true, hl = "Title" },
u = { conceal = true, hl = "Underlined" },
i = { conceal = true, hl = "Italic" }
}
},

types = {
p = { conceal = true, hl = "Title" },
u = { conceal = true, hl = "Underlined" },
i = { conceal = true, hl = "Italic" }
entites = {
enable = true
}
},

Expand Down
256 changes: 256 additions & 0 deletions lua/markview/entites.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
local entites = {};

entites.lookup = {
Aacute = "Á",
aacute = "á",
Acirc = "Â",
acirc = "â",
acute = "´",
AElig = "Æ",
aelig = "æ",
Agrave = "À",
agrave = "à",
alefsym = "",
Alpha = "Α",
alpha = "α",
amp = "&",
["and"] = "",
ang = "",
Aring = "Å",
aring = "å",
asymp = "",
Atilde = "Ã",
atilde = "ã",
Auml = "Ä",
auml = "ä",
bdquo = "",
Beta = "Β",
beta = "β",
brvbar = "¦",
bull = "",
cap = "",
Ccedil = "Ç",
ccedil = "ç",
cedil = "¸",
cent = "¢",
Chi = "Χ",
chi = "χ",
circ = "ˆ",
clubs = "",
congc = "",
copy = "©",
crarr = "",
cup = "",
curren = "¤",
Dagger = "",
dagger = "",
dArr = "",
darr = "",
deg = "°",
Delta = "Δ",
delta = "δ",
diams = "",
divide = "÷",
Eacute = "É",
eacute = "é",
Ecirc = "Ê",
ecirc = "ê",
Egrave = "È",
egrave = "è",
empty = "",
Epsilon = "Ε",
epsilon = "ε",
equiv = "",
Eta = "Η",
eta = "η",
ETH = "Ð",
eth = "ð",
Euml = "Ë",
euml = "ë",
euro = "",
exists = "",
fnof = "ƒ",
forall = "",
frac12 = "½",
frac14 = "¼",
frac34 = "¾",
frasl = "",
Gamma = "Γ",
gamma = "γ",
ge = "",
gt = ">",
harr = "",
hArr = "",
hearts = "",
hellip = "",
Iacute = "Í",
iacute = "í",
Icirc = "Î",
icirc = "î",
iexcl = "¡",
Igrave = "Ì",
igrave = "ì",
image = "",
infin = "",
int = "",
Iota = "Ι",
iota = "ι",
iquest = "¿",
isin = "",
Iuml = "Ï",
iuml = "ï",
Kappa = "Κ",
kappa = "κ",
Lambda = "Λ",
lambda = "λ",
lang = "",
laquo = "«",
lArr = "",
larr = "",
lceil = "",
ldquo = "",
le = "",
lfloor = "",
lowast = "",
loz = "",
-- lrm = "‎",
lsaquo = "",
lsquo = "",
lt = "<",
macr = "¯",
mdash = "",
micro = "µ",
middot = "·",
minus = "",
Mu = "Μ",
mu = "μ",
nabla = "",
nbsp = " ",
ndash = "",
ne = "",
ni = "",
["not"] = "¬",
notin = "",
nsub = "",
Ntilde = "Ñ",
ntilde = "ñ",
Nu = "Ν",
nu = "ν",
Oacute = "Ó",
oacute = "ó",
Ocirc = "Ô",
ocirc = "ô",
OElig = "Œ",
oelig = "œ",
Ograve = "Ò",
ograve = "ò",
Omeg = "Ω",
omega = "ω",
Omicron = "Ο",
omicron = "ο",
oline = "",
["or"] = "",
Oslash = "Ø",
oslash = "ø",
Otilde = "Õ",
otilde = "õ",
Ouml = "Ö",
ouml = "ö",
para = "",
part = "",
permil = "",
perp = "",
Phi = "Φ",
phi = "φ",
Pi = "Π",
pi = "π",
piv = "ϖ",
plusmn = "±",
pound = "£",
Prime = "",
prime = "",
prod = "",
prop = "",
Psi = "Ψ",
psi = "ψ",
quot = "\"",
radic = "",
rang = "",
raquo = "»",
rArr = "",
rarr = "",
rceil = "",
rdquo = "",
real = "",
reg = "®",
rflo = "",
Rho = "Ρ",
rho = "ρ",
-- rlm = "‏",
rsaquo = "",
rsquo = "",
sbquo = "",
Scaron = "Š",
scaron = "š",
sdot = "",
sect = "§",
shy = "­",
Sigma = "Σ",
sigma = "σ",
sigmaf = "ς",
sim = "",
spades = "",
sub = "",
sube = "",
sum = "",
sup = "",
sup1 = "¹",
sup2 = "²",
sup3 = "³",
supe = "",
szlig = "ß",
Tau = "Τ",
tau = "τ",
there4 = "",
Theta = "Θ",
theta = "θ",
thetasym = "ϑ",
thinsp = "",
THORN = "Þ",
thorn = "þ",
tilde = "˜",
times = "×",
trade = "",
Uacute = "Ú",
uacute = "ú",
uArr = "",
uarr = "",
Ucirc = "Û",
ucirc = "û",
Ugrave = "Ù",
ugrave = "ù",
uml = "¨",
upsih = "ϒ",
Upsilon = "Υ",
upsilon = "υ",
Uuml = "Ü",
uuml = "ü",
weierp = "",
Xi = "Ξ",
xi = "ξ",
Yacute = "Ý",
yacute = "ý",
yen = "¥",
yuml = "ÿ",
Yuml = "Ÿ",
Zeta = "Ζ",
zeta = "ζ",
-- zwj = "‍",
-- zwnj = "‌"
}

entites.get = function (string)
return entites.lookup[string], vim.fn.strdisplaywidth(entites.lookup[string]);
end

return entites;
17 changes: 15 additions & 2 deletions lua/markview/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ parser.md_inline = function (buffer, TStree, from, to)
] @link)
((code_span) @code)
((entity_reference) @entity)
]]);

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

col_start = col_start,
col_end = col_end
})
elseif capture_name == "entity" then
table.insert(parser.parsed_content, {
node = capture_node,
type = "html_entity",

text = capture_text,

row_start = row_start,
row_end = row_end,

col_start = col_start,
col_end = col_end
})
Expand All @@ -521,8 +536,6 @@ end
parser.html = function (buffer, TStree, from, to)
local scanned_queies = vim.treesitter.query.parse("html", [[
((element) @elem)
;((entity_reference) @entity)
]]);

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

0 comments on commit 3b270c1

Please sign in to comment.