pipr.tools
Pipes
Clean Email Strip formatting from pasted email for clean plain text Clean AI Output Clean plain text from ChatGPT or AI output Decode & Format JWT Decode a JWT and pretty-print header and payload Word Frequency Count word frequency in text

html-to-text Convert HTML to plain text preserving line breaks

</> Web
Input0 chars
Output0 chars

Examples

Convert an HTML email to readable plain text

Usage
"<div style="font-family:Arial">Hi team,</div><div><br></div>..." | html-to-text

Extract text from an HTML newsletter preserving structure

Usage
"<p>Welcome to our newsletter!</p><p>Here&rsquo;s what&apos;s..." | html-to-text

Get plain text from an HTML calendar invite

Usage
"<table><tr><td>Meeting:</td><td>Monday 9am</td></tr></table>..." | html-to-text
View source
(input)=>{
                let out = input;
                out = out.replace(/<\/(p|div|tr|table|blockquote|h[1-6])>/gi, "\n\n");
                out = out.replace(/<br\s*\/?>/gi, "\n");
                out = out.replace(/<li[^>]*>/gi, "\n- ");
                out = out.replace(/<[^>]+>/g, "");
                out = out.replace(/&nbsp;/gi, " ");
                out = out.replace(/&amp;/g, "&");
                out = out.replace(/&lt;/g, "<");
                out = out.replace(/&gt;/g, ">");
                out = out.replace(/&quot;/g, '"');
                out = out.replace(/&#39;/g, "'");
                out = out.replace(/&#(\d+);/g, (_, n)=>String.fromCharCode(n));
                out = out.replace(/&#x([0-9a-f]+);/gi, (_, h)=>String.fromCharCode(parseInt(h, 16)));
                return out;
            }