HTML anchors should be added


(NomNuggetNom ) #1

I believe this is a bug, not intentional, but Discourse breaks functionality of anchors. Here’s the example from w3schools:


See also Chapter 4.

Chapter 1

This chapter explains ba bla bla

Chapter 2

This chapter explains ba bla bla

Chapter 3

This chapter explains ba bla bla

Chapter 4

This chapter explains ba bla bla

Chapter 5

This chapter explains ba bla bla

Chapter 6

This chapter explains ba bla bla

Chapter 7

This chapter explains ba bla bla

Chapter 8

This chapter explains ba bla bla

Chapter 9

This chapter explains ba bla bla

Chapter 10

This chapter explains ba bla bla

Chapter 11

This chapter explains ba bla bla

Chapter 12

This chapter explains ba bla bla

Chapter 13

This chapter explains ba bla bla

Chapter 14

This chapter explains ba bla bla

Chapter 15

This chapter explains ba bla bla

Chapter 16

This chapter explains ba bla bla

Chapter 17

This chapter explains ba bla bla


If this is intentional, then I suppose another topic on the usefulness of them is in order? ;). I don’t think this is something that can be fixed with a plugin.


Using Discourse as a FAQ Help Center
(Jeff Atwood) #2

Correct, we don’t currently support HTML anchors :wink:

And technically anchor is a deprecated term and usage in modern HTML.


(NomNuggetNom ) #3

Although the Discourse meta forums don’t have huge posts, the forums that I use contain posts that really need anchors, like tutorials and guides and what not. Without folding spoilers, and without anchors, navigating lengthy posts is a massive pain. Is there a specific reason you don’t support them?


(Jeff Atwood) #4

I would rather make H1 and H2 and H3 support automatic, implicit div ids (aka anchors) like GitHub does. You can see it in action on any GitHub markdown file.


(NomNuggetNom ) #5

That would be cool too, but why not both? :wink:


(Nathan Rijksen) #6

Is there any workaround for this atm? I’ve tried adding elements with id or name attributes but it seems to be stripped when converted to html, making it impossible to even add manual anchors.


(NomNuggetNom ) #7

Yeah, Discourse has some HTML tags that are purposefully stripped. I’ll try
and make a workaround.


(Nathan Rijksen) #8

Had any luck @NomNuggetNom? :slight_smile:


(Felipe Cypriano) #9

Is this a planned feature? I just copied a big wiki page from GitHub into my Discourse and noticed that the links weren’t working.


Bounty / Crowdfund features
(Allen - Watchman Monitoring) #11

Is there something we could do to help this?


(Allen - Watchman Monitoring) #12

What replaced them? (I’m sure I missed the memo)


(Mittineague) #13

Element id attribute values.
For a while not all browsers supported it but AFAIK all modern browsers now do.


(Allen - Watchman Monitoring) #14

In a discourse post, adding <a name="flag-problems"></a> if i wanted to link to a page in http://fqdn/page#flag-problems

[Edited, this is how]

PPS This only works for links within a topic, not to link to the topic externally


(Jonathan Simmons) #15

@codinghorror I’d love to know what your source for this is?

Looking across the internet you’ll see that id anchors are still widely used. The Discourse FAQ page even uses the name="method" which is an old form of the ID anchor (deprecating in HTML5).

Yet if you try either of these in a discourse topic they don’t work. The name="method" works but only once on a topic, not as an external link. Which to me looks like discourse is intentionally stripping ID anchor links.


(NomNuggetNom ) #16

You're correct, Discourse strips the anchor tag. You can create a simple plugin to whitelist it.


(Jeff Atwood) #17

The anchor tag is what is deprecated in HTML 5. Bad idea.

The <a> tag with a name or id attribute is no longer used as a placemark for the target of a hypertext link. Most HTML tags may now include an id attribute for that purpose. Therefore, whenever there is an <a> tag with an id or name attribute but no href attribute, the value of the attribute should be coded as the id attribute of the tag following it:


(NomNuggetNom ) #18

The point remains that there should be anchoring functionality. If it uses HTML5 standards, even better.


(Jonathan Simmons) #19

@codinghorror explain why I can send you a link to the official HTML5 Docs that looks like this:
http://www.w3.org/TR/html5/obsolete.html#warnings-for-obsolete-but-conforming-features

This link when clicked scrolls to the HTML element with that ID specified in the url. Why can’t I do that on discourse.

This should work in Discourse but does not:

<a href="#some_element>Link to a div further down on the page</a>

<div id="some_element"> Some useful content we want to link to</<div>

What is the point, what is the gain that Discoure gets by stripping #something form a url? You’ve yet to answer that.


(Allen - Watchman Monitoring) #20

I can? Do tell… I’d say you can bill me for it, but what I really want, @NomNuggetNom, is a plugin to create anchors on the fly from my topic headings.


(Mittineague) #21

Aren’t topic headings always “top” and therefore wouldn’t need an anchor?