gregjacobs / Autolinker.js

Utility to Automatically Link URLs, Email Addresses, Phone Numbers, Twitter handles, and Hashtags in a given block of text/HTML
MIT License
1.48k stars 238 forks source link

Having trouble creating custom matcher #168

Open payamazadi opened 8 years ago

payamazadi commented 8 years ago

Hello, I don't know if this is the right approach, but I'm trying to create a new matcher implementation. Just like HashTag and email already exist, I want to create a custom one.

What I'm tryign to accomplish is look for something that matches regex y, and generates a specific link. Soon, the regex will be a whole set of related regexes, which is why I'd like to use a matcher.

if there is an easier way to do this, let me know.

what I have now, I'm just including the minified Autolinker.js file. Then I have code that tries to do:

Autolinker.matcher.DmReference = Autolinker.Util.extend( Autolinker.matcher.Matcher, { parseMatches: function (text){ ... }

But I'm getting console errors of Autolinker.matcher is undefined. Do I need to set this somewhere? Is this some sort of namespacing issue? Am I approaching this correctly? I'm basically just copying the code from HashTag and Email and repurposing it.

Thanks for any help!

gregjacobs commented 8 years ago

Hey @payamazadi. So Autolinker wasn't really intended to be extended by custom matchers (there's currently no way to add them to the Autolinker constructor). The code in Autolinker.getMatchers() would need to be modified to add your custom one at the moment.

But if Autolinker.matcher is undefined, then the Autolinker library must not be loaded in the browser yet. Do you have a <script> tag for it?

payamazadi commented 8 years ago

Hi! Yes, the script is loaded, it's already doing some URL replacements correctly. Autolinker.match(Es?) is defined and many other items attached to Autolinker. Just not this one. Weird! Good to know about .getMatchers(). I might play with that and submit a PR. Thanks for your quick follow up.

On Jul 6, 2016, at 20:34, Gregory Jacobs notifications@github.com<mailto:notifications@github.com> wrote:

Hey @payamazadihttps://github.com/payamazadi. So Autolinker wasn't really intended to be extended by custom matchers (there's currently no way to add them to the Autolinker constructor). The code in Autolinker.getMatchers() would need to be modified to add your custom one at the moment.

But if Autolinker.matcher is undefined, then the Autolinker library must not be loaded in the browser yet. Do you have a Githubissues.

  • Githubissues is a development platform for aggregating issues.