I was looking for ideas to format the template email output from an automation.
This thread, combined with an old memory from my days of dabbling with JavaScript, prompted me to try something. There used to be an issue that required combining “carriage return” (/r) with “new line” (/n), to get a line break across all browsers so I tried it and it worked!
In home assistant, templates returning carriage returns depends on the destination. All carriage returns are removed when in attributes or sensor states.
Using payloads in messages or notifications or the markdown card, they are typically honored but you have to match what the OS requires.
Not templates, but I recently had a similar problem with card labels, and the only workaround I found was to use an entities card and add the label in a section, as shown. Other methods I tried - leaving a lbank line in the text, using \n, html markup, using a < after the colon, none of these worked. Labels within cards in the HA frontend are pretty important to get right, se there should be some means to avhieve this without using a complicated workaround.
Old post I know, but you can force a word wrap via card-mod. The following works on a mushroom template card and will move text to a second line if there’s overflow.
card_mod:
style:
mushroom-state-info$: |
span.primary {
white-space: normal !important;
}
I use br with a < in front and a > behind (when I tried it in the correct format it put a line break in this reply and didn’t show up!!) or \n to force line breaks in templates that I use for widgets on my Android phone. Works a treat.
As you can see from the example, br in lesser and more than brackets does the job nicely. Previously text would just wraparound but this hasn’t failed yet. Hope it helps.