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

How to use the validate function with find? Doesn't seem to be working! #450

Closed
rfgamaral opened this issue Aug 30, 2023 · 5 comments · Fixed by #458
Closed

How to use the validate function with find? Doesn't seem to be working! #450

rfgamaral opened this issue Aug 30, 2023 · 5 comments · Fixed by #458
Assignees
Milestone

Comments

@rfgamaral
Copy link

Hi there,

I'm trying to use the validate function with find, but it doesn't seem to be working:

import { find } from 'linkifyjs'

const content = `[GitHub](https://github.com)

[Linkify](https://linkify.js.org "Linkify: a JS plugin by Hypercontext")`

const testA1 = find(content, {
  validate: false
})

const testA2 = find(content, {
  validate: () => false
})

const testA3 = find(content, {
  validate: {
    url: () => false
  }
})

const testB1 = find(content, 'url', {
  validate: false
})

const testB2 = find(content, 'url', {
  validate: () => false
})

const testB3 = find(content, 'url', {
  validate: {
    url: () => false
  }
})

console.log(testA1, testA2, testA3)
console.log(testB1, testB2, testB3)

Output:

image

CodeSandbox:

Am I using it wrong, or is there an issue somewhere?

@nfrasser
Copy link
Collaborator

@rfgamaral thanks for reporting, this is a bug in the find function. Will fix this to the next release. In the mean time, you can try .filter() or something similar on the result of .find() to further filter out matches

@nfrasser nfrasser added this to the 4.1+ milestone Aug 30, 2023
@nfrasser nfrasser self-assigned this Aug 30, 2023
@rfgamaral
Copy link
Author

@nfrasser I don't think that will work for what I'm trying to achieve, which is to prevent linkify from capturing links enclosed in Markdown syntax. But if you have any workaround suggestions, please, do let me know.

For the record, I want to apply this filtering here, most likely based on a boolean option so that it's user configurable.

@rfgamaral
Copy link
Author

@nfrasser Do you have any other workaround that would work for my use case?

@nfrasser
Copy link
Collaborator

nfrasser commented Nov 9, 2023

@rfgamaral apologies for the delay, this is now working with the latest Linkify v4.1.2

@rfgamaral
Copy link
Author

Thank you, @nfrasser.

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 a pull request may close this issue.

2 participants