5

I am working in Stack Overflow for Teams - Enterprise (hosted in my company).

The issue below is encountered when entering longer posts, in the form of articles.

Markdown has no standard defined to insert a Table of Contents for the content in a post.

I'm trying to create one through a manual approach in the Markdown specification: a list of links:

# Table of Content

* [description1](link1)
* [description2](link2)
* ...

I want the link to jump to the corresponding header within the same post. But, I don't know how to:

  • Create the anchor; I have tried embedded HTML, but that gets stripped out by the Stack Overflow Markdown renderer:

    <a name="Link"></a>
    
  • Create the actual link; embedded HTML also doesn't get the job done (HTML tags are just stripped):

    <a href="#Link">Description</a>
    

I have found solutions for Markdown for GitHub, Bitbucket, etc., but none of those suggestions seem to apply to Stack Overflow.

9
  • 9
    You can't. We don't have anchors enabled
    – Catija StaffMod
    Mar 20, 2022 at 16:55
  • @CodyGray Why was this closed?
    – pppery
    Mar 24, 2022 at 14:53
  • 1
    I can understand that I shouldn't ask questions about StackOverflow for Teams in StackOverflow (where I originally posted my question)? But isn't this question a perfect question for StackOverflow Meta??!
    – Flandraco
    Mar 24, 2022 at 22:18
  • @Flandraco "Stack Overflow for Teams" is really two substantially different products, which SO marketing has decided will share the "Stack Overflow for Teams" name. What Meta Stack Overflow understands as "Stack Overflow for Teams" is the web-based product for smaller or mid-sized teams which is hosted by Stack Overflow on Stack Overflow's servers. That product is relatively new (couple years). There's also Stack Overflow for Teams: Enterprise, a product for Enterprise level customers which is hosted on your company's servers. The Enterprise product has been available for many years.
    – Makyen Mod
    Mar 24, 2022 at 23:45
  • 1
    Given you stated your "company updated our Stack Overflow for Teams to a recent release", it's assumed that you're asking about the Enterprise level product (because that's the only product where your company could update a release). Part of the Enterprise level of product is that such customers have a dedicated support structure first within your organization and then to dedicated people inside Stack Overflow. There's almost certainly a direct way for you to contact them. Unfortunately, I don't have that information and can only suggest using the "Contact Us" link at the bottom of the page.
    – Makyen Mod
    Mar 24, 2022 at 23:46
  • 1
    Enterprise support is not provided through Meta Stack Overflow, both because there's a desire to provide the dedicated support which your company is paying for with the Enterprise product and because the people on Meta Stack Overflow just don't have access to the Enterprise product, which is different, at least in some characteristics (example: my answer below saying what you wanted isn't possible, which it isn't on Stack Overflow proper, but it is possible in the Enterprise level product, as you demonstrated with your answer).
    – Makyen Mod
    Mar 24, 2022 at 23:46
  • 2
    So, while we here on Meta Stack Overflow (MSO) want to help you, we really can't give you good assistance for the Enterprise product here on MSO. MSO is the correct place to ask questions about the web-hosted version of Stack Overflow for Teams, but not the self-hosted, Enterprise level product. In my opinion, it's unfortunate that Stack Overflow has chosen to not more clearly differentiate the web-hosted and self-hosted Enterprise products.
    – Makyen Mod
    Mar 24, 2022 at 23:46
  • 1
    I do realize, however, that my/our assumption that you're using the Enterprise version of Stack Overflow for Teams may be wrong. You haven't confirmed that you are using the self-hosted, Enterprise product rather than the web-hosted version. If you're using the web-hosted version, then you would access Stack Overflow for Teams through a URL which starts with https://stackoverflow.com/c/. I would appreciate you confirming in a comment here, or in your question, which version of the Stack Overflow for Teams product you're using.
    – Makyen Mod
    Mar 24, 2022 at 23:46
  • 1
    @pppery It was closed because it's believed the question is asking about "Stack Overflow for Teams: Enterprise", which has dedicated support and isn't supported through Meta Stack Overflow, largely because we don't have access to that product, so can't really know anything we respond with is actually correct (see above for a more detailed discussion).
    – Makyen Mod
    Mar 24, 2022 at 23:49

2 Answers 2

8

Articles on Stack Overflow and Stack Overflow for Teams can have tables of content

For articles, the backend Markdown to HTML conversion process automatically adds an id attribute to header elements, which allows targeting a link to the headers. The format of the automatically generated id has changed at least once over time. The automatically generated id is based on the text of the header, so if the header text changes, then the id, and thus the URL, will change. Currently, it's the text "header-" followed by "all-the-words-in-the-header-converted-to-lowercase-and-joined-with-hyphens".

While you can determine prior to saving what the id will be, and thus what URL to use, you're probably better off first saving a draft of the article, copying the URLs needed for the headers you desire to link to in your table of contents, then editing the article to add links to those URLs. Links can be in any supported Markdown or HTML link format (e.g. the basic Markdown format of [link text](URL); see the Markdown editing help for more detail about how to create links).

You can probably manually assign an id to explicit HTML header elements (I haven't verified current availability of this feature)

Being able to manually assign an id was possible for <hx> elements which were explicitly placed within the Markdown as HTML text. In other words, <h4 id="my-unique-manual-id">Some header text</h4> would produce a level 4 header element with the id of my-unique-manual-id. This feature was available when header ID generation was briefly turned on for Stack Exchange in general. I don't know if it was retained after id support was limited to only in articles.

Other types of posts can not have a table of contents which is linked to content within a Stack Exchange post.

Unlike articles, the Markdown to HTML conversion for other types of posts does not add id attributes to header elements. There is, currently, no way to create link targets (i.e. anchors with a name1 or elements with an id) within a Stack Exchange post.2 Given that you can't create a link target within an SE post, there's no way to have links within your SE post which link to somewhere else within the same post (or target within almost any Stack Exchange post).

You can link to other SE posts, but you must use either a path-relative URL (e.g. /a/123456) or a protocol-relative URL (e.g. //stackoverflow.com/a/123456), as using a fragment-relative (e.g. #answer-123456, normally used for links within the same page) will result in the <a> element being stripped when Stack Exchange converts the post from Markdown to HTML.

For more detail of what HTML is permitted in Stack Exchange posts, see: "What HTML tags are allowed on Stack Exchange sites?"


  1. Using a name attribute with an <a> element is deprecated. An id attribute should be used instead.
  2. There was a brief time (couple/few weeks in 2021-07) where Stack Exchange automatically created id attributes for header elements within posts and allowed custom id attributes for explicit HTML header elements (e.g. <h4 id="foobar">). Unfortunately, generating/permitting those id attributes was turned off after only a short time. These were created during the Markdown➞HTML conversion process. Stack Exchange only does the Markdown➞HTML conversion process upon the post being posted or edited, so you may find some posts which were posted or edited in the timeframe during which this was enabled which still have internal anchors.
4
  • 1
    Just making sure: the definition of post in this answer also applies to a StackOverflow article?
    – Flandraco
    Mar 21, 2022 at 17:31
  • 1
    @Flandraco It applies to anything which is rendered from Markdown to HTML by Stack Exchange's backend post Markdown processor, so, yes, it includes ̵a̵r̵t̵i̵c̵l̵e̵s̵,̵ questions, answers, election nominations, election question responses, help center articles, etc.
    – Makyen Mod
    Mar 21, 2022 at 18:07
  • @Flandraco Ironically, you could sort-of make it work with links from comments, if you're willing to accept that it will work only in Chrome and browser's derived from Chrome. For example, this is a link to a question which will highlight and scroll to some text within an answer. Unfortunately, the backend post Markdown to HTML converter mangles such links, so they can't be used in posts.
    – Makyen Mod
    Mar 21, 2022 at 18:09
  • @Flandraco I apologize. Unfortunately, I relied on information from other people and didn't do enough of my own research. I've updated this answer to reflect that articles, even in SO Collectives, do support having a table of contents. I have not verified that tables of content are possible in the web-based "Stack Overflow for Teams: Business", because I'm not a member of a Team which has articles enabled. Given that a ToC is supported in articles for Collectives, I consider it very likely that they are supported in the web-based "Stack Overflow for Teams: Business", which supports articles.
    – Makyen Mod
    Mar 27, 2022 at 3:59
4

Last weekend, my company updated our Stack Overflow for Teams to a recent release.

This release has the auto-header-link generation available...

I can manually build my Table of Contents as a list. I can get the links by hovering over the link, using the context menu, selecting the Copy link address command:

# Table of Contents

* [Header1](Link1)
* [Header2](Link1)
...

Copy link address

1
  • 2
    Based on you saying "my company updated our Stack Overflow for Teams to a recent release", I assume you're using the Enterprise product (i.e. the Stack Overflow which is hosted on your company's servers, rather than hosted on a webpage by Stack Overflow). Ohhhh... It looks like Stack Overflow renamed "Stack Overflow Enterprise" to be under the "Stack Overflow for Teams" umbrella as "Stack Overflow for Teams: Enterprise". That's going to be confusing for us here on Meta Stack Overflow. But, it's good to know.
    – Makyen Mod
    Mar 23, 2022 at 18:25

Not the answer you're looking for? Browse other questions tagged .