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

Adds wrapAttrs option #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Adds wrapAttrs option #59

wants to merge 1 commit into from

Conversation

plakak
Copy link

@plakak plakak commented Apr 28, 2017

I could really use this functionality and I think it's a good idea to include it as a standard option for everyone to use.

P.S. Amazing work with this library. Lifesaver for me. Thanks!

@hftf
Copy link

hftf commented Oct 27, 2017

I suppose I would use this wrapAttrs option if I could pass in an object of functions:

findAndReplaceDOMText(..., {
    find: /.../,
    wrap: 'mark',
    wrapAttrs: {
        'class': 'match',
        'data-index': function(portion, match) { return match.index; }
    },
    ...
}

But then again, I'm using a replace function anyway:

function replace(portion, match) {
    var html = '<mark class="match" data-index="' + match.index + '">' + 
                   portion.text +
               '</mark>';
    return htmlToElement(html);
}
function htmlToElement(html) {
    var template = document.createElement('template');
    template.innerHTML = html;
    return template.content.firstChild;
}

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

Successfully merging this pull request may close these issues.

2 participants