kellym / smartquotes.js

Smart quotes are smart typography, and now it’s just a ’script away.
https://smartquotes.js.org
MIT License
150 stars 30 forks source link

Add API support for ignored html classNames #53

Closed toddka closed 2 years ago

toddka commented 3 years ago

Hey there! I wanted to offer an addition I recently made to this package that gives the ability to ignore HTML classes. I found that some javascript packages require a lot of control over the DOM, and smartquotes was interfering with their performance. For example, some text editors, like react-quill and slate, do not correctly select text while the smartquotes listener is running.

My approach was to mark any DOM nodes that are descendants of an Ignored class and skip them in the element handler. There may be a better way to do this, but I hacked this together and it seems to work well enough. I haven't noticed any performance issues with the additional node parsing. However, it's conceivable that if a user ignores large subtrees, then the recursive node marking may slow things down.

The API interface isn't very readable, but it is backwards compatible. I'm open to changing the format to make it easier to pass in additional options, etc. but didn't want to submit a breaking change without more context.