lettersanitizer
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -154,5 +154,7 @@ "use strict"; | ||
sanitizeCssStyle(element.style, allowedSchemas, preserveCssPriority, rewriteExternalResources); | ||
// Add rel="noopener noreferrer" to <a> | ||
if (tagName === 'a') { | ||
// Add rel="noopener noreferrer" to <a> | ||
element.setAttribute('rel', 'noopener noreferrer'); | ||
// Add target="_blank" to <a> | ||
element.setAttribute('target', '_blank'); | ||
} | ||
@@ -159,0 +161,0 @@ } |
{ | ||
"name": "lettersanitizer", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "DOM-based HTML email sanitizer for in-browser email rendering.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -31,17 +31,26 @@ <h1 align="center">lettersanitizer</h1> | ||
```ts | ||
export function sanitize( | ||
html: string, | ||
text?: string, | ||
options?: SanitizerOptions | ||
) { | ||
let contents = html ?? ''; | ||
if (contents?.length === 0 && text) { | ||
contents = sanitizeText(text) | ||
.split('\n') | ||
.map(line => '<p>' + line + '</p>') | ||
.join('\n'); | ||
} | ||
import { sanitize } from 'lettersanitizer'; | ||
return sanitizeHtml(contents, options ?? {}); | ||
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. | ||
```ts | ||
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); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23841
654
56