![]() |
Summary | Linkify Words allows you to automatically hyperlink certain words or patterns in your post with desired destination URL. |
![]() |
Repository Link | https://github.com/discourse/discourse-linkify-words |
![]() |
New to Discourse Themes? | Beginnerâs guide to using Discourse Themes |
Install this theme component
NOTE BEFORE INSTALLING
Discourse has a built in feature called Watched Words
which can replicate most of the features of this theme component. Considering using that before installing this theme component. You can find Watched Words in the Admin menu under Customize â Watched Words
How to configure?
After importing the theme component, configure the theme settings with the format
WORD, https://destination.url.com
or using regular expressions (in JavaScript implementation) with the format
/regex/, https://destination.url.com
One item per line
Using regular expressions
With regular expressions, you can match a certain pattern to a single URL. This is useful for synonyms or for words which can take different forms in the sentence etc.
However, you can also generate the URL automatically based on what was matched. For example, letâs say you have a line of products, each with its own numeric id, and you want to autolink them to their own URLs. Using
/product-([0-9]+)/, https://myshop.com/product/$1
product-42
will be autolinked to https://myshop.com/product/42
Notice the capturing parentheses in the regular expression and the $1
in the URL which is substituted by the match inside the parenthesis. You can also capture multiple parts of the string and use $2
, $3
and so on.
Regular expressions are by default case sensitive (unlike WORDâs which are case insensitive). However, you can change that by using a standard âiâ modfier like this:
/foo/i, https://example.com
In this case, FOO, Foo or foo will all be matched.
Limitations
- Replacement will only appear in the web UI and will not appear in emails.
How this looks in action?
Credits
Big thanks to @Osama for building theme settings and Javascript Bookmarklet to replace text with a link - Stack Overflow for guiding on the implementation.