Skip to main content

Notifications

Power Automate - Using Connectors
Unanswered

Avoiding Unwanted Line Breaks in HTML to Plain Text Conversion in Power Automate

(0) ShareShare
ReportReport
Posted on by

Hello everyone,

I am seeking help with an issue related to HTML to plain text conversion using Html to text (Preview) action in Power Automate. My input HTML, when converted to plain text, is producing unusual line breaks represented as "\n".

 

Here's a sample of my Input and Output:

Input:

<p>CompanyXYZ managed the construction of Building123. At a significant height, the structure was one of the tallest residential buildings in the region at the time of completion. Located in one of the city's most desired neighborhoods, the large square foot footprint boasts over a substantial amount of contiguous feet of frontage on Main Street, alongside some of the most prestigious retail space in the city.</p>

Output:

CompanyXYZ managed the construction of Building123. At a significant height, the\nstructure was one of the tallest residential buildings in the region at time\nof completion. Located in one of the city's most desired neighborhoods, the\nlarge square foot footprint boasts over a substantial amount of contiguous feet of\nfrontage on Main Street, alongside some of the most prestigious retail\nspace in the city.\n

So here, the newline characters that appear between "the" and "structure", "time" and "of", and "retail" and "space" are unwanted.

 

I am aware that I could use a replace function to replace the "\n" with a space, but that approach also replaces the actual line breaks that I need to keep. I am looking for a method that can distinguish between these "unusual" newline characters and the intentional ones in the original HTML.

 

Any help or guidance on how to achieve this within Power Automate would be greatly appreciated.

 

Thanks in advance!

  • ManishSolanki Profile Picture
    ManishSolanki 15,075 on at
    Re: Avoiding Unwanted Line Breaks in HTML to Plain Text Conversion in Power Automate

    Hi @hasannaqvi 

     

    To get the exact content (including new line) between paragraph tag '<p>', you can make use of xpath() function. It accepts valid xml or html and using api parses the tags and fetches the content of a tags.

     

    I tried extracting the content using the sample text shared by you. I have stored the original text in the "Compose" action:

    ManishSolanki_0-1691385109036.png

     

    Next, add an another "Compose" action, here will add an expression in the expression box. Inside expression box, we will add a formula to extract the content of <p> tag:

    ManishSolanki_1-1691385229611.png

    Expression used in the above screenshot:

    xpath(xml(outputs('Compose')),'string(/p)')

    Note: In the above example, the root tag is <p> but in the actual case, you need to traverse from root tag to the <p> tag to get the content. 

     

    This way you will be able to retrieve the new line breaks within the content along with the content in the xml node or html tag.

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

    Thanks

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,422

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,711

Leaderboard

Featured topics