Syntax highlighting for brackets on HTML (and XML)?

Syntax highlighting for brackets on HTML (and XML)?

2
NewbieNewbie
2

    Dec 03, 2015#1

    Hello everybody!

    I am new to UltraEdit and I am trying to modify the syntax highlighting and create a proper theme for me. The Monokai theme of Visual Studio Code makes code very easy to read (see attachment!) as it uses extra colors for BRACKETS. It's great, the special color for brackets emphasizes the tags, it optically removes the brackets from the tags. Also lists look much cleaner.

    I couldn't find a possibility in UE to define a special color for brackets. Is it possible to create a theme in UE that looks exactly like the attachment?

    Best wishes
    Fiorellino

    Visual Studio 2015 (Monokai).png (60.14KiB)
    The Monokai theme of Visual Studio Code

    481
    Basic UserBasic User
    481

      Dec 03, 2015#2

      That's going to be difficult. Syntax highlighting works through a combination of the language word file, in this case html.uew, that is used to specify classes of items and by choosing View->Themes->Manage Themes, picking your language and then setting the colour for a particular class.

      So, you might think that you could just create a new class in the uew file:

      /C4"Angle Brackets"
      < >

      and then go and choose new colours for those in the manage themes dialog. However, I'm pretty sure that UE will pick the longest match when doing syntax highlighting so even though you have asked for less than and greater than brackets to be some custom colour, UE will find a better match and use that e.g.

      <html class="no-js">

      The C1"Tags" section of the uew file contains:

      <html

      That is a longer (and therefore better) match than just:

      <

      So UE will pick that in preference.

      I'm not 100% sure on the above but it looks that way. Hopefully mofi can confirm or deny.

      6,680583
      Grand MasterGrand Master
      6,680583

        Dec 03, 2015#3

        Explanation above written by netizensmith is absolutely right. But it is even more complicated for HTML (and XML).

        In general such a syntax highlighting is possible in UltraEdit. And for most programming and scripting languages brackets and operators are defined in 1 or more color groups for being highlighted different to language keywords, custom symbols and other text.

        The attached wordfile hypertext.uew with a language named HyperText demonstrates syntax highlighting as Fiorellino would like to use for HTML files for files with extension HT. This wordfile is based on html.uew installed with UltraEdit for Windows v22.20.0.40.

        But HTML and also XML are different and can't be highlighted using standard methods. Therefore UltraEdit contains special code for syntax highlighting HTML, XHTML and XML files.

        Those built-in specials for HTML files make it impossible to append the file extensions HTM and HTML at end of first line of HyperText.uew and then get a syntax highlighting like for *.ht files for *.htm or *.html files.

        Even if the wordfile containing the file extension of active HTML file does not contain language marker HTML_LANG or contains a different known language marker from list included on page Syntax Highlighting in help of UltraEdit, UltraEdit applies automatically for *.htm and *.html files the special syntax highlighting activated also by language marker HTML_LANG.

        This is necessary to support HTML specific features like:
        I think, I have to explain the second feature more clearly specific for HTML.

        UltraEdit uses as simple mechanism for syntax highlighting. It takes the character stream of a file and splits it up into strings by using the characters defined in the wordfile on line starting with /Delimiters =. For more details download from the ultimate syntax highlighting tools the ZIP file and read HTML documentation for TestForInvalid being included in this ZIP file.

        Then each string is compared either case-sensitive or case-insensitive with the strings (words) specified in the syntax highlighting wordfile to determine the color.

        So this simple method does not take the context into account, i.e. it does not check what is left and what is right to a string to highlight.

        This context ignoring behavior is a big problem for HTML highlighting as there are many strings where context is important. For example there is the element title with the tags <title> (start tag with no attributes), <title (start tag with attributes) and </title> (end tag) as also the attribute title which requires a value in single or double quotes and therefore is valid only with title=. HTML specification lists several such context specific meanings like for element span and attribute span to list here just one more example.

        So for HTML (and also XML) it is extremely important what is left and what is right of a string to highlight. Usually UltraEdit supports only that a string in the wordfile in a color group starts with a delimiter character to support differences on highlighting depending on character left to a "word". But for HTML/XML it is important to support also < and </ left to a word and = and > right to a word to be able to highlight tags of elements different to attributes. This is the reason why for wordfiles containing HTML_LANG or XML_LANG it is possible and for correct highlighting even required to define tags and attributes with <, </, = and > which must be nevertheless sorted in wordfile like when those characters would not be there.

        As UltraEdit contains for some file types (= file extensions) internal defaults which can be overwritten by a customized wordfile like applying HTML_LANG for *.htm and *.html files or XML_LANG for *.xml files and others, it is not possible with UE v22.20 to get a syntax highlighting as wanted by Fiorellino for HTML files.


        Fiorellino, I can only suggest to send an email to IDM support with the feature request to be able to define a color for begin and end of an HTML/XML tag and the equal sign of an attribute for highlighting <, </, =, > and /> (empty element) different to element / attribute name.

        Such an enhancement could work with a html.uew as packed by me also into the ZIP file. With using this version of the wordfile the different highlighting works currently by 100% for = and />, just partly for > (only on quote left to angle bracket) and not at all for < and </.
        hypertext_markup_language_uew.zip (5.68 KiB)   102
        This ZIP file contains hypertext.uew and html.uew as described in text above.
        Best regards from an UC/UE/UES for Windows user from Austria