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

Add a hook for custom behavior #28

Closed
howardjing opened this issue Jun 5, 2017 · 3 comments
Closed

Add a hook for custom behavior #28

howardjing opened this issue Jun 5, 2017 · 3 comments

Comments

@howardjing
Copy link
Contributor

Hi,

I'd like to add a hook for custom behavior -- so for example

smartquotes(element, {
  processString: (string) => (
    string.replace(/\-\-/g, '\u2014')
  );
});

to replace double dashes with em dashes. Does that sound fine to you? I'll probably have a PR up today or tomorrow with tests / documentation if yes.

@kellym
Copy link
Owner

kellym commented Jun 5, 2017

You know, a long time ago there was a suggestion of adding behavior for em dashes and ellipses. I was sort of against it at the time, seeing as this is called "smartquotesjs" and I didn't want this library to get bloated with a bunch of other 'smart' conversions.

However, I'm not certain of many other situations besides quotes, em dashes, and ellipses, and possibly a couple others, and I can't find another js library that handles those, so I'd be willing to revisit that instead. Any other scenarios you were thinking of besides the em dash?

@howardjing
Copy link
Contributor Author

My use case is pretty much just smart quotes and em dashes. I read through #4, and the proposal that they had was to convert double dashes to en dashes and triple dashes to em dashes. On the other hand, I want double dashes to be em dashes, and no en dashes at all.

Because the conversion process seems ambiguous, I was thinking it might be better to have a processString hook for the user to do their own logic for their own specific use cases at the cost of added complexity to the user.

@kellym
Copy link
Owner

kellym commented Oct 5, 2017

In lieu of this, I've exposed smartquotes.replacements as an array of regex/replacement pairs. In order to add the use-case you describe, you should be able to add that like so:

const smartquotes = require('smartquotes');
smartquotes.replacements.push([/\-\-/g, '\u2014']);

@kellym kellym closed this as completed Oct 5, 2017
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