Macro for colored table cells

56 views
Skip to first unread message

MaxGyver

unread,
Jul 15, 2019, 2:35:21 PM7/15/19
to TiddlyWiki
Recently I have switched from TiddlyWiki Classic to TiddlyWiki 5. Now it has become complicated to color individual table cells. I have found this workaround (somewhere in this newsgroup):

<html><style>
/* compensating the cell padding */
.cell { margin:-1px -7px; padding:1px 7px; }
.positive { background-color:#afa; }
.negative { background-color:#faa; }
</style></html>

| | manual |h
| A |
<div class="cell negative">-</div> |
| B |
<div class="cell positive">+</div> |

This still requires a lot of typing. So I tried creating a macro for that:

\define pos() <div class="cell positive">+</div>

| | manual | macro |h
| A | <div class="cell negative">-</div> | - |
| B | <div class="cell positive">+</div> | <<pos>> |

But this doesn't work. The lower right table cell stays empty. What am I doing wrong? Is it possible to create a macro containing HTML at all?

Mark S.

unread,
Jul 15, 2019, 3:01:35 PM7/15/19
to TiddlyWiki
It's unclear how you're putting the pieces together, but the macro has to be defined at the top of the tiddler. This seems to work:

\define pos() <div class="cell positive">+</div>

<style>
/* compensating the cell padding */
.cell { margin:-1px -7px; padding:1px 7px; }
.positive { background-color:#afa; }
.negative { background-color:#faa; }
<
/style>

| | manual | macro |h
| A | <div class="cell negative">-</
div> | - |

| B | <div class="cell positive">+</div> | <<pos>> |

MaxGyver

unread,
Jul 15, 2019, 3:14:19 PM7/15/19
to TiddlyWiki
Awesome!!!

Thanks a lot!
Reply all
Reply to author
Forward
0 new messages