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

**URL:** https://meta.discourse.org/t/what-method-is-used-by-discourse-to-identify-urls-in-post-body/75876
**Category:** Development
**Created:** [12 december 2017 om 15:16 UTC](https://meta.discourse.org/t/what-method-is-used-by-discourse-to-identify-urls-in-post-body/75876 "2017-12-12T15:16:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Sudaraka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sudaraka/32/68401_2.png) [@Sudaraka](https://meta.discourse.org/u/Sudaraka)
#### Post date: [12 december 2017 om 15:16 UTC](https://meta.discourse.org/t/what-method-is-used-by-discourse-to-identify-urls-in-post-body/75876/1 "2017-12-12T15:16:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![notriddle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/notriddle/32/133055_2.png) [@notriddle](https://meta.discourse.org/u/notriddle)
#### Post date: [12 december 2017 om 15:35 UTC](https://meta.discourse.org/t/what-method-is-used-by-discourse-to-identify-urls-in-post-body/75876/2 "2017-12-12T15:35:40Z")

</div>

It uses [markdown-it](https://github.com/markdown-it/markdown-it)’s linkify extension.

[https://github.com/markdown-it/linkify-it](https://github.com/markdown-it/linkify-it)

---

<div class="post-metadata">

### Author: ![Sudaraka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sudaraka/32/68401_2.png) [@Sudaraka](https://meta.discourse.org/u/Sudaraka)
#### Post date: [12 december 2017 om 15:42 UTC](https://meta.discourse.org/t/what-method-is-used-by-discourse-to-identify-urls-in-post-body/75876/3 "2017-12-12T15:42:22Z")

</div>

Thank you @notriddle 😀

---

<div class="post-metadata">

### Author: ![Sudaraka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sudaraka/32/68401_2.png) [@Sudaraka](https://meta.discourse.org/u/Sudaraka)
#### Post date: [12 december 2017 om 16:22 UTC](https://meta.discourse.org/t/what-method-is-used-by-discourse-to-identify-urls-in-post-body/75876/4 "2017-12-12T16:22:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![xrav3nz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xrav3nz/32/76894_2.png) [@xrav3nz](https://meta.discourse.org/u/xrav3nz)
#### Post date: [12 december 2017 om 17:07 UTC](https://meta.discourse.org/t/what-method-is-used-by-discourse-to-identify-urls-in-post-body/75876/5 "2017-12-12T17:07:59Z")

</div>

It actually also uses `linkify-it`.

I could be wrong, AFAIK the [`PrettyText` module](https://github.com/discourse/discourse/blob/master/lib/pretty_text.rb) 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.

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [12 december 2017 om 17:16 UTC](https://meta.discourse.org/t/what-method-is-used-by-discourse-to-identify-urls-in-post-body/75876/6 "2017-12-12T17:16:04Z")

</div>

I guess you want to extract all the links inside the post for the feature [Preventing malicious linking - #27 by Sudaraka](https://meta.discourse.org/t/preventing-malicious-linking/37982/27). You can get it simply by `doc.css("a[href]")` using Nokogiri module.

example

> <https://github.com/discourse/discourse/blob/b3b55e18d1c804982eef5a1b4264234e5a5a335f/lib/cooked_post_processor.rb#L154-L155>

---

<div class="post-metadata">

### Author: ![Sudaraka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sudaraka/32/68401_2.png) [@Sudaraka](https://meta.discourse.org/u/Sudaraka)
#### Post date: [12 december 2017 om 17:22 UTC](https://meta.discourse.org/t/what-method-is-used-by-discourse-to-identify-urls-in-post-body/75876/7 "2017-12-12T17:22:27Z")

</div>

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