Displaying Hard Linebreaks in Text which is pulled from JSON Datatiddler

118 views
Skip to first unread message

scourfie...@gmail.com

unread,
Jan 5, 2021, 9:01:04 AM1/5/21
to TiddlyWiki
Hi all

I have some text stored in a json datatiddler which I'm pulling out using the transclude widget in index mode. 

I'd like to display this text with hard linebreaks respected, rather than the default tiddlywiki behaviour of ignoring single linebreaks and collapsing many linebreaks down into one. However I can't seem to do this, even when wrapping my transclude widget in triple double quotes as described here.

Any advice on how to do this? I suspect its something to do with how the json encodes text, but its not my area of expertise.

Thanks a ton

TW Tones

unread,
Jan 5, 2021, 7:29:15 PM1/5/21
to TiddlyWiki
Just a quick check;

If you use the transclude widget you can specify mode=block, have you tried this yet?

The triple quotes is more a WikiMarkup option for text within a tiddler. With transclusion and templates and more the inline vs block tends to be used. See

Tones

scourfie...@gmail.com

unread,
Jan 6, 2021, 4:42:56 AM1/6/21
to TiddlyWiki
Hi

Yes, I'm already using block mode. The code looks like this:

<$transclude tiddler="_planning_descriptions" index={{!!created}} mode=block/>

(I'm using this tiddler as a template and storing the textbox content in a json, indexed by the "created" timecode so that they can be renamed freely)

If I use inline mode, it doesn't respect any linebreaks at all (even double ones).

Thanks for your response

Mark S.

unread,
Jan 6, 2021, 12:32:29 PM1/6/21
to TiddlyWiki
Here's a solution. Hopefully there's a more elegant one. In my data, "test" is the data tiddler and "idx1" is the index.
This uses the new search-replace operator to replace linefeeds with html linebreaks, so that the text will display 
as expected.

<$vars eol="<br/>" lf="""
""">
<$set name=out value={{{ [[test]getindex[idx1]search-replace:g<lf>,<eol>] }}} >
<<out>>
</$set>
</$vars>

If you want output like TW, with single linefeeds ignored but double linefeeds recognized, then you could use the simpler:

<$wikify name=out text="""<$transclude tiddler=test index=idx1 mode=block />""" output="html">
<<out>>
</$wikify>


scourfie...@gmail.com

unread,
Jan 7, 2021, 5:24:55 AM1/7/21
to TiddlyWiki
Thanks Mark

I couldn't get your solution to work for some reason, but in my own time I found another one which seems to work and is a little cleaner. It involves applying a custom css class to the transclude widget.

Define the following somewhere:

.hardLineBreaks { word-break: normal; word-wrap: break-word; white-space: pre-wrap; } 

And then wrap the transclude widget as follows

@@.hardLineBreaks
<$transclude tiddler="_planning_descriptions" index={{!!created}} mode=block />
@@

This led to the intended behaviour for me.

Thanks all for your responses

Reply all
Reply to author
Forward
0 new messages