Trying to split a status text on line break

I have a payload.status string with I believe line breaks. If I try to send the string as it is to my dashboard text node though, I have no line break. So I thought I try to split the string at the line break, then after each part I add a
and send it to the text node.
Not sure this is the right approach though

Here is a screen grab of the debug, as when I try and copy paste the line break symbol it doesnt work.
The screen grab has my attempt of splitting and on the right side status: "14/12 Thalia... is the string I need to split
(this is a calendar retrieved from google calendar via Homeseer)

msg.payload = msg.payload.status.split('</p>') 

Read the built in help...

image

And always use the great tools Node-RED provides...

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

As for how to split in a JS function - always go look on mdn


update...

Forgot to say, the symbol you see in the debug output is a newline character. In JS strings, you type these as \n - so you probably would want msg.payload = msg.payload.status.split('\n')

You could just use <pre></pre> tags around the text, to display it in the text node.
e.g.

[{"id":"53063e508fc2d807","type":"inject","z":"452103ea51141731","name":"text with line breaks","props":[{"p":"payload.status","v":"\"text one\\ntext two\\ntext three\\n\"","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":4100,"wires":[["4e323c6454e038e3","449c43256cc9d923"]]},{"id":"4e323c6454e038e3","type":"debug","z":"452103ea51141731","name":"debug 110","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":4040,"wires":[]},{"id":"449c43256cc9d923","type":"ui_text","z":"452103ea51141731","group":"2d4fe667.28f8ba","order":17,"width":0,"height":0,"name":"","label":"text","format":"<pre>{{msg.payload.status}}</pre>","layout":"row-spread","className":"","x":470,"y":3980,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":2,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

That looks the easiest solution as I was just trying to figure out how to display the array the function gives me. Now I came across the next (expected) issue. Its displaying 4 lines out of 6. I thought the text node might be restricted with how many lines it can display. Is there a way to change the height to get more lines in ? This changes all the time, as sometimes I can have 15 or so lines, other times only 1 or 2

I just seen it had been blocked by another text node, it does display more than 4 lines. But it doesnt look right, I think the height of the display field might need adjusting ?

This is from 2 text nodes

image

Playing around with the formatting to get it to display nicely. I can set the colour of the text, but then I have a indent on the first line. No idea where that comes from, its not there if I dont change the colour...
If I have spacers under the text field, it looks a bit nicer but it seems to center the text (height)

image

I use this in the text node value

<pre><font color= {{"red"}} > {{msg.payload.status}} </font></pre>

<font color="red"><pre>{{msg.payload.status}}</pre></font>

Notice no white space between > and {

I did not see that... the indent is now gone

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.