clutcher / bh

Issue tracker for Better Highlights Intellij IDEA plugin
6 stars 0 forks source link

regex color highlight #125

Open mywebmanavgat opened 2 weeks ago

mywebmanavgat commented 2 weeks ago

Hello, how can I make the following colouring?

I need a regex that selects and colours the attiributes keys between starting with <form and ending with > u can see example https://intellij-support.jetbrains.com/hc/user_images/01J0Y6K5RRWJQTWFWMD2BYDE0R.jpeg

I want to do this by creating regex rules in this way

clutcher commented 2 weeks ago

@mywebmanavgat Suppose you need something like

You can adopt above regexps to your needs. Also I recommend you to use ChatGPT to generate regexps and https://regex101.com/ to test/validate it.

mywebmanavgat commented 1 week ago

I tried the regexes you sent on the regex test site. However,

It applies in the attriibutes of all elements such as div, i, img until the

element is closed.

I tried very hard to do this using chat gpt, but I couldn't get it to use something like or and combining operator in regex.

I cannot experience the examples you have given. Because my trial licence has expired. can you define a trial licence for a few days?

clutcher commented 1 week ago

@mywebmanavgat Can you share your email? I can send a promocode for 1 more free month.

mywebmanavgat commented 1 week ago

I sent an e-mail to the e-mail address in your profile. Thank you for your attention.

mywebmanavgat commented 1 week ago

I try but it fails because there is no and operator in the regex.

(?=\s+(\w+(-\w+(-\w+)?)\s*=) this regex code selects all attribute keys and works very well.

To select those starting with <form

form\s+(\w+(-\w+)?)\s*=

but this selects the first attribute and not the rest.

but I need two steps to apply it for lines starting with . Can't you add such a feature for the plugin? Please give me a quote to do this.

image

image

mywebmanavgat commented 1 week ago

I succeeded.

You Can Use : https://github.com/mywebmanavgat/phpstorm-html-highlight/tree/main

image

clutcher commented 1 week ago

@mywebmanavgat Wow, you did a lot of work.

As for plugin functionality - regexp functionality was created for that, as implementation would be too specific for particaular.

I also asked chatgpt to combine regexps for you and he suggested:

(<form|<input|<select|<textarea|<option|<label|<button).* (data-[^=]*|id|class|method|action|type|value|for|name|placeholder|min|max|selected|rows|readonly|disabled)=|(<\/form>|<\/textarea>|<\/select>|<\/option>|<\/button>|<\/label>|<label>|<button>)

(<table|<thead|<tbody|<tfoot|<tr|<td|<th).* (id|class|scope|colspan|data-[^=]*)=|(<\/table>|<\/thead>|<\/tbody>|<\/tfoot>|<\/tr>|<\/td>|<\/th>|<th>|<table>|<thead>|<tbody>|<tfoot>|<tr>|<td>)

(<a).* (class|href|title|id|data-[^=]*)=|(<a>|<\/a>)
mywebmanavgat commented 1 week ago

@clutcher

the code you pass only captures one attribute and leaves it. for this you need to run the regex algorithm twice. but better highlight does not support this.

https://regex101.com/r/kQEu0M/1

If there is only one class in an element, it catches it. but if there is both a class and a name in an element, it catches the last one and leaves it.