Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowedStyles option #158

Closed
codemzy opened this issue Aug 29, 2017 · 2 comments
Closed

allowedStyles option #158

codemzy opened this issue Aug 29, 2017 · 2 comments
Labels

Comments

@codemzy
Copy link

codemzy commented Aug 29, 2017

Thanks for the awesome work 👍

I understand the reasons for not allowing inline styles but for some wysiwyg editors they are hard to avoid completely.

I was thinking rather than an all or nothing approach, it could be cool to have something similar to the allowedClasses option, where some (safe?) inline styles can be allowed.

Like..

  allowedStyles: {
    'table': [ 'width', 'border-style' ]
  }

I couldn't find an option for this other than allowing all styles, for now I have come up with a work around... which could probably be improved on...

transformTags: {
    '*': function(tagName, attribs) {
        if (attribs.style) {
            let allowedStyles = ["width"];
            let cleanedStyles = [];
            allowedStyles.forEach(function(element) {
                let regex = new RegExp(element + ":[\\s|\\S]*?;");
                let matches = attribs.style.match(regex);
                if (matches) {
                    cleanedStyles.push(matches[0]);
                }
            });
            attribs.style = cleanedStyles.join(' ');
        }
        return {
            tagName: tagName,
            attribs: attribs
        };
    }
}
@boutell
Copy link
Member

boutell commented Aug 30, 2017 via email

@stale
Copy link

stale bot commented Jul 7, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants