orbitalquark / scintillua

Scintillua enables Scintilla lexers to be written in Lua, particularly using LPeg. It can also be used as a standalone Lua library for syntax highlighting support.
https://orbitalquark.github.io/scintillua
MIT License
51 stars 20 forks source link

html syntax highlight misses on single tags #114

Closed jvvv closed 2 months ago

jvvv commented 2 months ago

Using vis, 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 compared the html lexers in scintillua and vis, and they do not differ. Also, I submitted downstream issue with vis: https://github.com/martanne/vis/issues/1196 which may get closed since I was asked to upstream the issue.

orbitalquark commented 2 months ago

Thanks for reaching out.

Scintillua distinguishes between tag "subclasses" using a .. For example, <html> is tagged as a 'tag' (lexer.TAG), but <img /> is tagged as a 'tag.single' (lexer.TAG .. '.single'). Unknown tags like <foo> are tagged as 'tag.unknown'. Editors can choose highlight these subclasses separately, or fall back onto the parent tag (in this case, lexer.TAG, or 'tag').

Your solution suggests two things:

  1. That your theme does not actually recognize the 'tag.single' tag and provide highlighting/styles for it like it does for just the 'tag' tag.
  2. That if your editor does not have styling information for a given tag, it does not fall back to styling it in the parent style (e.g. tag.single -> tag).

If you update your theme and/or editor, you should get your desired behavior with no changes to Scintillua being necessary.

jvvv commented 2 months ago

Thank you for your detailed analysis, it has be exceedingly helpful. Turns out that the main problem was that some tags are not added to the themes. After adding this comment, I will close and pursue this downstream. Thanks again.