{"library":"micromark-util-encode","title":"Micromark HTML Character Encoder","description":"micromark-util-encode is a focused utility package within the micromark ecosystem, designed specifically for encoding dangerous HTML characters to ensure text is safe for embedding in HTML documents. Its current stable version is 2.0.1, part of the 2.x release line which maintains compatibility with Node.js 16 and higher. As a component of the unified collective, it follows a pragmatic release cadence often aligned with major micromark and Node.js version updates. This package differentiates itself by providing a robust, performant, and standards-compliant algorithm for HTML escaping, specifically tailored for the needs of markdown processors and related text transformation tools, where correctness and minimal overhead are critical. It is fully typed with TypeScript, ensuring good developer experience for static analysis and type safety.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install micromark-util-encode"],"cli":null},"imports":["import { encode } from 'micromark-util-encode'","import { encode } from 'micromark-util-encode'","import type { Value } from 'micromark-util-types'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { encode } from 'micromark-util-encode';\n\nconst unsafeHtml = '<script>alert(\"XSS\")</script> & <img src=\"x\" onerror=\"alert(\\'Error\\')\">';\nconst safeHtml = encode(unsafeHtml);\n\nconsole.log('Original:', unsafeHtml);\nconsole.log('Encoded:', safeHtml);\n// Expected output: Original: <script>alert(\"XSS\")</script> & <img src=\"x\" onerror=\"alert(\\'Error\\')\">\n// Expected output: Encoded: &lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt; &amp; &lt;img src=&quot;x&quot; onerror=&quot;alert(&#x27;Error&#x27;)&quot;&gt;","lang":"typescript","description":"Demonstrates how to import and use the `encode` function to escape common HTML special characters for safe embedding.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}