# Covert HTML to plain text

**URL:** <https://discourse.nodered.org/t/covert-html-to-plain-text/75079>\
**Category:** General\
**Created:** [12 February 2023 17:59 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079 "2023-02-12T17:59:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [12 February 2023 17:59 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079/1 "2023-02-12T17:59:48Z")

</div>

Is there a easy contrib node that convert small bits of HTML into a plainer format

e.g

```auto
<p>My beautiful lil pup Mayhem is one year old today. </p><p>For every boost or favorite I’ll pet her and tell her she’s a good girl. </p><p>🎂 🐶 </p><p><a href="https://mas.to/tags/dogstodon" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>dogstodon</span></a> <a href="https://mas.to/tags/dogs" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>dogs</span></a> <a href="https://mas.to/tags/puppy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>puppy</span></a> <a href="https://mas.to/tags/birthday" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>birthday</span></a> <a href="https://mas.to/tags/dog" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>dog</span></a> <a href="https://mas.to/tags/pet" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>pet</span></a></p>

```

to how it looks on Mastodon itself

```auto
My beautiful lil pup Mayhem is one year old today. 

For every boost or favorite I’ll pet her and tell her she’s a good girl. 

🎂 🐶 

#dogstodon #dogs #puppy #birthday #dog #pet

```

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [12 February 2023 18:10 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079/2 "2023-02-12T18:10:38Z")

</div>

You could use a HTML node with selector set to p

```auto
[{"id":"68c213fc92e5f97e","type":"inject","z":"719a883a54bf61c7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<p>My beautiful lil pup Mayhem is one year old today. </p><p>For every boost or favorite I’ll pet her and tell her she’s a good girl. </p><p>🎂 🐶 </p><p><a href=\"https://mas.to/tags/dogstodon\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>dogstodon</span></a> <a href=\"https://mas.to/tags/dogs\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>dogs</span></a> <a href=\"https://mas.to/tags/puppy\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>puppy</span></a> <a href=\"https://mas.to/tags/birthday\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>birthday</span></a> <a href=\"https://mas.to/tags/dog\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>dog</span></a> <a href=\"https://mas.to/tags/pet\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>pet</span></a></p>","payloadType":"str","x":1025,"y":390,"wires":[["5d8954f2d4562e6a"]]},{"id":"de5dfc3ca3520b2f","type":"debug","z":"719a883a54bf61c7","name":"debug 71","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1335,"y":390,"wires":[]},{"id":"5d8954f2d4562e6a","type":"html","z":"719a883a54bf61c7","name":"Link","property":"payload","outproperty":"payload","tag":"p","ret":"text","as":"multi","x":1180,"y":390,"wires":[["de5dfc3ca3520b2f"]]}]

```

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [12 February 2023 18:15 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079/3 "2023-02-12T18:15:30Z")

</div>

This gives 1 payload per line, but you could just add a join node to convert to 1 sting if needed.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2023 18:17 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079/4 "2023-02-12T18:17:09Z")

</div>

Set the selector to html in the HTML node and you will get all the text, including the span, in one text element. no join required

should return

```auto
My beautiful lil pup Mayhem is one year old today. For every boost or favorite I’ll pet her and tell her she’s a good girl. 🎂 🐶 #dogstodon #dogs #puppy #birthday #dog #pet

```

example flow

```auto
[{"id":"6548356dba8d2e98","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<p>My beautiful lil pup Mayhem is one year old today. </p><p>For every boost or favorite I’ll pet her and tell her she’s a good girl. </p><p>🎂 🐶 </p><p><a href=\"https://mas.to/tags/dogstodon\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>dogstodon</span></a> <a href=\"https://mas.to/tags/dogs\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>dogs</span></a> <a href=\"https://mas.to/tags/puppy\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>puppy</span></a> <a href=\"https://mas.to/tags/birthday\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>birthday</span></a> <a href=\"https://mas.to/tags/dog\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>dog</span></a> <a href=\"https://mas.to/tags/pet\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>pet</span></a></p>","payloadType":"str","x":70,"y":4480,"wires":[["7618a32a405b0a4b"]]},{"id":"7618a32a405b0a4b","type":"html","z":"da8a6ef0b3c9a5c8","name":"","property":"payload","outproperty":"payload","tag":"html","ret":"text","as":"single","x":290,"y":4480,"wires":[["51cd62bd47b3cbac"]]},{"id":"51cd62bd47b3cbac","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 231","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":4520,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [12 February 2023 18:29 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079/5 "2023-02-12T18:29:15Z")

</div>

Ah but .... 😀

It its easier to replicate Simon's request, with 4 lines of text using either 4 payloads or joining to create 1 string with carriage returns.

```auto
12/02/2023, 18:24:14node: debug 71
msg.payload : string[176]
string[176]
My beautiful lil pup Mayhem is one year old today. 
For every boost or favorite I’ll pet her and tell her she’s a good girl. 
🎂 🐶 
#dogstodon #dogs #puppy #birthday #dog #pet

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2023 18:38 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079/6 "2023-02-12T18:38:54Z")

</div>

True for this example html, but what if other html has div or span or a multitude of html tags containing the text required. Just added `html` for information purposes.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [12 February 2023 18:44 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079/7 "2023-02-12T18:44:41Z")

</div>

To be fair, as a mere mortal, I wasn't aware that just using html was even an option (can't see it documented) 😉  
So I also learned something useful for other cases.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [12 February 2023 20:10 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079/8 "2023-02-12T20:10:19Z")

</div>

Doesn't this work?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a4a4356d9d85abde306abcc8e62d597f3be8f5a9.png)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [13 February 2023 08:09 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079/9 "2023-02-13T08:09:23Z")

</div>

Thanks for all the answers 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 February 2023 08:09 UTC](https://discourse.nodered.org/t/covert-html-to-plain-text/75079/10 "2023-02-27T08:09:45Z")

</div>

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