#javascript
JS - 1. Getting Started ...
#javascript:getting-started-v2
JS - 2. Code your own adventure
#javascript:javascript-beginner-en-x9DnD
JS - 3. Intro to Functions
#javascript:javascript-beginner-en-6LzGd
JS - 4. RPS
#javascript:javascript-beginner-en-Bthev-mskY8
(works only in the codecademy site, but you might get the idea)
In the composer, not all of these links look live. After you submit the post they appear fine. If you go back into the composer they will not look live again.
The ones that aren’t showing as live have this class (in the composer):
class="hashtag hashtag-tested tag-hashtag-tested"
The ones that do show live have:
class="hashtag"
This is an image demo:
Note that only the first two are showing live (clickable). But when you submit the post, they all appear live.
This is the relevant JavaScript category over those forums, if it’s needed.
Credits to @AlbionsRefuge for the initial draft
2 « J'aime »
I got the relevant files after some manual digging. They are these three:
/**
Supports Discourse's category hashtags (#category-slug) for automatically
generating a link to the category.
**/
Discourse.Dialect.inlineRegexp({
start: '#',
matcher: /^#([\w-:]{1,101})/i,
spaceOrTagBoundary: true,
emitter: function(matches) {
var slug = matches[1],
hashtag = matches[0],
attributeClass = 'hashtag',
categoryHashtagLookup = this.dialect.options.categoryHashtagLookup,
result = categoryHashtagLookup && categoryHashtagLookup(slug);
if (result) {
return ['a', { class: attributeClass, href: result[0] }, '#', ["span", {}, result[1]]];
} else {
return ['span', { class: attributeClass }, hashtag];
This file has been truncated. show original
export const SEPARATOR = ":";
export function replaceSpan($elem, categorySlug, categoryLink) {
$elem.replaceWith(`<a href="${categoryLink}" class="hashtag">#<span>${categorySlug}</span></a>`);
};
export function categoryHashtagTriggerRule(textarea, opts) {
const result = Discourse.Utilities.caretRowCol(textarea);
const row = result.rowNum;
var col = result.colNum;
var line = textarea.value.split("\n")[row - 1];
if (opts && opts.backSpace) {
col = col - 1;
line = line.slice(0, line.length - 1);
// Don't trigger autocomplete when backspacing into a `#category |` => `#category|`
if (/^#{1}\w+/.test(line)) return false;
}
This file has been truncated. show original
The following file adds the "hashtag-tested" class:
import { replaceSpan } from 'discourse/lib/category-hashtags';
const validCategoryHashtags = {};
const checkedCategoryHashtags = [];
const testedKey = 'tested';
const testedClass = `hashtag-${testedKey}`;
function updateFound($hashtags, categorySlugs) {
Ember.run.schedule('afterRender', () => {
$hashtags.each((index, hashtag) => {
const categorySlug = categorySlugs[index];
const link = validCategoryHashtags[categorySlug];
const $hashtag = $(hashtag);
if (link) {
replaceSpan($hashtag, categorySlug, link);
} else if (checkedCategoryHashtags.indexOf(categorySlug) !== -1) {
$hashtag.addClass(testedClass);
}
});
This file has been truncated. show original
Now, it should be probably easy to find the bug.
2 « J'aime »
tgxworld
(Alan Tan)
Mars 19, 2016, 4:42
3
I’ll have a look next week.
2 « J'aime »
tgxworld
(Alan Tan)
Mars 28, 2016, 3:17
4
Thanks for reporting @GaurangTandon Turns out category slugs are case sensitive but my query wasn’t.
Fixed in
committed 03:15AM - 28 Mar 16 UTC
4 « J'aime »