Skip to content

📧 DOM-based HTML email sanitizer for in-browser email rendering.

License

Notifications You must be signed in to change notification settings

mat-sz/lettersanitizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lettersanitizer

DOM-based HTML email sanitizer for in-browser email rendering.

workflow npm npm NPM

Used in react-letter and vue-letter.

Installation

lettersanitizer is available on npm, you can install it with either npm or yarn:

npm install lettersanitizer
# or:
yarn install lettersanitizer

Example usage

import { sanitize } from 'lettersanitizer';

sanitize('<b>test</b><script>test</script>', '', { id: 'test' });
// <div id="test"><b>test</b></div>

sanitize function

lettersanitizer exposes a sanitize function that uses DOMParser to sanitize the HTML content of messages and returns HTML text.

text is used for fallback text in case of no HTML source being available. Plain text in that case is processed into safe HTML output.

interface SanitizerOptions {
  id?: string;
  dropAllHtmlTags?: boolean;
  rewriteExternalResources?: (url: string) => string;
  rewriteExternalLinks?: (url: string) => string;
  allowedSchemas?: string[];
  preserveCssPriority?: boolean;
  noWrapper?: boolean;
}

function sanitize(html: string, text?: string, options?: SanitizerOptions);

About

📧 DOM-based HTML email sanitizer for in-browser email rendering.

Resources

License

Stars

Watchers

Forks

Packages

No packages published