How can I color text?

4,016 views
Skip to first unread message

cangaroo joe

unread,
Jan 30, 2014, 11:52:17 AM1/30/14
to tiddl...@googlegroups.com
Can I color a specific text in TW5?

Danielo Rodríguez

unread,
Jan 30, 2014, 6:41:48 PM1/30/14
to tiddl...@googlegroups.com
Hello.

Here you can grab the Macro to put text in red and a explanation of how to use it:

http://braintest.tiddlyspot.com/

cangaroo joe

unread,
Jan 30, 2014, 11:58:06 PM1/30/14
to tiddl...@googlegroups.com
Hi,

Very useful thank you very much.

Stephan Hradek

unread,
Jan 31, 2014, 2:16:55 AM1/31/14
to tiddl...@googlegroups.com

Small improvements


/*\
title: $:/macros/danielo/tinto.js
type: application/javascript
module-type: macro

\*/

(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Information about this macro
This is developed to put some text in color.

<<tinto "text" "green">>
<<tinto "text">> (will be red)
<$macrocall $name="tinto" color="pink" text="elephant"/>
*/


exports
.name = "tinfo";

exports
.params = [
        { name: "text" },
        { name: "color" }
];

/*
Run the macro
*/

exports
.run = function(text, color) {
    if( !text) text = "IMPORTANT";
    if( !color) color = "red";
return "<span style='color:" + color + "'>" + text + "</span>";
};

})();

cangaroo joe

unread,
Jan 31, 2014, 2:48:29 AM1/31/14
to tiddl...@googlegroups.com
Dear Stephan,

Thank you very much!

Danielo Rodríguez

unread,
Jan 31, 2014, 1:02:54 PM1/31/14
to tiddl...@googlegroups.com
Thank you Stephan. I thought about it, but I was too anxious to post my answer. I will put the color as a secondary option in a different macro. I want to have one macro per each color, just for keeping things simple and for readability of the non-rendered code.

Ton Gerner

unread,
Jan 31, 2014, 1:22:49 PM1/31/14
to tiddl...@googlegroups.com
Hi all,

What's wrong with the following?

\define red($text$)
@@color:red;
$text$
@@
\end

<<red "this is red">>

Cheers,

Ton

Stephan Hradek

unread,
Jan 31, 2014, 1:39:44 PM1/31/14
to tiddl...@googlegroups.com
  1. the \define red($text$) is wrong. It should be \define red(text)
  2. It's a macro that you need to put everywhere where you want red text

But this one might be interesting. Define a tiddler "red" containing:

\define red(text)

@@color:red;
$text$
@@
\end

<$macrocall $name="red" text={{!!title}}/>

and then use it like so:

this not red {{this is red||red}} this not red


Ton Gerner

unread,
Jan 31, 2014, 1:54:54 PM1/31/14
to tiddl...@googlegroups.com
Hi Stephan,



On Friday, January 31, 2014 7:39:44 PM UTC+1, Stephan Hradek wrote:
  1. the \define red($text$) is wrong. It should be \define red(text)

You are right. I was too fast ;)
  1. It's a macro that you need to put everywhere where you want red text
But you can put it into $:/core/ui/PageMacros

But this one might be interesting. Define a tiddler "red" containing:

\define red(text)
@@color:red;
$text$
@@
\end

<$macrocall $name="red" text={{!!title}}/>

and then use it like so:

this not red {{this is red||red}} this not red

Interesting!

Cheers,

Ton

Stephan Hradek

unread,
Jan 31, 2014, 2:14:51 PM1/31/14
to tiddl...@googlegroups.com

But you can put it into $:/core/ui/PageMacros

So what's the advantage over having it in a javascript macro? You need to reload in both cases. The disadvantage with the page macros is that you mess with the core. The advantage of making it a javascript macro is that you can easily take it over to any new TW.

Ton Gerner

unread,
Jan 31, 2014, 2:31:43 PM1/31/14
to tiddl...@googlegroups.com
The advantage is that you don't have to know javascript to make macros. I am not a programmer.

Ton

Danielo Rodríguez

unread,
Jan 31, 2014, 3:06:26 PM1/31/14
to tiddl...@googlegroups.com
The javascript macro has a global scope, so you don't have to define it on every tiddler you want to use it.

Danielo Rodríguez

unread,
Jan 31, 2014, 3:11:34 PM1/31/14
to tiddl...@googlegroups.com
I don't understand your tiddler transclussion. Why does it work with title? I expected it to render the title of the tiddler in red, not the text passed.

cmari

unread,
Jan 31, 2014, 3:36:27 PM1/31/14
to tiddl...@googlegroups.com
Stephan, in your "small improvements" version, is that a typo in export.name?  Should it be "tinto" instead of "tinfo"?

