Covert HTML to plain text

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

e.g

<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

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

You could use a HTML node with selector set to p

[{"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"]]}]
1 Like

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

1 Like

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

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

[{"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":[]}]
1 Like

Ah but .... :grinning:

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.

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
1 Like

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.

1 Like

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

1 Like

Doesn't this work?

image

Thanks for all the answers :slight_smile:

1 Like

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