TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
8.07k stars 1.19k forks source link

[BUG] EvenRow and OddRow reversed? #8738

Open BurningTreeC opened 1 week ago

BurningTreeC commented 1 week ago

Describe the bug

While creating a table using a filter I wanted to apply the evenRow and oddRow classes. The way I did it, the first row "1" would get the oddRow class because "1" is odd if I recall correctly. Then I compared with how TiddlyWiki parses the | this is a table cell | this is another table cell | constructs and I've seen that the first row gets the evenRow class.

Is this a bug or is there a reason for this?

Expected behavior

I would expect the first row to have the oddRow class applied. I don't believe it should be evenRow - even if we think that it has index 0 - it's the 1st row.

To Reproduce

No response

Screenshots

No response

TiddlyWiki Configuration

Current prerelease

Additional context

No response

pmario commented 1 week ago

The table rowCount variable starts at 0

https://github.com/TiddlyWiki/TiddlyWiki5/blob/a58337d594bd23c9f0b5d96bef73fa586cf073bd/core/modules/parsers/wikiparser/rules/table.js#L142

pmario commented 1 week ago

The first row in a table should be the header, so the first "data" row is no. 1. -- But we can not change that any more.

BurningTreeC commented 1 week ago

Ok, so if we create a table for the wiki core using <table> tags, we should apply the "wrong" classes to the <tr> tags, correct?

pmario commented 1 week ago

Ok, so if we create a table for the wiki core using

tags, we should apply the "wrong" classes to the tags, correct?

It depends.

  1. yes ... If you want to create HTML code the is the same as a wikitext-table
  2. no ... If you intend to use CSS nth-of-type(even). It seems to start with 1

    tbody > tr:nth-of-type(even) {
        background-color: red;
    }

I think, I would go with option two to make it "valid" HTML code.


@Jermolene -- What do you think. Should we fix the problem with the current |core |table parser |? So it produces valid HTML table syntax

pmario commented 1 week ago

It seem at the moment the TW table syntax also counts a table-header if there is one. CSS nth-of-type(even) only uses the rows in the TBODY element and it starts with 1.

Jermolene commented 1 week ago

Hi @pmario in what way does the table parser not product valid HTML table syntax? I understand that the odd and even classes are reversed, but that is not an error of HTML syntax. Is there anything else wrong with it?

pmario commented 1 week ago

@Jermolene -- Sorry bad wording. There is nothing else wrong with it. Only the counter is wrong.

Jermolene commented 1 week ago

Then I think that sadly backwards compatibility constrains us to leave things as they area, but it would be great to update the documentation to call attention to it.