editor.js/types/configs/sanitizer-config.d.ts
Tomoyuki Hata a67e699991
Fix SanitizerConfig type definition (#1456)
* Fix SanitizerConfig type definition

* Update docs/CHANGELOG.md

Co-authored-by: Peter Savchenko <specc.dev@gmail.com>

* Fix CHANGELOG

* Add JSDoc to TagConfig

* yarn lint:fix

Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com>
2021-03-02 16:34:23 +03:00

42 lines
1.1 KiB
TypeScript

/**
* Sanitizer config of each HTML element
* @see {@link https://github.com/guardian/html-janitor#options}
*/
type TagConfig = boolean | { [attr: string]: boolean | string };
export interface SanitizerConfig {
/**
* Tag name and params not to be stripped off
* @see {@link https://github.com/guardian/html-janitor}
*
* @example Save P tags
* p: true
*
* @example Save A tags and do not strip HREF attribute
* a: {
* href: true
* }
*
* @example Save A tags with TARGET="_blank" attribute
* a: function (aTag) {
* return aTag.target === '_black';
* }
*
* @example Save U tags that are not empty
* u: function(el){
* return el.textContent !== '';
* }
*
* @example For blockquote with class 'indent' save CLASS and STYLE attributes
* Otherwise strip all attributes
* blockquote: function(el) {
* if (el.classList.contains('indent')) {
* return { 'class': true, 'style': true };
* } else {
* return {};
* }
* }
*/
[key: string]: TagConfig | ((el: Element) => TagConfig);
}