What method is used by Discourse to identify urls in post body


(Sudaraka Jayathilaka) #1

What method is used by Discourse to identify urls in post body and make it clickable?. I tried going through the codebase. But still no luck.


(Michael Howell) #2

It uses markdown-it’s linkify extension.


(Sudaraka Jayathilaka) #3

Thank you @notriddle :grinning:


(Sudaraka Jayathilaka) #4

The above is used for client, are there any similar ways for ruby on rails ?


#5

It actually also uses linkify-it.

I could be wrong, AFAIK the PrettyText module is used to cook raw content into markdown: it essentially utilizes mini_racer to embed the V8 JavaScript Engine into Ruby, and runs exactly the same scripts as the client.


(Vinoth Kannan) #6

I guess you want to extract all the links inside the post for the feature Preventing malicious linking. You can get it simply by doc.css("a[href]") using Nokogiri module.

example


(Sudaraka Jayathilaka) #7

Thank you @xrav3nz and @vinothkannans . Yes @vinothkannans I was trying to find the optimal method for extracting all urls in the post :slight_smile: