[MyCode] Tables
#1
This is my first attempt at anything like this so if there are better ways of coding it or you think other things should be added then feel free to do so. As someone who knew almost nothing about HTML codes before this project and still knows almost nothing I'm sure you can offer insight and help to make this better.

First of all the basics.

Regular Expression \[table\](.*?)\[/table\]
Replacement         <table class="{option}" BORDER=1 width="10%">$1</table>

Regular Expression \[tr\](.*?)\[/tr\]
Replacement         <tr class="{option}">$1</tr>

Regular Expression \[td\](.*?)\[/td\]
Replacement         <td class="{option}">$1</td>

With this you can create basic tables. Maybe everyone else knows this already but I found this quite hard to find one that would actually work for people as unknowing as me.

You can add to this with a header cell,

Regular Expression \[th\](.*?)\[/th\]
Replacement         <th class="{option}" BGCOLOR="#D8BFD8">$1</th>

I coloured mine but you can remove BGCOLOR="#D8BFD8" if you want or change the colour entirely by changing the Hex code at the end.

There is also a custom version that allows you to edit the colour on creation.


Regular Expression \[th=(.*?)\](.*?)\[/th\]
Replacement         <th class="{option}" BGCOLOR="$1">$2</th>

So you would be typing [th=#000000][/th] and can change the colour at will.

There is no reason you can't add BGCOLOR= to other tags here to change their colour as well.

To make tables look better for display infomation I tried to allow for wider tables but the only way I could think of was a custom width with [table width=][/table]

Regular Expression \[table width=(.*?)\](.*?)\[/table\]
Replacement         <table class="{option}" BORDER=1 width="$1%">$2</table>

So that the number you type is a percentage.

The only problem with all this is that if someone gets the code wrong, it effects the forum layout in quite extreme ways on that page. Is there a way of having it just not work if its not imputed properly?

Where would I be looking to edit if I was to change the table characteristics? To say an thin black line?

I hope you will point out any errors and if you were like me struggling to find this sort of thing can put it to good use.

Example

A minor update,

Spans have been added to the header and normal cells

For normal cells

Regular Expression \[td colspan=(.*?)\](.*?)\[/td\]
Replacement         <td colspan="$1">$2</td>

So the first entry is the number of cells spanned

And as it'll take the colour out of headers,

Regular Expression \[th colspan=(.*?)\](.*?)\[/th\]
Replacement         <th class="{option}" BGCOLOR="#D8BFD8" colspan="$1">$2</th>

Row span would be the same if you needed it, just replace colspan= with rowspan=
Reply
#2
This is more better and more complicated than what I can do

Good Job
Proud Owner of The HD Forums since Aug 2009
[Image: dp93py.png]
Reply
#3
I'll suggest to use the following
regular expression: \[td(( colspan=\d+| rowspan=\d+| bgcolor=\#[a-f0-9]{6})*)\](.*?)\[/td\]
replacement:        <td class={option} $1>$3</td>

then you can use colspan, rowspan and bgcolor in any combination or sequence, including without them. for example

[td]test[/td]
[td colspan=2]test[/td]
[td colspan=2 rowspan=3]test[/td]
[td colspan=2 bgcolor=#ab34ef]test[/td]

also you can easily add any necessary attribute, for example 'align' and 'width'
regular expression: \[td(( width=\d+\%| align=(left|center|right)| colspan=\d+| rowspan=\d+| bgcolor=\#[a-f0-9]{6})*)\](.*?)\[/td\]
replacement:        <td class={option} $1>$4</td>

example:
[td width=40% colspan=2 align=center]test[/td]

please pay attention, this will not work with multiple spaces, if you want to allow that, in regular expression add + after each space.
vim it!^[:wq
Reply
#4
That is very nice, thank you very much.

I'll look into fitting that into a new set of mycodes once I've played around with it a little.
Reply
#5
No matter what I try I simply cannot get this to work. Soooooooo many Regular Expressions and such that it's impossible to follow these steps (they are very sporadic).

Would be a nice plugin though.
Reply
#6
a very simple plugin
.zip   mycode_table.php.zip (Size: 861 bytes / Downloads: 383)

you can change table style inside of plugin.
vim it!^[:wq
Reply
#7
ah, nice asmile Wink
Hello, Welcome to MyBB Indonesia to get local support
My 'Simple' Unique Plugin here Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)