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

Option to disable automatically generated classes #329

Open
danielbachhuber opened this issue Sep 20, 2020 · 1 comment
Open

Option to disable automatically generated classes #329

danielbachhuber opened this issue Sep 20, 2020 · 1 comment

Comments

@danielbachhuber
Copy link

I'm using Tailwind on my project. If I supply 'hover:underline' as a className, then I'll end up with 'hover:underline hover:underline-url' as my classes.

Similarly, if I supply 'text-blue hover:underline' as className, I'll end up with 'text-blue hover:underline text-blue hover:underline-url' as my classes (note the duplicate 'text-blue' now).

I know adding more options is a faff but it would be nice to disable these automatically generated classes.

@danielbachhuber
Copy link
Author

Fortunately, it looks like replaceFn offers a pretty reasonable workaround. Here's what I did for my Vue mixin:

import Autolinker from 'autolinker';
export default {
    methods: {
        autoLink(text, options = {} ) {
            if ( typeof text !== 'string' ) {
                return text;
            }
            return Autolinker.link(text, {
                replaceFn: ( match ) => {
                    if ( typeof options.className === 'undefined' ) {
                        return true;
                    }
                    const tag = match.buildTag();
                    tag.setClass(options.className);
                    return tag;
                },
                ...options,
            });
        },
    }
}

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

1 participant