New [table], [tr], [th], [td] bbCodes

Post Reply
User avatar
Dave Keenan
Site Admin
Posts: 1962
Joined: Tue Sep 01, 2015 2:59 pm
Location: Brisbane, Queensland, Australia
Contact:

New [table], [tr], [th], [td] bbCodes

Post by Dave Keenan »

As requested by @volleo6144 here, a table like this:

NameAge
John65
Gitte40
Sussie19

can now be generated by this:

[table]
[tr][th]Name[/th][th]Age[/th][/tr]
[tr][td]John[/td][td]65[/td][/tr]
[tr][td]Gitte[/td][td]40[/td][/tr]
[tr][td]Sussie[/td][td]19[/td][/tr]
[/table]

tr = table row
th = table heading
td = table data

User avatar
Dave Keenan
Site Admin
Posts: 1962
Joined: Tue Sep 01, 2015 2:59 pm
Location: Brisbane, Queensland, Australia
Contact:

Re: New [table], [tr], [th], [td] bbCodes

Post by Dave Keenan »

[table=<border-width>]

I've added an optional parameter to the [table] bbCode which is the width of the table's borders. If you omit it, the table has no borders, as before. For example, this:

NameAge
John65
Gitte40
Sussie19

can now be generated by this:

[table=1]
[tr][th]Name[/th][th]Age[/th][/tr]
[tr][td]John[/td][td]65[/td][/tr]
[tr][td]Gitte[/td][td]40[/td][/tr]
[tr][td]Sussie[/td][td]19[/td][/tr]
[/table]

tr = table row
th = table heading (also thl, thc, and thr for left, center, and right aligned headings)
td = table data (also tdl, tdc, and tdr for left, center, and right aligned data)

User avatar
Dave Keenan
Site Admin
Posts: 1962
Joined: Tue Sep 01, 2015 2:59 pm
Location: Brisbane, Queensland, Australia
Contact:

Re: New [table], [tr], [th], [td] bbCodes

Post by Dave Keenan »

There's a gotcha with the new [table=<border-width>]. Because of the way it is implemented, you can't have tables with and without borders (or with different widths of border) in the same post. The last one wins, and overrides the others.

User avatar
ᴄᴍʟᴏᴇɢᴄᴍʟᴜɪɴ
Site Admin
Posts: 1643
Joined: Tue Feb 11, 2020 3:10 pm
Location: San Francisco, California, USA
Real Name: Douglas Blumeyer (he/him/his)
Contact:

Re: New [table], [tr], [th], [td] bbCodes

Post by ᴄᴍʟᴏᴇɢᴄᴍʟᴜɪɴ »

It was even worse than that, I realized: it would affect every table on the same page, including others'.

I did a bit of experimentation with generating random IDs for each table to scope their styles, but then I couldn't reliably find the right table to tag with that ID. And I also tried generating the tables with JavaScript, but then it can't reliably know where to place them on the page. It's kind of a catch-22. We could also make it work if we could figure out how to have bbCode generate the random number, so it could easily put it in both places, linking them. Or we could make this work if we educated all users to provide a second attribute to their table bbCodes when providing it, but that's horrible of course: replacing the convenience of the code with fear of messing it up!

But that gives me the idea to simply use the width value already provided by the user as the ID. So how's this:

NameAge
John65
Gitte40
Sussie19

NameAge
John65
Gitte40
Sussie19

I think that'll do for now.

Post Reply