simple-marked-sanitizer
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,7 +0,23 @@ | ||
export default class SimpleMarkedSanitizer { | ||
construct(): SimpleMarkedSanitizer; | ||
export as namespace SimpleMarkedSanitizer; | ||
elementWhiteList(list: string[]): SimpleMarkedSanitizer; | ||
attributeWhiteList(list: {[key: string]: string[]}): SimpleMarkedSanitizer; | ||
export = SimpleMarkedSanitizer; | ||
declare class SimpleMarkedSanitizer { | ||
constructor(); | ||
elementWhiteList(): Array<string>; | ||
elementWhiteList(v: Array<string>): SimpleMarkedSanitizer; | ||
attributeWhiteList() : { [key: string]: Array<string> } | ||
attributeWhiteList(v: { [key: string]: Array<string> }): SimpleMarkedSanitizer; | ||
debug(): boolean; | ||
debug(v: boolean): SimpleMarkedSanitizer; | ||
getSanitizer(): (str: string) => string; | ||
} | ||
declare namespace SimpleMarkedSanitizer { | ||
const ELEMENT_WHITELIST: string[]; | ||
const ATTRIBUTE_WHITELIST: { [key: string]: Array<string> }; | ||
} |
23
index.js
@@ -210,5 +210,9 @@ (function(root) { | ||
this._attributeWhiteList = ATTRIBUTE_WHITELIST; | ||
this._debug = false; | ||
} | ||
elementWhiteList(v) { | ||
if (!v) { | ||
return this._elementWhiteList; | ||
} | ||
this._elementWhiteList = v; | ||
@@ -219,2 +223,5 @@ return this; | ||
attributeWhiteList(v) { | ||
if (!v) { | ||
return this._attributeWhiteList; | ||
} | ||
this._attributeWhiteList = v; | ||
@@ -224,2 +231,10 @@ return this; | ||
debug(v) { | ||
if (typeof(v) === "undefined") { | ||
return this._debug; | ||
} | ||
this._debug = v; | ||
return this; | ||
} | ||
getSanitizer() { | ||
@@ -230,7 +245,7 @@ return this.sanitize.bind(this); | ||
sanitize(tag) { | ||
if (tag.startsWith("</")) { | ||
return this.sanitizeCloseTag(tag); | ||
} else { | ||
return this.sanitizeOpenTag(tag); | ||
const result = tag.startsWith("</") ? this.sanitizeCloseTag(tag) : this.sanitizeOpenTag(tag); | ||
if (this._debug) { | ||
console.log(`[SimpleMarkedSanitizer] ${tag} -> ${result}`); | ||
} | ||
return result; | ||
} | ||
@@ -237,0 +252,0 @@ |
{ | ||
"name": "simple-marked-sanitizer", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Simple sanitizer for marked", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -47,3 +47,3 @@ # simple-marked-sanitizer | ||
"*": [class", "id", "style"] // `*` means these attributes are allowed to all tags. | ||
}); | ||
}).debug(true); // If you want to see conversion result in console.log, switch debug flag to true. | ||
@@ -50,0 +50,0 @@ const htmlString = marked(markdownString, { |
@@ -6,3 +6,3 @@ const assert = require("chai").assert; | ||
const DEFAULT_SANITIZER = new Sanitizer(); | ||
const DEFAULT_SANITIZER = new Sanitizer().debug(true); | ||
@@ -9,0 +9,0 @@ function apply(input, sanitizer) { |
15742
437