cmari



--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/groups/opt_out.

Stephan Hradek

unread,
Jan 31, 2014, 4:37:59 PM1/31/14
to tiddl...@googlegroups.com
"tinto" spanish (according to translate.google.com) for "colorize".

Stephan Hradek

unread,
Jan 31, 2014, 4:38:27 PM1/31/14
to tiddl...@googlegroups.com
The title is the text.

Stephan Hradek

unread,
Jan 31, 2014, 4:49:14 PM1/31/14
to tiddl...@googlegroups.com


Am Freitag, 31. Januar 2014 20:31:43 UTC+1 schrieb Ton Gerner:
The advantage is that you don't have to know javascript to make macros. I am not a programmer.

"Thou shalt not fear JavaScript" :D

Come on, Ton! You understand so much of TiddlyWiki, that little of JavaScript you need to know to transfer a TW macro to JS is nothing.

You can even use a bookmarklet I wrote. Look  at http://tw5magick.tiddlyspot.com and search for " Macro to Javascript Bookmarklet".

Drag that bookmarklet to you bookmarks.

Create a new tiddler.

Paste into that tiddler your macro.

Click your new bookmarklet and you'll get your macro translated to Javascript.

Alberto Molina

unread,
Jan 31, 2014, 5:08:20 PM1/31/14
to tiddl...@googlegroups.com
Hi Stephan,
 
"tinto" spanish (according to translate.google.com) for "colorize"

In this case automatic translation is not very accurate. "Tinto" means dark red and is used specially for red wine: "vino tinto". The verb "to colorize" can be translated by "colorear" or even by "tintar", which is shorter but less often used.

Cheers,
Alberto

Danielo Rodríguez

unread,
Jan 31, 2014, 5:54:51 PM1/31/14
to tiddl...@googlegroups.com
I was going to say what Alberto said :)

cmari

unread,
Jan 31, 2014, 6:02:52 PM1/31/14
to tiddl...@googlegroups.com
oops, I wasn't trying to question the word itself (!), merely (the consistency of) its spelling in the example macro. 
In order to make the macro work, I had to change the letter "f" to the letter "t" in the word "tinfo" in this line:
exports.name = "tinfo";
 




On Fri, Jan 31, 2014 at 2:54 PM, Danielo Rodríguez <rdan...@gmail.com> wrote:
I was going to say what Alberto said :)

Ton Gerner

unread,
Feb 1, 2014, 5:07:33 AM2/1/14
to tiddl...@googlegroups.com
Hi Stephan,


On Friday, January 31, 2014 10:49:14 PM UTC+1, Stephan Hradek wrote:


Am Freitag, 31. Januar 2014 20:31:43 UTC+1 schrieb Ton Gerner:
The advantage is that you don't have to know javascript to make macros. I am not a programmer.

"Thou shalt not fear JavaScript" :D

Long, long time ago I did some programming in BASIC and even a little bit in Pascal.
What remained is I am not "anxious" to have a look at code (although I don't understand half of it).

I just don't have the time to learn javascript ;)
I want to learn more about the list & filter stuff of TW5 itself.
 
Come on, Ton! You understand so much of TiddlyWiki, that little of JavaScript you need to know to transfer a TW macro to JS is nothing.

Using copy and paste it looks like you know a lot ;) Years of experience with TWclassic helps.

You can even use a bookmarklet I wrote. Look  at http://tw5magick.tiddlyspot.com and search for " Macro to Javascript Bookmarklet".

Drag that bookmarklet to you bookmarks.

Create a new tiddler.

Paste into that tiddler your macro.

Click your new bookmarklet and you'll get your macro translated to Javascript.

Yes, I know, I have a complete set of bookmarklets you made + a few of my own made with your bookmarkletmacro or just changing some characters in one of yours.

For sure, one day, I'll try the macro to javascript macro.

Cheers,

Ton
 

Alberto Molina

unread,
Jan 30, 2014, 12:18:27 PM1/30/14
to tiddl...@googlegroups.com
Can I color a specific text in TW5?

Try the following:

@@color:red; This is red text@@

@@color:green;
And this is green text.
@@

@@background-color:yellow;
And this is highlighted text in yellow.
@@

Danielo Rodríguez

unread,
Jan 30, 2014, 12:39:39 PM1/30/14
to tiddl...@googlegroups.com
Or you can wrap it inside a macro. I'm working on my public TW where you will find some of these.

chiposaur

unread,
Aug 22, 2018, 1:32:44 AM8/22/18
to TiddlyWiki
Thank you for this snippet. It's allowed me to do exactly what I want without a whole lot of extra stuff.
Reply all
Reply to author
Forward
0 new messages