Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When saving a node, whilst using IE7 with Tiny MCE, the html tags are saved as capitals. This means that Table Alternate Rows doesn't find the expected tbody tag.
Could the preg_match look for lower and uppercase versions of tbody and tr, as this would solve issues with IE7?
As time was short earlier today, I came up with a quick fix that worked just by using another while loop below the first while loop... I'm sure with more time the preg_match could have been changed to look for tbody and TBODY.
//IE hack
while(preg_match('!(<TBODY ?.*>)!', $text, $matches, PREG_OFFSET_CAPTURE, $offset)) {
$offset = $matches[0][1];
$count = 1;
// While the tbody is still open
while(preg_match('!(<TR( ?.*)>)|(</TBODY>)!', $text, $matches, PREG_OFFSET_CAPTURE, $offset)) {
// +1 so we don't match the same string
$offset = $matches[0][1] + 1;
// Don't process tr's until we find a tbody.
if($matches[0][0] == '</TBODY>') {
break;
}
// Don't replace existing classes. Perhaps this should append a class instead?
if(!strstr($matches[2][0], 'class=')) {
if(($count % 2) == 0) {
$new_tag = '<tr class="even"' . $matches[2][0] . '>';
$text = str_replace_count($matches[0][0], $new_tag, $text, $offset - 1, 1);
}
else {
$new_tag = '<tr class="odd"' . $matches[2][0] . '>';
$text = str_replace_count($matches[0][0], $new_tag, $text, $offset - 1, 1);
}
}
$count++;
}
}
Comments
Comment #1
markhalliwellActually this is a quite simple change, by throwing a case insensitive flag (
i
) after the regular expression, you can search for either, thus:Should be (notice the little
i
after the last!
):Comment #2
jefflogan CreditAttribution: jefflogan commentedExcellent thanks Mark. I've just started getting to grips with regular expressions, and realise how useful they are!
Comment #3
deviantintegral CreditAttribution: deviantintegral commentedThis change is all ready in the 7.x version, so I've committed the regex modifier in 26cb576. Thanks!