Table class breaks preceding tables

robbm - January 5, 2009 - 17:00
Project:Table Alternate Rows
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

It seems that if:

  • I use FCKeditor to create a page
  • I create multiple tables on this page
  • I add a (table) class to one or more of those tables

then the rows within those tables that are before the last table with the (table) class applied do not get "even" and "odd" (row) classes added to their rows.

Here's a simple example (I've added some whitespace to make it readable):

  <div class="content">
    <table cellspacing="0" cellpadding="0" border="0">
      <tbody>
        <tr><td>A1</td><td>A2</td><td>A3</td></tr>
        <tr><td>A4</td><td>A5</td><td>A6</td></tr>
        <tr><td>A7</td><td>A8</td><td>A9</td></tr>
      </tbody>
    </table>
    <table class="data" cellspacing="0" cellpadding="0" border="0">
      <tbody>
        <tr><td>B1</td><td>B2</td><td>B3</td></tr>
        <tr><td>B4</td><td>B5</td><td>B6</td></tr>
        <tr><td>B7</td><td>B8</td><td>B9</td></tr>
      </tbody>
    </table>
    <table class="data" cellspacing="0" cellpadding="0" border="0">
      <tbody>
        <tr><td>C1</td><td>C2</td><td>C3</td></tr>
        <tr><td>C4</td><td>C5</td><td>C6</td></tr>
        <tr><td>C7</td><td>C8</td><td>C9</td></tr>
      </tbody>
    </table>
    <table class="data" cellspacing="0" cellpadding="0" border="0">
      <tbody>
        <tr class="odd"><td>D1</td><td>D2</td><td>D3</td></tr>
        <tr class="even"><td>D4</td><td>D5</td><td>D6</td></tr>
        <tr class="odd"><td>D7</td><td>D8</td><td>D9</td></tr>
      </tbody>
    </table>
    <table cellspacing="0" cellpadding="0" border="0">
      <tbody>
        <tr class="odd"><td>E1</td><td>E2</td><td>E3</td></tr>
        <tr class="even"><td>E4</td><td>E5</td><td>E6</td></tr>
        <tr class="odd"><td>E7</td><td>E8</td><td>E9</td></tr>
      </tbody>
    </table>
  </div>

Note that none of the tables that come before the last table with a (table) class (i.e. table D) have even or odd rows, but that table D and table E do.

Interestingly:

  • switching FCKEditor to source mode
  • cutting and pasting the source code
  • resubmitting the page

seems to fix the problem. This seems to suggest that FCKEditor is initially producing code that the Table Alternate Rows module cannot parse, but that it changes this to code that the Table Alternate Rows module can parse when switched to source mode.

#1

robbm - January 5, 2009 - 18:59

Further investigations seems to show that the Table Alternate Rows module depends upon a certain amount of whitespace in the source. If FCKEditor's "Apply source formatting" is set to "true" then

the editor will format the XHTML when switching from WYSIWYG view to Source view, by inserting line breaks on some tags endings and indenting paragraphs, tables and lists.
This ensures that the Table Alternate Rows module works on all tables.

If FCKEditor's "Apply source formatting" is set to "false" and I manually format the source HTML, then again the Table Alternate Rows module works on all tables.

However, if I create a number of tables (with or without FCKEditor) without any line breaks (or superfluous white space) then any tables that come before a table with a (table) class do not get even and odd rows.

However, I can't currently see the connection between table classes and whitespace...

#2

robbm - January 5, 2009 - 20:44

If anyone's experiencing the same problem, I now have a workaround:

  1. Install the Custom Filter module
  2. Add admin/settings/customfilter/* to your WYSIWYG editor's excluded paths (e.g. Admininster > Site Configuration > FCKeditor > edit FCKeditor Global Profile > Visibility settings > Paths to exclude/include)
  3. Create a custom filter with a "Pattern" of
    /<table/i
    and "Replacement text" of

    <table
    (that's a space, followed by a return character, followed by <table)
  4. Add this filter to your input formats before Table Alternate Rows

This will then add (a space and) a line break before each <table...> tag, which seems to be enough for Table Alternate Rows to work...

#3

deviantintegral - January 6, 2009 - 02:47
Version:5.x-1.1» 5.x-1.x-dev
Status:active» postponed (maintainer needs more info)

Interesting. This is definitely something to fix in the module itself, versus relying on something else. What I'm curious about is that the module never actually looks for a table tag - it skips right to <tbody>. Also, the filter keeps an offset counter, so it shouldn't care about newlines at all.

I'm thinking the problem is the '.*' being a little greedy. Can you try this patch and see if it fixes it?

AttachmentSize
354615_greedy_regex.patch 1.08 KB

#4

deviantintegral - January 6, 2009 - 02:47
Status:postponed (maintainer needs more info)» needs review

#5

robbm - January 6, 2009 - 14:18

Thanks. That seems to fix it here.

#6

deviantintegral - September 13, 2009 - 21:39
Status:needs review» fixed

Looks like I missed committing this patch - it's now committed for both DRUPAL-5 and DRUPAL-6--1.

#7

System Message - September 27, 2009 - 21:40
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.