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:
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.
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.
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:
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?
Are you sure? I am a little surprised by this. I would think that if your regex is greedy enough you should be able to match it. Note removing the the dot from the boundary characters breaks linkifying words at the end of the sentence.
I did a little test with your regex below on regex101.com and it seems to work with the current boundary characters, see regex101: build, test, and debug regex
Note that if I understand your purpose correctly, you may need to turn some of your capturing groups into non-capturing groups with (?:)
The inability of using | is very annoying, agreed. Note that for ID|id part you can just use the i modifier to make the regex case insensitive. For the numbers if you really need the exact range between 1-10 and 1-100 then it’s tricky, relaxing to 1-19 and 1-199 would make it easier.
Here’s your regex with non-capturing groups that I think should work
This theme component you linked is an adaptation of Sam’s that I did as a workaround for a need you described in another topic.
They are simple theme components which only change how these words are rendered in a post (Sam’s converts specific words to links, mine converts specific words to images) based on the theme component settings, which are only managed by admins.
The feature you describe can’t be done in a theme component, it would need a plugin to store a per-user set of (word, image url) in the database and the word to image conversion should be done server-side, when building the cooked post (as HTML) content. These can’t be done in a theme component, which is only frontend/client-side code (if you hire someone to do this work it’s critical that they understand these details).
This is out of scope of this theme component and would need a way more involved work. The suggestion is to post the details of how you want this feature to behave on #marketplace and you can hire someone here with prior experience with the Discourse internals to help you.