zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.84k stars 1.17k forks source link

XHTML? #3421

Open TailsFanLOL opened 1 month ago

TailsFanLOL commented 1 month ago

Description of the problem or steps to reproduce

I want an XHTML syntax highlighter. Shouldn't be that difficult to implement. Currently it defaults to XML.

Specifications

Commit hash: doesn't show, OS reports 2.0.9-1ubuntu0.22.04.2, but I took my time to look through the syntax files in this repo to make sure there's no such thing that I want right now. OS: Ubuntu Jammy Terminal: Alacritty

Andriamanitra commented 1 month ago

Doesn't the HTML syntax highlighting (you can try it with setlocal filetype html) work for XHTML too? Or do you mean that you would like some XHTML specific file extension(s) to be automatically detected as HTML?

TailsFanLOL commented 1 month ago

It does work, but XHTML has a much stricter syntax. For example, all tags must be closed with no exceptions, attributes must be lowercase, attributes must have a value, etc.

Andriamanitra commented 1 month ago

It does work, but XHTML has a much stricter syntax. For example, all tags must be closed with no exceptions, attributes must be lowercase, attributes must have a value, etc.

Micro's syntax highlighting system is based on regular expressions and thus not advanced enough to pair (nested) tags or do any other kind of advanced syntax analysis. I guess the syntax highlighting could help with some simple things such as only coloring lowercase attributes that end with a '=', but in general you would be better off using a linter (or a language server) to catch mistakes. As far as I know the HTML syntax should be a superset of XHTML syntax and as such sufficient to highlight any correctly formatted XHTML file.

That said if you do want to give making a bespoke XHTML syntax a go the html.yaml syntax would be a good starting point. Just copy the contents of that file to ~/.config/micro/syntax/xhtml.yaml and start hacking! The system is rather simple, you don't need any programming experience (besides the basics of regular expressions). You could then either publish it as a plugin or make a pull request to try and get it merged to the editor.