To allow something like this:

<img id="CamelCase" class="AnotherCamelCase" ...>
CommentFileSizeAuthor
#3 case-insensitive-class-id-name.patch3.54 KBmattyoung

Comments

mattyoung’s picture

Before I do make a patch, do you think if I just make it case in-sensitive would work?

markus_petrux’s picture

Look at wysiwyg_filter_get_advanced_rules() in wysiwyg_filter.module. I think we need the following, and then check if that's enough or we need to change something else.

     'valid_classes' => array(
       'title' => t('Rules for Class Names'),
       'description' => t('Enter a comma separated list of rules for <em>Class Names</em>. Whitespaces and line-breaks are ignored. <em>Class Names</em> should start with a lower case letter &quot;a-z&quot; and can be followed by one or more lower case letters &quot;a-z&quot;, digits &quot;0-9&quot;, hyphens &quot;-&quot; and/or underscores &quot;_&quot;. The asterisk character &quot;*&quot; can be used in rules to represent any number of characters from the second position of the rule. Example: &quot;userclass*, my-font-*&quot; are valid rules for <em>Class Names</em>, whereas &quot;*class&quot; is invalid.'),
-      'validate_regexp' => '`^[a-z][-_a-z0-9?*]*$`',
-      'asterisk_expansion' => '[-_a-z0-9]*',
+      'validate_regexp' => '`^[a-zA-Z][-_a-zA-Z0-9?*]*$`',
+      'asterisk_expansion' => '[-_a-zA-Z0-9]*',
     ),

Well, the description also needs to be updated to reflect uppercase letters would be also allowed.

mattyoung’s picture

Status: Active » Needs review
StatusFileSize
new3.54 KB

here is a patch

This make class and id names case insensitive to allow both upper or lower case letters to be used.

I just change the regex to be case insensitive and change asterisk expansion to allow upper case letter also.

markus_petrux’s picture

Committed to CVS an slight variation (patch). I'm adding A-Z to both regular expressions.

Thank you!

markus_petrux’s picture

Status: Needs review » Fixed
mattyoung’s picture

>I'm adding A-Z to both regular expressions

I debated about A-Z vs the i switch. A-Z probably perform better than i?

markus_petrux’s picture

I opted for A-Z because it is easier to read and compare both regexps. There's no much difference in performance.

$times = 1000000;
timer_start('test-1');
for  ($i=0; $i < $times; $i++) {
  preg_match('`^[a-z]$`i', '123 abc');
}
$timer = timer_stop('test-1');
print $timer['time'] ."<br/>\n";

timer_start('test-2');
for  ($i=0; $i < $times; $i++) {
  preg_match('`^[a-zA-Z]$`', '123 abc');
}
$timer = timer_stop('test-2');
print $timer['time'] ."<br/>\n";
1239.9
1259.92
mattyoung’s picture

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.