stripHtml with \n regex html (v6)

Revision 6 of this benchmark created on


Preparation HTML

<script src="https://cdn.jsdelivr.net/npm/string-strip-html/dist/string-strip-html.umd.js"></script>

Setup

const { stripHtml } = stringStripHtml;
const html = "<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'><title>Basic HTML Example</title></head><body><h1>This is a Heading</h1><p>This is a paragraph of text. It can contain multiple lines.</p><p>This is another paragraph.</p><a href='https://www.example.com'>This is a link to example.com</a><img src='image.jpg'alt='An example image'><ul><li>Item one</li><li>Item two</li><li>Item three</li></ul><ol> <li>First item</li><li>Second item</li> </ol><pre>This is preformatted text.It preserves spaces and line breaks.</pre><br><hr> <small>This is small text.</small><p><b>This is bold text.</b></p><p><i>This is italic text.</i></p><p><strong>This is strong text.</strong></p> <p><em>This is emphasized text.</em></p> <p><mark>This is marked text.</mark></p></body></html>';"

Test runner

Ready to run.

Testing in
TestOps/sec
Without \n regex
return stripHtml(html).result;
ready
With \n regex
const htmlToStrip = html
      .replace(/<br\s*\/?>/gi, "\r\n")
      .replace(/<\/p\s*>/gi, "\r\n</p>");
return stripHtml(htmlToStrip).result;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.