Sublime Forum

Syntax highlight background color comes to full line

#1

when i apply background color for a particular regex, the background color extends upto the end of the line. is it possible to make the background color just matching the word.

my syntax definition as below,

%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Logging stubs
file_extensions: [log]
scope: source.log
contexts:
  main:
    # tuts captured
    - match: '.*(Entering.*)\b'
      scope: meta.function.text.plain
      captures:
        1: entity.name.function.text.plain
    # Line starting in all caps
    - match: '^[A-Z_]+\b.*'
      push:
        - meta_scope: markup.heading
        - match: '$\n?'
          pop: true

color scheme as below,

{
	// http://www.sublimetext.com/docs/3/color_schemes.html
	"variables": {
		// "green": "#FF0000",
		"lightblack": "hsl(0, 5%, 0%)"
	},
	"globals": {
		// "foreground": "var(green)",
		"line_highlight": "#00eeee",
	},
	"rules": [
		{
            "name": "markup headings",
            "scope": "markup.heading",
            "font_style": "bold",
            "foreground": "var(black)",
            "background": "var(red)"
		},
		{
            "name": "markup bold",
            "scope": "markup.bold",
            "font_style": "italic",
            "foreground": "var(black)",
            "background": "var(blue5)",
        },
		{
            "name": "markup headings",
            "scope": "markup.heading1",
            "font_style": "bold",
            "foreground": "var(green)",
        }        
	],
}
0 Likes

#2

Because you assign \n the scope markup.heading. Either you don’t assign \n with that scope, or you assign it an extra scope so that you can exclude it by the - selector operator.

Yet you don’t need push at the first place. I suggest

- match: '^[A-Z_]+\b.*$(\n?)'
  captures:
    0: markup.heading # the whole matched string
    1: meta.whitespace.newline
{
  "name": "markup headings",
  "scope": "markup.heading - meta.whitespace.newline",
  "font_style": "bold",
  "foreground": "var(black)",
  "background": "var(red)",
},

On this forum, posts are written in Markdown. To write code block in Markdown:

```yaml
# yaml content
```
```json
# json content
```
1 Like

#3

Thanks it worked,

Can you point me to tutorials / examples for captures and push?

0 Likes

#4

There is doc for selector as well. https://www.sublimetext.com/docs/selectors.html

1 Like