Add <abbr> tags to words in posts


(Freso) #1

About

This theme component is ported from Linkify words in post to provide functionality similar to the Abbreviations and acronyms plugin – namely to wrap various abbreviations used in a given forum/site/Discourse installation in <abbr> tags.

Location

How to install

Credits

Thanks to @sam for writing the “Linkify words in post” plugin.


Discourse Post Abbreviations
Abbreviations and acronyms plugin
(Southpaw) #2

Hi @Freso,

Thanks for creating Auto-Abbrify! It’s so simple for users to be able to mouse over an abbreviation rather than having to click away from what they are reading to look it up online or in a lexicon!

One question for you, please:
I was hoping to also use it to provide explanations for some Android Hidden Codes, for example: *#*#8647#*#*
To make such a code display correctly in Discourse, we have to escape the sequence using the preformatted text button image. I’m having trouble getting Auto-Abbrify to work with this code. I’ve tried entering the code in the Auto-Abbrify theme both with and without the backticks. Do you have any suggestion to make Auto-abbrify work with this kind of sequence?


(Southpaw) #4

I have a second question for you, @Freso (or anyone else using Auto-Abbrify.)

We’re seeing some instances where abbreviations on the Abbrify list are repeating characters. Examples:

image

and

image

Any idea what I’ve done to cause that?


(Joe) #5

Hi @Southpaw

You need to make a small adjustment to the theme to fix both problems.

  • Abbreviated words / phrases not picked up in <code> tags
  • Repeating characters in oneboxes

Go to the edit theme > common > /head section and change line #19

You’d only need to change the word

code

to

aside

Like so:

This will have two effects:

  • ask the theme not to ignore <code> tags when looking for abbreviated words. Which allows you to add the sequence *#*#8647#*#* in the abbreviated words list (no backticks) like any other word and it should work:

Untitled

  • ask the theme not to look for abbreviated words in <aside> tags to prevent duplicated letters in oneboxes

Here’s a before:

and after:

The catch here is that this a local change and would need to be reapplied every time you update the theme, but considering it’s only one word, I don’t think this is a big problem.

Are there any other places where you’re seeing duplicate letters in abbreviations?


(Southpaw) #6

Hi @Johani,

Thanks for such a detailed response! I’ve implemented it and it works for both the onebox and <code> situations.

Yes, the second example I gave is linked to a user-typed reply, not a onebox. Ordering the free SIM cards? - Questions & Answers - Community Forums


(Joe) #7

Thank you for the link @Southpaw

I can definitely reproduce the issue. It’s caused by white-space characters not being removed.

I’ve made a small change in your theme to address the issue until the theme is updated and submitted a PR for @Freso to look at

Now that this is fixed, you can remove line #19 entirely from your theme if you want oneboxes to have abbreviations as well.


(Southpaw) #8

Thanks @Johani! I had linked the sample images… sorry, I should have been more explicit.


#9

Has anyone found a workaround to shop the tooltip without any delay? Could not find anything in CSS specifications.


(Christoph) #10

I wonder if it would be feasible to make it so that certain abbreviations can be limited to certain categories? For example, by specifying CA,California,US politics and CA,Canada,International politics CA would be abbrified differently in the Categories US politics and International Politics.

Oh, and it would also be great if the detection of acronyms could be context sensitive (to avoid false positives when an abbreviation also exists as a word in ordinary language).


(Christoph) #11

Here is another idea for refinement:

Let’s say on my forum, AA commonly stands for Alcoholic Anonymous and so we have a the abbrify theme component set up to explain AA as Alcoholics Anonymous. Now let’s say John writes a post mentioning the Automobile Association as AA. If he notices that the explanation for the abbreviation is wrong, he might want to stop discourse from abbrifying AA in his post. Or perhaps he doesn’t notice the problem but a staff member does but doesn’t know what AA stands for, only that it’s obviously not Alcoholics Anonymous.

Is there perhaps an easy solution to stop a word from being abbrified on a per post basis (except for using a different word or abbreviation, of course)? Perhaps such an escape mechanism could also be useful for the linkify theme component?


(Daniel Hollas) #12

Well, one solution would be to manually insert the abbr tag in those instances. :slight_smile:
Or, if there exist some non-intrusive HTML tag that you could wrap around that particular abbreviation and than add that tag to the skipTags object in the code.


(Daniel Hollas) #13

I wonder, wouldn’t it make sense to make a new theme settings for listing skiped HTML tags? (Same goes for auto-linkify).

EDIT: Hmm, that was actually very easy to do, have a local working version, happy to submit PR…