javascript macro: Linebreaks

63 views
Skip to first unread message

juan erasmo gomez

unread,
Apr 28, 2017, 12:22:25 AM4/28/17
to TiddlyWiki
Hi

I'm writing a small macro to create a table. The idea behind the macro is that I'll receive the number of columns as a parameter and work from there.
So far I've been able to create the first line of the table, but I haven't found a way to add a line break and to add the second row of the table:

/*\
title: TrxMacro2
type: application/javascript
module-type: macro
\*/

(function(){

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

exports
.name = "trxmacro";

exports
.params = [
 
{name: "columns"}
];

/*
Run the macro
*/

exports
.run = function(columns) {
 
var ret+="|";
 
var i;
 
for(i=0; i < columns; i++) {
 ret
+=" column "+(i+1) + " |";
 
}
 ret
+="\n";
 
return ret;
};

})();

How can I add a linebreak to the return of my macro?

Thanks,

BJ

unread,
Apr 28, 2017, 1:53:14 AM4/28/17
to TiddlyWiki
Hi Juan,
you cannot see single linebreaks in tiddlerwiki5, only double ones. So to create two rows of a table

ret = "|a1|b1|\n|a2|b2|\n\n"

all the best

BJ

xanato...@gmail.com

unread,
Apr 28, 2017, 1:56:35 AM4/28/17
to TiddlyWiki
Hi Juan,

you must add a newline for every row.
And each row must itself start a row with a "|" pipe symbol.
See below:

ret+="|column "+(i+1) + " |"+"\n";

That should do what you want

On Friday, April 28, 2017 at 6:22:25 AM UTC+2, juan erasmo gomez wrote:
/*\
title: TrxMacro2
type: application/javascript
module-type: macro
\*/

(function(){

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

exports
.name = "trxmacro";

exports
.params = [
 
{name: "columns"}
];

/*
Run the macro
*/

exports
.run = function(columns) {

 
var ret="";

 
var i;
 
for(i=0; i < columns; i++) {

 ret
+="|column "+(i+1) + " |"+"\n";
Reply all
Reply to author
Forward
0 new messages