Sublime Forum

Code coloring for html tag XMP

#1

HTML tags enclosed by a XMP tag are colored as HTML tags. This gives a problem to differentiate between real-HTML tags not enclosed by a XMP tag and fake-HTML tags enclosed by a XMP tag.

How can I change the color of HTML tags enclosed by a XMP tag so that it corresponds to the color of HTML string ?

I’m using Sublime Text 3 with color scheme “Mariana” on Windows 10.

0 Likes

#2
%YAML 1.2
---
scope: text.html.xmp
file_extensions:
  - html
variables:
  ascii_space: '\t\n\f '

  # https://html.spec.whatwg.org/multipage/parsing.html#tag-name-state
  tag_name_char: '[^{{ascii_space}}/<>]'
  tag_name_break: (?=[^{{tag_name_char}}])
  tag_name: '[A-Za-z]{{tag_name_char}}*'

contexts:
  main:
    - include: tag-xmp-closing
    - include: tag-xmp-opening
    - include: HTML.sublime-syntax

  tag-xmp-closing:
    - match: (</)(xmp){{tag_name_break}}
      captures:
        1: punctuation.definition.tag.begin.html
        2: entity.name.tag.other.html
      push: tag-xmp-closing-content

  tag-xmp-closing-content:
    - meta_include_prototype: false
    - meta_scope: meta.tag.xmp.end.html
    - include: HTML.sublime-syntax#tag-end

  tag-xmp-opening:
    - match: (<)(xmp){{tag_name_break}}
      captures:
        1: punctuation.definition.tag.begin.html
        2: entity.name.tag.other.html
      push: tag-xmp-opening-content

  tag-xmp-opening-content:
    - meta_scope: meta.tag.xmp.begin.html
    - match: '>'
      scope: punctuation.definition.tag.end.html
      set: tag-xmp-body
    - match: '/>'
      scope: punctuation.definition.tag.end.html
      pop: true
    - include: HTML.sublime-syntax#tag-attributes

  tag-xmp-body:
    - meta_content_scope: string.unquoted.xmp
    - match: (?=</xmp{{tag_name_break}})
      pop: true

Note: https://www.w3docs.com/learn-html/html-xmp-tag.html

1 Like

#3

Thanks for your quick answer.

I have put your code in file “%APPDATA%\Sublime Text 3\Packages\User\xmp.sublime-syntax”. But the color of HTML tags enclosed by XMP tag doesn’t change. What must I do to activate your code ?

0 Likes

#4

Your code doesn’t work with file extension “.htm”. So I added the other html file extensions :

file_extensions:
  - html
  - htm
  - shtml
  - xhtml

Now it works. Thanks for your help.

0 Likes