Preface: this does not feel like it’s within the scope of Discourse. That’s why I opted for uncategorized.
Background:
If you start a word with #
(hashtag) in Discourse you get a small menu that’s populated with categories. For example I can start typing #un then I can select #uncategorized and a link to that category is automatically added.
The output html is:
<a href="/c/17-uncategorized" class="hashtag">#<span>uncategorized</span></a>
However, if you continue to type and not select anything from the menu, something else happens.
For example if I type #uneven and then continue to type normally, the word is rendered with different html.
in the composer preview:
<span class="hashtag hashtag-tested tag-hashtag-tested">#uneven</span>
in the cooked post / reply:
<span class="hashtag">#uneven</span>
Note that the <span>
wraps around the entire term and is unclickable.
In essence, Discourse does a wonderful job of recognizing hashtags, so I’m wondering if that can be built upon in the form of a plugin.
The concept:
With hashtag recognition out of the way,
could we not trigger a search when a hashtag is clicked that only returns the latest exact matches for the entire contents of the <span>
? There’s no need for anything extra, just a native search operation with parameters (?)
Something along the lines of:
$("span.hashtag").on("click", function() {
// do something
});
Combined with a little bit of CSS like so:
span.hashtag {
cursor: pointer;
color: /* link color */
}
span.hashtag:hover {
color: /* link hover color */
}
to create basic hashtag functionality in Discourse. It seems feasible - again, in the form of a plugin - but there maybe limitations I am unaware of.
What do you think?