Projects Presenteer.js BetterExamples.js FilteredPaste.js

FilteredPaste.js

Source code at https://github.com/willemmulder/FilteredPaste.js

What does it do?

FilteredPaste.js is a jQuery plugin that filters any pasted input so that your application gets clean input, without any tags or attributes that you don't want. It supports native undo with control+z. IE and Opera are not supported yet.

// Simply works like this
$("#anytextarea").filteredPaste();

Comes with a default filter that

FilteredPaste also allows for custom filters. See below examples for how that works!

Examples

This is a snippet you could copy. It has custom styling that you don't want and way too much whitespace between lines.

This is how pasting works without FilteredPaste

Paste here. This contenteditable uses *no filteredPaste*

And this is how it works *with* FilteredPaste

// Go with default settings
$("#input1").filteredPaste();
Paste here. This contenteditable uses default settings of filteredPaste
// Explicitly use default filter
$("#input2").filteredPaste({
	"filters" : ["default"]
});
Paste here. This contenteditable explicitly specifies the default filter
// Use no filters
$("#input3").filteredPaste({
	"filters" : []
});
Paste here. This contenteditable uses filteredPaste, but with no filters.
// Use default filter but set custom options that allows only style attribute on any tag
$("#input4").filteredPaste({
	"filters" : {
		"default" : { 
			options : { "tags" : { "*" : { "attributes" : ["style"] }}}
		}
	}
}); 
Paste here. This contenteditable uses the default filter but with custom options. The style attribute is allowed on all tags.
// Go with custom filter. It makes all pasted text yellow
$("#input5").filteredPaste({
	"filters" : {
		"someName" : { 
			filter : function(content, options) {
				return "" + content + "";
			},
			options : { }
		}
	}
}); 
Paste here. It uses a custom filter that colors the inserted text yellow.
// Same as above, but define custom filter on $.filteredPaste *and* now also use default filter
$.filteredPaste.filters.customFilter = function(content, options) {
	return "" + content + "";
}
$("#input6").filteredPaste({
	"filters" : ["default", "customFilter"]
});
Paste here. It uses the default filter, and additionally a custom filter that colors the inserted text yellow.