martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.25k stars 257 forks source link

html syntax highlight misses on single tags #1196

Closed jvvv closed 2 months ago

jvvv commented 3 months ago

Single html tags like hr, input, and meta (etc) aren't getting highlighted. My lua knowledge is pretty sparse, but here's a work-around that is working for me so far:

From 69243d5a88623f5e7d08eb79b827ad31aa893ece Mon Sep 17 00:00:00 2001
From: jvvv
Date: Mon, 17 Jun 2024 13:16:17 -0400
Subject: [PATCH] fix syntax highlight for html single tags

---
 lua/lexers/html.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lua/lexers/html.lua b/lua/lexers/html.lua
index 9146b63..a0ce2e7 100644
--- a/lua/lexers/html.lua
+++ b/lua/lexers/html.lua
@@ -16,7 +16,7 @@ lex:add_rule('doctype',

 -- Tags.
 local paired_tag = lex:tag(lexer.TAG, lex:word_match(lexer.TAG, true))
-local single_tag = lex:tag(lexer.TAG .. '.single', lex:word_match(lexer.TAG .. '.single', true))
+local single_tag = lex:tag(lexer.TAG, lex:word_match(lexer.TAG .. '.single', true))
 local known_tag = paired_tag + single_tag
 local unknown_tag = lex:tag(lexer.TAG .. '.unknown', (lexer.alnum + '-')^1)
 local tag = lex:tag(lexer.TAG .. '.chars', '<' * P('/')^-1) * (known_tag + unknown_tag) * -P(':')
-- 
2.45.2

I'm running vis built from git HEAD on alpinelinux edge. I can also report this upstream to scintillua if that is desired.

mcepl commented 3 months ago

vis is taking its lexers from https://github.com/orbitalquark/scintillua, please, file your issue report there, and we will take it from them (of course, you are more than welcome to initiate another round of synchronization with their code).

@rnpnr , I think, this could be closed.

mcepl commented 3 months ago

Otherwise, added as a commit to https://git.cepl.eu/cgit/vis/vis/commit/?id=5629ca0091c2 and after testing, I will submit it upstream.

jvvv commented 3 months ago

Just submitted: https://github.com/orbitalquark/scintillua/issues/114

rnpnr commented 3 months ago

This can stay open for now. We can bulk pull in the changes once its resolved upstream.

jvvv commented 3 months ago

Ok, got some good help from orbitalquark. There are tags that handle this case here but are not in the themes. I will post a PR soon that will solve this issue more correctly, but might first spend some time looking for similar issues with tags in other lexers that are not handled by the themes. The patch I suggested when I opened this is not correct.

What is needed is something like this in the themes:

lexers.STYLE_TAG_SINGLE = lexers.STYLE_TAG
lexers.STYLE_TAG_DOCTYPE = lexers.STYLE_TAG

or

lexers.STYLE_TAG_UNKNOWN = 'fore:magenta'
lexers.STYLE_TAG_SINGLE = lexers.STYLE_TAG
lexers.STYLE_TAG_DOCTYPE = lexers.STYLE_TAG .. ',italics'

or how ever seems more appropriate.

These are just the ones that I noticed so far, mainly because both were not getting styled. I included STYLE_TAG_UNKNOWN because that was what helped me get a clue about how to translate the scintillua tag to style/theme language.

rnpnr commented 3 months ago

Oh I see now; those should actually be available to style but are just not included in the default themes. This line: https://github.com/martanne/vis/blob/a7aac1044856abc4d1f133c6563fc604d7fe6295/lua/vis.lua#L287

replaces the . in the names with a _. If you add something like lexers.STYLE_TAG_SINGLE = '...' to your theme it should just work.

I don't have a good way of indicating all possible combinations in the themes besides just adding them and letting people tweak for their own preferences.

jvvv commented 2 months ago

I had hoped to prepare a more expansive set of changes. #1197 will have to do for now until I have more time.