Power automate html to text line breaks

Hi, Guys.

When using "HTML to Text", line breaks and spaces become abnormal.
Mail is sent in the following format.
(I can not show the real mail. Please forgive me.)

blah-blah-blah 
blah-blah-blah 
blah-blah-blah

2019/06/11 18:57:30 System_error_5_occurred 
525866,AABBCCDDEEFFGGHH

2019/07/19 21:49:13 System_error_5_occurred 
535896,OOKKOOOONJJJOOOO

2019/08/25 13:38:34 System_error_5_occurred 
596322,PPKKOKKKKKKMNJJK

2020/01/01 13:30:27 System_error_5_occurred 
574147,OOKKAAAAAAAAAAAA

blah-blah-blah 
blah-blah-blah 
blah-blah-blah

If you do conversion, the space will disappear or you may end up with unusual newlines at unwanted locations.

blah-blah-blah blah-blah-blah blah-blah-blah 2019/06/11 18:57:30
System_error_5_occurred 525866,AABBCCDDEEFFGGHH2019/07/19 21:49:13
System_error_5_occurred 535896,OOKKOOOONJJJOOOO2019/08/25 13:38:34
System_error_5_occurred 596322,PPKKOKKKKKKMNJJK2020/01/01 13:30:27
System_error_5_occurred 574147,OOKKAAAAAAAAAAAAblah-blah-blah 
blah-blah-blah blah-blah-blah

I want to keep my shape even after conversion if I can do it.
Since I am getting the number of characters, I am troubled because it causes an error if it changes.
I can use it repeatedly as a "date", "error code", "ID" and "content" records.

For example ...

2019/06/11 18:57:30 System_error_5_occurred 525866,AABBCCDDEEFFGGHH

Thanks.

HI @RLSid17 

Can you check something for me? In the long string that has the whole email, can you localize the "Ceiling is leaking" and check if the character is precise "\n"? For example, it could be
or \\n, so we're sure it works.

If not, can you please copy the small HTML section so we can replicate it and try to help you?

Cheers
Manuel

------------------------------------------------------------------
If I have answered your question, please mark it as "Accept as Solution." It will help other members find the solution faster. If you like my response, please give it a Thumbs Up. ?
Otherwise, reply to it, and the community will do its best to help you.

There are times when HTML is not helpful, being for parsing the text or saving it. Removing HTML tags is a pain; that’s why the “HTML to Text” action is a god-send. It removes the HTML tags and presents us with the “raw” text that we can use to do whatever we want. Let’s explore it.

Where to find it?

You can find it under Standard.

Power automate html to text line breaks

“Content Conversion”

Power automate html to text line breaks

Here’s what it looks like.

Power automate html to text line breaks

Pro Tip:
Power Automate tends to save the most common actions on the main screen, so check there before going through the full hierarchy. Also, you can use the search to find it quickly.

Usage

You can use any element to add to the “HTML to text” action. For example, a trigger parameter, variable, compose or even provide yourself the raw HTML in the field.

Power automate html to text line breaks

Limitations

There are a few things to keep in mind. First in the conversion and then in the size of the HTML.

Conversion limitations

I’ll list them as they are in Microsoft’s Reference and then provide some context:

  • The max line length is 80 characters; afterward, a line break will follow.
  • For link elements that follow the structure, text the result becomes text text[link]. If text and link are the same, only text will be present.
  • Headers (

    ,

    Etc) are uppercased.

  • Heading cells (
) are uppercased.
  • Empty lines will be trimmed as a space-saving measure.
  • Unordered lists will use * as a prefix.
  • There will be three spaces between data table columns.
  • There will be 0 empty lines between data table rows.
  • Links  href='#...' will be ignored.
  • New lines \n from the input, HTML will be collapsed into space as any other HTML whitespace characters.
  • These are not limitations per se but notice a pattern in the conversion. For example, the links will be converted to text[link] the markdown reference (some “flavors” of markdown will represent it differently, but this is how Microsoft represents it). The same with the * that represents in markdown an unordered list. This does not mean that the “HTML to text” is converting HTML to markdown, but since you’re aware of what will be converted, you can use them to your advantage.

    Size limitations

    Since HTML files can be pretty significant, Microsoft imposes a 5Mb size in the file and a 250 HTML DOM Tree. DOM stands for “Document Object Model,” and you can think of it this way. So if you have an HTML file, you’ll have:

    Power automate html to text line breaks

    As you can see, it’s a tree structure. Inside the text, you can have more links, tables, images, and more. The limitation indicates that you can only have nested up to 250 branches of the tree. It may look enormous, but HTML can get very complex very quickly, so be aware of this limit if you’re not getting all values converted correctly.

    Recommendations

    Here are some things to keep in mind.

    First, convert and then format.

    As you can notice, the “HTML to Text” allows for the formatting of the value.

    Power automate html to text line breaks

    I would recommend, though, that you leave it “as is,” convert the HTML to text, and in the following action, do the necessary formatting.

    It’s essential to have the “source” text unchanged. The “HTML to text” action will convert the value that you can refer to in any part of your Flow. This is important because, in the future, you may want to convert the text before you do the formatting, so you have the division of work done already.

    Also, it’s essential to have only one “step” per action. We’re converting the text in this action, enabling us to debug to see if the text was correctly converted. If we apply any formatting, we won’t know if the conversion or the formatting made the changes that we see.

    Be careful with the limitations.

    Both file size and DOM branch number can be a problem in complex HTML. Break it down and parse it in sections if you have to. Find a point where you can safely break your HTML into sections, like
    for example, and then combines all of them in the end.

    Don’t try to do it yourself.

    It’s complex to parse HTML, so don’t try to do it yourself. If you have huge files, break them down and use the “HTML to Text” action to parse them. There are many hidden complexities in parsing HTML, so always defer to the actions to do the heavy lifting for you.

    Name it correctly

    The name is super important in this case since we’re getting information from somewhere. It’s important to know where it comes from and what it is. Always build the name so that other people can understand what you are using without opening the action and checking the details.

    Always add a comment.

    Adding a comment will also help to avoid mistakes. Indicate where the HTML comes from and what you are expecting to get. It’s essential to enable faster debugging when something goes wrong.

    Always deal with errors.

    Have your Flow fail graciously when the file doesn’t exist and notify someone that something failed. It’s horrible to have failing Flows in Power Automate since they may go unlooked for a while or generate even worse errors. I have a template that you can use to help you make your Flow resistant to issues. You can check all details here.

    Am I missing something? Leave a comment or interact on Twitter. Let’s work together to make this reference as complete as we can

    Back to the Power Automate Action Reference.

    Photo by Pankaj Patel on Unsplash

    How do you add a new line in string Power Automate?

    Add 'Enter' into the expression Add opening single quote, press Enter on your keyboard, and then add the closing single quote. It'll split the expression on multiple lines, but Power Automate will translate it as a new line character.

    Is HTML in Power Automate?

    The Create HTML Table action in Power Automate is a useful tool, but lacks any formatting or styling options. In this blog, we'll see how to create a HTML table in Power Automate.

    What does HTML to text do?

    The “HTML to text” action will convert the value that you can refer to in any part of your Flow. This is important because, in the future, you may want to convert the text before you do the formatting, so you have the division of work done already.