Auto-Linkify Words

I have Linkify working almost exactly the way that I want:

/TBI\s*\W?(\d*)/,https://tbi.example.com/tbi/$1/

This covers “TBI numbers” entered by the users with many different forms:

  • TBI 17
  • TBI-17
  • TBI17
  • TBI -17
  • TBI*17
  • etc.

I like this flexibility.

Unfortunately, it does not handle the canonical way of entering these numbers:

  • TBI #17

It seems that nothing I can do will properly match the # (hashtag, hash, number sign, octothorp, hash mark, pound sign, tictactoe symbol). I’ve tried

/TBI\s*#?(\d*)/,https://tbi.example.com/tbi/$1/
/TBI\s*\#?(\d*)/,https://tbi.example.com/tbi/$1/

of course, and they don’t work; but not even a full wildcard works:

/TBI\s*.?(\d*)/,https://tbi.example.com/tbi/$1/

It looks to me like the category pop-up functionality may be taking this over and not allowing Linkify to do its matching work — even when the user doesn’t choose one of the offered categories.

Is this expected behavior or a bug? Does anyone know of a way to work around it?

Yeah, if you inspect the HTML source code, Discourse seems to put anything prefaced with hastag in a separate span element which breaks the linkify theme flow. I don’t think there is an easy fix for this, sorry. :frowning: You’d need to fork the theme and customize it specifically for this case I’m afraid, unless somebody has a better idea.

This plug works well, thanks. However, in combination with abrify it doesn’t work.
Is it possible for the link to work as well with the class it adds with this plugin:
https://github.com/metabrainz/discourse-abbrify-words.

I think the issue is that the abbrify plugin skips link tags by defualt. You can try to fix it by modifying the code, deleting line 16 in head_tag.html

'a': 1,

https://github.com/metabrainz/discourse-abbrify-words/blob/a6651cf1c0a6d5233412f61b486cf256e36ffa1e/common/head_tag.html#L16

Let me know if it worked or if you need more guidance. :slightly_smiling_face:

2 Likes

It seems to be working thanks a lot.

By the way, does it make any difference if it edits only in css/html template instead of directly from github ?

Yes, you need to be careful when you update the theme component from Github, it will overwrite your local changes in in css/html.

3 Likes

Thanks, I wonder if it is possible to do the same, but to add a different class instead of the abriffy attribute, e.g. dfn data-info or span aria-label or other of this type

e.g. to play with the content: attr()

Yep, definitely. You can try playing with the function createAbbr (or with the corresponding function in linkify theme)

https://github.com/metabrainz/discourse-abbrify-words/blob/a6651cf1c0a6d5233412f61b486cf256e36ffa1e/common/head_tag.html#L32

1 Like

really good. I have got to play on it a little bit.
I guess there might be a lot of possibilities here. Do you have any idea how to use json and api here in some way?

For example, to be able to display abriffy words and others data on wordpress through api ?

I am not sure what you mean. Could you be more concrete on what you’re trying to achieve? Theme components run on in Discourse, there’s no API to use them elsewhere. But you should, for the most part be able to use the JS code by simply copying it elsewhere and modify discourse-specific parts.

Is there any way to exclude content in oneboxes from being linkified?

1 Like

You can try adding the <aside> tag in the skipped tags settings. Although I am not sure that all oneboxes are placed inside the <aside>. Maybe we would need a filter based on class name,

@sam any thoughts on this? :arrow_double_up: This would seem like a reasonable default behaviour (not autolink in oneboxes).

4 Likes

Class based filter setting sounds perfect, by default we should exclude one box

7 Likes

Okay, I’ll try to submit a PR next week.

2 Likes

Hi I have successfully installed this theme component for my default Light theme today. However it doesn’t work for me.

I have tried regex and the default linkify words (discourse and meta). Neither has luck.

I have v2.3.0.beta2 +256 installed. Is there any tips to debug this please? Thanks in advance :slight_smile:

1 Like

We did a code refactor recently and it is possible that you have to update your Discourse (which is convenient anyway since 2.4 has just been released :slightly_smiling_face:)

6 Likes

Linkify in oneboxes should now be disabled by default. @jrgong Could you please update your theme and try it out?

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

1 Like

Seems like this hasn’t been resolved? I thought I could create a backup by exporting the component from the admin interface, but the export doesn’t include the custom settings.

An idea: What if the setting with all its rows turns into an editable text area on double-click? Similar to the Edit CSS/HTML editors? That would make it easy to backup/export as well as import a list of items with one item per line.

Before:
Screen Shot 2020-04-13 at 22.48.03

On double-click:
Screen Shot 2020-04-13 at 22.51.41

On a different note: you might see some weird Regex there, but you can’t use | in these setting fields. Maybe that could be solved with the above proposal as well.

3 Likes

Hello again man! how do you think turn words/link using (linkify/abrify plugin) into a picture(s) ?

Probably not possible with the current plugin, but it shouldn’t be hard to modify the plugin to produce <img> tags instead of <a>.

1 Like