sanitize method for Block Tool seems to be typed wrong
Case 1:
In Block Tool types, sanitize should return SanitizerConfig (which is object with tag names as keys). Examples in SanitizerConfig are also written for fields with tag names as keys.
Case 2:
In documentation, it returns object with 'url' and 'caption' keys. Same behavior in other official plugins, such as paragraph, quote etc. And unfortunately, in that situation I can't use function as value for tag name, because tag name here becomes typed as 'attr'.
Editor.js version: 2.30.8
I can't understand which of that cases is right or wrong. Is there any correct way to use function for sanitizing tag?
I'm not sure I've got the problem. SanitizerRule can be a function in our types:
export type SanitizerRule = TagConfig | ((el: Element) => TagConfig)
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]: SanitizerRule;
}
@neSpecc
I'm trying to do that
and receiving TypeScript error TS2322: Type '(el: any) => boolean' is not assignable to type 'string | boolean'
Yes, probably we have some problems in types. Could you try to fix it?
I think I could try.
But also, I tried to find in that repo, how sanitize field is actually used, and I didn't find anything.
So it seems to me that this field is not actual at all (please correct me if I'm wrong).
It is used on paste and on save.
Can you show any example?