# Auto-Linkify Words

**URL:** https://meta.discourse.org/t/auto-linkify-words/82193
**Category:** Theme component
**Tags:** official, linkify-words
**Created:** [5 maart 2018 om 07:16 UTC](https://meta.discourse.org/t/auto-linkify-words/82193 "2018-03-05T07:16:06Z")
**Posts on this page:** 20
**Page:** 5

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [11 oktober 2018 om 21:36 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/89 "2018-10-11T21:36:58Z")

</div>

I just made it wiki, so go ahead 😇

---

<div class="post-metadata">

### Author: ![anon36484860](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@anon36484860](https://meta.discourse.org/u/anon36484860)
#### Post date: [12 oktober 2018 om 12:36 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/90 "2018-10-12T12:36:16Z")

</div>

Is there any way to linkify words in quotes? It seems whenever a linkified word is in a quote, the linkify CSS class is stripped.

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [12 oktober 2018 om 13:06 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/91 "2018-10-12T13:06:28Z")

</div>

Yes, this was an intentional decision, we thought that quote indicate that no magic should be applied. You can easily modify the code to fix that though: Just include the quotes in variables `leftWordBoundary` and `rightWordBoundary` like this

```
  let leftWordBoundary = "(\\s|[\"\'\\([{]|^)";
  let rightWordBoundary = "([\"\':.;,!?…\\]})]|\\s|$)";

```

Let me know if this works or if you need more guidance.

---

<div class="post-metadata">

### Author: ![anon36484860](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@anon36484860](https://meta.discourse.org/u/anon36484860)
#### Post date: [12 oktober 2018 om 13:31 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/92 "2018-10-12T13:31:56Z")

</div>

it seems the issue is rather that when quoting a text passage with a linkified word, it picks up the link as a regular one and adds it in markdown which obviously does not include any CSS class

so to display the link in the quote properly, the markdown link has be either stripped when pressing “quote button”. the workaround provided would help then.

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [12 oktober 2018 om 13:58 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/93 "2018-10-12T13:58:55Z")

</div>

> [@anon36484860](#):
>
> it seems the issue is rather that when quoting a text passage with a linkified word,

Oh, I misunderstood. Do you mean quoting like this ⏫? Or something else? What do you mean by “quote” button? Could you be more specific what do you mean by quoting and step by step instructions how to reproduce?

I did a test on my site and it seems to me that it works just fine inside the quoted text. (and btw: this should be largely independent of any CSS).

As long as the text is not inside the `<a>`, `<pre>`, `<iframe>` or `<code>` tags, it should work.

If this theme would be installed here in meta we could test it, but it is probably not.

EDIT: Indeed, when you quote the text with autolink, it is converted to a proper full markdown link. But I would call that a win. What are the downsides of this behaviour?

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [12 oktober 2018 om 14:48 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/94 "2018-10-12T14:48:03Z")

</div>

Well played, Sam, well played. 🤨

I took a stab at it, please have a look and clean up if needed.

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [14 oktober 2018 om 23:15 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/95 "2018-10-14T23:15:54Z")

</div>

One more small PR 👼

I added a new settings for user-selectable excluded HTML tags. For example, in our case we do not want anything inside the header tags `<hX>` to be linkified.

[https://github.com/discourse/discourse-linkify-words/pull/5](https://github.com/discourse/discourse-linkify-words/pull/5)

The default is the same as before i.e. `<pre>` and `<code>`.

Exclusion of `<a>` and `<iframe>` is hardcoded and cannot be changed by the settings.

---

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [1 november 2018 om 11:46 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/96 "2018-11-01T11:46:36Z")

</div>

Could this be used to add affiliate codes to URLs too? For example:

`https://webshop.com/product/name`

Gets linked to

`https://webshop.com/product/name?code=123`

I’ve been trying with regexp, but I suspect the autolinker might be interfering here?

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [1 november 2018 om 13:10 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/97 "2018-11-01T13:10:19Z")

</div>

Hmm, I am not sure I am understanding correctly. What keyword do you want to get autolinked? Which regex did you use?

EDIT: So you’re trying to turn one URL into another? Yeah, in that case autolinker in Discourse would interfere. Not sure what’s the best solution here. I guess it would not be super hard to customize the code to handle this specific case. At this moment, this theme skips everything inside the `<a>` tag.

---

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [1 november 2018 om 13:40 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/98 "2018-11-01T13:40:32Z")

</div>

> [@danekhollas](#):
>
> So you’re trying to turn one URL into another?

Yeah, that’s right. Now that I know, I’ll take a look at the code and see if I can use a modified version. Thanks!

---

<div class="post-metadata">

### Author: ![jerdog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jerdog/32/122843_2.png) [@jerdog](https://meta.discourse.org/u/jerdog)
#### Post date: [1 november 2018 om 18:18 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/99 "2018-11-01T18:18:27Z")

</div>

> [@danekhollas](#):
>
> Hmm, I think it should be fairly easy todo, although there are some details to be discussed. If there is still interest in this feature, I might give it a try, although probably not right away.

Yeah I think this definitely would be helpful, especially for when a poster uses the same word multiple times because it’s part of what they’re doing, it creates a page all littered with links of the same word

---

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [26 november 2018 om 08:11 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/100 "2018-11-26T08:11:02Z")

</div>

Here is a regular expression that the theme component won’t let me add:

`/(козий +рынок|козьего +рынка|козьем +рынке|козьему +рынку)/i, https://forum.kozovod.com/c/kozij-rynok`

As soon as I click on the green “OK” button:

 ![image](https://global.discourse-cdn.com/meta/original/3X/0/1/0125d652f773bd5b542c439ac37136aa1b7ffc38.png)

… it does this:

 ![image](https://global.discourse-cdn.com/meta/original/3X/a/c/ac41a680bdccdf7a345b5a25a964f3f998cb966d.png)

Also, **case-insensitivity flag** is not preserved, e.g. `/козий рынок/i` won’t recognise `Козий рынок`

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [26 november 2018 om 09:21 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/102 "2018-11-26T09:21:04Z")

</div>

Hi @meglio,

thanks for the report! I think the first problem is with the `|` character because it is used internally in this list input component as a delimiter. I am not quite sure how to approach this. Any ideas, @j.jaffeux?

A workaround for now would be to split the regex into several different regexes without `|`

As for the case sensitivity, do you see a problem only in this specific example or does it not work for you at all? I wonder whether this flag works for non-latin alphabets?

---

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [26 november 2018 om 10:52 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/103 "2018-11-26T10:52:51Z")

</div>

> [@danekhollas](#):
>
> I think the first problem is with the `|` character because it is used internally in this list input component as a delimiter.

Yes looks so. I’d suggest allowing either a backslashed “|” or a double “||” as a valid "| symbol in regex. Maintaining 4 regexes instead of one is a workaround though.

> [@danekhollas](#):
>
> As for the case sensitivity, do you see a problem only in this specific example or does it not work for you at all? I wonder whether this flag works for non-latin alphabets?

I only tried with non-latin alphabets as that’s what is used on our forum.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [26 november 2018 om 20:38 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/104 "2018-11-26T20:38:21Z")

</div>

@maja can you suggest a way for @meglio to enter his regular expression?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [26 november 2018 om 21:07 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/105 "2018-11-26T21:07:53Z")

</div>

I think fundamentally we need a way of escaping pipes in lists, double pipe is sort of workable but requires a custom list parser, I suspect we just need to fix this at the source and allow site settings and theme settings to natively support this. I guess a workaround for now in this theme setting is to use a very rare char as the item separator like a rare Unicode seldom used and split on that

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [26 november 2018 om 21:43 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/106 "2018-11-26T21:43:22Z")

</div>

Hmm, but how do you set the splitting character? Can it be specified in the settings.yaml?

> <https://github.com/discourse/discourse-linkify-words/blob/aa8156eaab881740d4245a47db951935462dc463/settings.yaml#L1>

Because in the JS code itself, the `|` char seems to be “hard-coded”

> <https://github.com/discourse/discourse-linkify-words/blob/aa8156eaab881740d4245a47db951935462dc463/common/head_tag.html#L5>

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [26 november 2018 om 21:44 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/107 "2018-11-26T21:44:37Z")

</div>

Yeah we need a new change to select kit to support this cc @j.jaffeux

---

<div class="post-metadata">

### Author: ![Ben\_Tristem](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ben_tristem/32/121684_2.png) [@Ben\_Tristem](https://meta.discourse.org/u/Ben_Tristem)
#### Post date: [17 januari 2019 om 10:02 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/108 "2019-01-17T10:02:10Z")

</div>

Can I suggest there is a checkbox to make this case sensitive? Or the the trigger is based on regex?

For example I’d like it to trigger for `Discourse` but not `discourse`.

Would this be a suggestion you guys can take on, or would you be open to a Pull Request?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [17 januari 2019 om 10:22 UTC](https://meta.discourse.org/t/auto-linkify-words/82193/109 "2019-01-17T10:22:21Z")

</div>

> [@Ben\_Tristem](#):
>
> would you be open to a Pull Request?

Sure totally open to having a PR here.

[Vorige pagina](https://meta.discourse.org/t/auto-linkify-words/82193.md?page=4)

[Volgende pagina](https://meta.discourse.org/t/auto-linkify-words/82193.md?page=6)
