Linking to portions of a post

(Tom Shea) #1

Is there any way to link to a specific subportion of a large post? At first I attempted to specify an HTML name for an element and reference it [like so](#name). However, discourse (rightly) automatically strips name and id attributes from elements. As a side note, I’m not entirely sure that it would work anyway, as clicking anchor links of that style appears to redirect to the homepage.

The reason I would want to do this is that I am somewhat stretching the intended use for discourse by running a Nomic game on it. This game features a very long post with many rules with detailed descriptions, which will be edited and expanded as the game progresses. It would be very useful if I were able to insert a link to a specific rule when discussing it, rather than quoting the rule, which can become very cumbersome when discussing the interaction between multiple rules.

(Bill Ayakatubby) #2

You could break up the rules into sections and put each section in its own post. Then you can link to a specific post when you need to call out a rule. Since the rules can change, maybe reserve the first 7-10 posts for rules expansion.

(Tom Shea) #3

It’s a serviceable solution, although I am somewhat uncomfortable with the enforced number of sections that would cause. Perhaps a separate rules topic would work, but I’d still prefer the named elements solution. I will experiment and report back.

(Jeff Atwood) #4

I noticed that GitHub automatically adds deep links for each heading in content. That could make sense but it is kind of a rare use case. I suggest doing what @BhaelOchon recommended first.

(Tom Shea) #5

I’ve compromised by creating a topic explicitly for holding rules, and making each rule its own reply. There are some nice side effects to that, such as being able to see posts where a rule has been invoked or referenced.

I would love the automatic header deep links, but I understand why that would be a low priority feature. Might make it a plugin myself if it bothers me enough.

(Evaryont 🎆) #6

It’s also doesn’t make sense as what defines a “heading” in Discourse? While Markdown is fully supported (so you could do # Part 1) I think it’s such a rare and unlikely to be used feature.

However, adding ids to headers makes a lot of sense if once wiki posts are supported.

(Tom Shea) #7

I don’t understand where ambiguity could exist on that subject, headings would be defined as h1-h6 surely?

(Marcin Rataj) #8

Seems that this is still missing(?)

Idea: perhaps renderer could just assign a slug generated from contents to each header (h1-h6)?


# this is a title

should render as a named anchor:

<a name="this-is-a-title"><h1>this is a title</h1></a>

one could then link to its location directly:

[jump to local anchor](#this-is-a-title)

(Tom Newsom) #9

This functionality is planned for the next release.

(Matt) #10

Came here looking for this. (Sorry to be that guy reviving an old thread.) Did it ever go out with 1.5? Because I can’t find any instance of “deep linking” or “headings” in those release notes. Is there a way to link directly to headings yet?

(Tom Newsom) #11

It’s still listed in the upcoming features for 1.6, which has a planned release date of August. So we can hope to see it some time between now and then.