Auto-Linkify Words

@danekhollas

Unfortunately I still have the issue. I tried changing the order of the regexes in the theme settings, yet the “shorter” entry is still triggered first.

Hello @jrgong! Were you able to do bulk uploads using a CSV file? Trying to figure it out but I’m not quite sure where to click. I am not a developer btw :smiley:

I am using this :slight_smile:

https://meta.discourse.org/t/discourse-linkify-google-sheets/163985/4

So do we. I note that:

discourse,https://discourse.org
discourse meta,https://meta.discourse.org
meta discourse,https://meta.discourse.org

Gives us:

discourse
discourse meta
meta discourse

The order that these are in the Theme Settings (and presumably the database beneath) doesn’t seem to make a difference. Rather, if you extend an existing linkified word, it will pick up the difference. If you add a word in front, it doesn’t.

1 Like

Hmm, that’s a bit strange. You’re right, the order in the settings shouldn’t matter, because we sort the words by length:

https://github.com/discourse/discourse-linkify-words/blob/a516d488dc23f401a7062808b98a231af9a16ef1/javascripts/discourse-linkify/lib/utilities.js.es6#L99

Not sure how much time should be invested in this since AFAIK this feature is being ported to Discourse core.

4 Likes

Hi,

Just noticed that the linkified words don’t have that click counter as other links have (which would be a nice feature to have, in my opinion). Is it on purpose or just a bug?

2 Likes

can this be restricted to specific categories/tags so that a post would have to be in the category or tagged to generate links?

1 Like

Is it possible to specify a title for the link? So “ghost” becomes “ghost (see warning!)”?

Possibly using markdown link syntax:

ghost,[ghost (see warning!)](https://warning.example.com)

Or specifying the title as a third parameter:

ghost,https://warning.example.com,ghost (see warning!)

@Paracelsus the click counter is not supported in this theme, sorry.

Not really a bug, the theme is only a JavaScript code running in your browser. It doesn’t talk to the server so there’s no way to store the number of clicks.

2 Likes

Now in discourse under replace words:
/admin/customize/watched_words/action/replace

If I just enter the word and then just put the URL without any markdown, it works! So that is how to get it to work without the autolink theme component.

(Whereas in the theme component you put the word/phrase then a comma then the link to use, in watched word replace you enter the word in one field and JUST the link in another… do not try to enter markdown in the replacement string like I originally tried.)

4 Likes

Hey, this’s a great component! Thanks for having done this.

But a little problem there, it seems that the linkification requires a space after the specific word, so the component is not working well in Chinese and Japanese (maybe also Korean? I don’t know this language) Discourse instances.

I’m a native speaker of Chinese, and I speak Japanese too. In Chinese, it happens that people use some fixed borrowed words in letters, like Apple, Office, BB (Blackboard), DNA, etc., whose translation is quite rarely used in the familiar language. And we usually don’t add a space before/after this kind of word when it’s surrounded by Chinese, in informal writing.

This is an example:

你会用Office吗?
Do you know how to use Office suite?

It’s similar in Japanese.

革新に満ちたAppleの世界へようこそ。(copied from Apple Japan official site)
Welcome to the world of Apple, which is full of revolutions.

I’m aware that it might be a lot of work to adapt this component for these two languages, cause this might lead to unintended linkifications in languages using the alphabet. So, just pointing out the existence of a small imperfection. Appreciate again this great idea of making this component. :smiley_cat:

2 Likes

This works great. Is it possible to run it retroactively, or do you need to search all the links manually and change them?

You should be able to rebake those posts. You can click the wrench and rebuild html. When you s they works then you can search for how to rebake matching posts rake task.

Actually, this theme linkifies posts dynamically when they are loaded in the browser so no need to do anything. :slight_smile:

3 Likes

Oh. Very cool. I hadn’t realized, but that makes sense.

3 Likes

Our FOSS genealogy software glossary was too extensive for a Posting or Linkifying.

If we had just Linkified each Glossary term, then every posting would drown in a sea of blue links. Users would be likely to stop clicking links. And we wanted an audit trail for the Glossary.

So I linkified “Gramps Glossary” to that article in our MediaWiki-powered wiki. And now use an annotation like “(see [glossary term] in the Gramps Glossary)

(We have a 2nd Genealogy Glossary for terminology that is generic to the Genealogy subject matter rather than specific to our software.)

1 Like

Has something been done to allow pipes?

I’m currently using this as a workaround:
image


Also, is there a way to exclude a world from being linkified when inside a grand-grand-[…]children of an excluded class?
I’m building a forum with a Documentation category, and I don’t want linkified words in it because it would be redundant: words in other categories will be linkified and will link to topics in this documentation category.
Plus, linkified words open in a new window.

So, this didn’t work:

Here’s an example of the issue I’m facing. This is the part of a text inside a documentation topic.

If I click 22° halo, it will open a page that links to… The same page, at the same place.
I can exclude words in titles, especially because it contains a table of content, but the following paragraphs don’t have any specific class. They are regular paragraphs.


Maybe the excluded class setting could accept CSS selectors?
For example, d-toc-cooked > *


edit: Also I fail to understand why this doesn’t work since my word is a direct child of an excluded class:

image

The “22° Halo” is still linkified:

<h3 id="toc-h3-22-halo" data-d-toc="toc-h3-22-halo" class="d-toc-post-heading">
    <a name="h-22-halo-7" class="anchor" href="#h-22-halo-7"></a>
    <a href="https://discourse.canapin.com/t/ice-halos-information-and-list/28#h-22-halo-7" rel="nofollow" target="_blank" class="linkify-word no-track-link">22° Halo</a>
</h3>

Is that because the table of content HTML code could be generated after the “linkification”?

1 Like

Yeah, that’s probably the issue here, both of these are JavaScript components so you have a race condition and the result will depend on which one runs first.

4 Likes

I added a class in the HTML allowlist so I circumvented the issue.

However, being able to have a button excluded attributes could allow more flexibility to prevent linkify words, using the build-in data-(anything) HTML attribute since it’s allowed by default in Discourse.

Example:
<span data-nolinkify> text </span> text

Would a push request be accepted if I manage to add this to the theme component?

1 Like

This unfortunately prevents linkifying words that explicitly include any of these (especially ., which is handy in linking abbreviations like ID.1 or id2.5).

This is perhaps best fixed in core, but for the meantime here’s a PR that fixes the above issues:

https://github.com/discourse/discourse-linkify-words/pull/21

Sample regex rule (will match id1.1 to id10.100 (including variations id m.n, IDm.n and ID m.n)

/(ID¦id)\s?(([1-9]¦10)\.([1-9]¦[1-9][0-9]¦100))/, https://example.com/id$2