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

Question: How can I remove inline styles on paste? #49

Open
jessegavin opened this issue Jan 5, 2017 · 5 comments
Open

Question: How can I remove inline styles on paste? #49

jessegavin opened this issue Jan 5, 2017 · 5 comments

Comments

@jessegavin
Copy link

jessegavin commented Jan 5, 2017

I want to be able to use woofmark as a wysiwyg editor for markdown only.

  1. I never want my users to be able to switch to html mode (I know how to do this).
  2. I would like to automatically strip out any inline styles when a user pastes rich text into the editor while in wysiwyg mode. ( don't know how to do this).

How can I accomplish the second item?

I created a code pen to illustrate the non-desirable behavior. http://codepen.io/jessegavin/pen/mRyOJb?editors=0010

Thanks so much. This is one of the coolest implementations I have seen for a wysiwyg editor.

@jywarren
Copy link
Collaborator

jywarren commented Jan 5, 2017 via email

@jessegavin
Copy link
Author

jessegavin commented Jan 5, 2017

@jywarren that is correct. I can get the desired result if I paste inline-styled content into the wysiwyg mode, then switch to markdown, then switch back.

I want some way to skip the step of having to manually switch to markdown mode and back.

@jywarren
Copy link
Collaborator

jywarren commented Jan 6, 2017 via email

@jessegavin
Copy link
Author

jessegavin commented Jan 7, 2017

Ok, I have come up with a "solution" which works for my particular needs, but it doesn't feel clean at all.

And, because it uses setTimeout() there's a visual "blip" when the pasted content is displayed with inline styles, then immediately they are removed.

var editor = woofmark(...);

editor.editable.addEventListener('paste', function(e) {
  setTimeout(function() {
    var els = editor.editable.querySelectorAll('*'), i;
    for (i = 0; i < els.length; i++) {
      els[i].removeAttribute('style');
    }
  },0);
}, false);

@jywarren
Copy link
Collaborator

jywarren commented Jan 11, 2017 via email

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

No branches or pull requests

2 participants