Anchors Not Working Across Posts Within Topic

We’re trying to set up a topic as a sort of FAQ/forum usage guide, and in doing so we’d like to have a number of longer posts, each with a number of headings, and compile a table of contents in the first post of the topic so users can easily jump around.

This is proving deceptively difficult to make work as intended and digging around Meta isn’t really helping, unfortunately. We’re aware of the plugin-thingy (auto-ToC or whatever it’s called), but we just want this for one singular topic and so don’t really want to deal with that.

We’ve tried using the link icons next to an auto-generated markdown header via the # symbols, but that isn’t working - we’re not sure if this is just because of the colors we’re using for the headers, or something else entirely, but in any case this works for some but not all of our headers.

Trying to use HTML tags with manual ids for our headers had no success either - this just wasn’t jumping to the links at all. We saw somewhere on Meta that the id information was being stripped out by Discourse and stopped pursing this approach.

We then saw a clever idea using empty links placed right above our headers that you could just jump to, and although this at first seemed to work after we get a few posts down it also stops jumping to the correct place in the linked post.

Does anybody know why headers seem to be so broken, and how we can make them work across multiple posts within a single topic? I’m classifying this as a bug, because the behavior seems incredibly undesirable, but I’d be okay jumping through some hoops on our end to get this working if anybody knows how.

For anchors to work across longer topics you would need to use the full post address with the header appended to compensate for the target post not being loaded on the screen.

If the anchor was <a name="anchor"></a> in the OP of this topic, using this link would work even in post eg 456

Does that help?

1 Like

That is what we were already doing, unfortunately

Our links in the ToC were of this format:

and our actual links in the posts were of this format

<a name="header--header-name"></a>

Worked for the first few posts, broke around post 8 or 9.

1 Like

I use this method on another site and it works really well for me. Have you got a link you could share so I can see it in action?

No, unfortunately, because the post is still restricted to staff-only.

Maybe I could try to replicate our setup on the theme creator website and see if it works there?

Update: Theme creator has no DIscourse BBCode, so I’m not convinced it’ll be perfectly 1:1. Unfortunate.

We tend to use for these, but it may be more effort than it’s worth in this case?

The only thing that looks different than the ones I use is the double hyphen, but that seems a long shot. Perhaps it’s the amount of header links? I’m not sure.

1 Like

That’s what I suspect, and why this is classified under #bug and not #support.

I forgot about try, might move over

1 Like

Got 'em

Reproducible on Try

The first few sets of anchor links work

The anchors for the last three posts do not

Sorry to push this out on a weekend

When do things on try get wiped, generally? Would prefer to not have to rebuild that entire set of anchor links again lol

They work for me the first time, and on a page refresh, but don’t when I use the navigation timeline to return to the OP.

I have ‘go back’ links in my similar posts with the full post address of the OP/TOC headers in, which would perform a page refresh. Would that work for you?

1 Like

I mean, we could certainly use that as a stopgap

Because you are right, that does indeed work

However, nobody navigates like that normally, so I definitely think this is a pretty clear-cut bug and ideally should be patched when the team has time to get around to it

Actually we’ll probably just only link to the top-level posts, and add in the specific section anchors when it’s been fixed

Seems better than a broken feature for our users

Is there any way to save this post on Try from getting wiped so somebody who knows more about Discouse than I do can poke around to figure out why this is happening?

Or would I be better off to recreate it here?

You could open those posts up in edit mode or grab the raw version and copy them over to a topic on your site as a more permanent example to link to (or to save them and recreate them on try again at a later point).

eh I’ll just do it here

this way there’s no chance of something on our site messing with the team’s ability to fix the issue