Vincular a um título dentro de uma postagem ou tópico

:bookmark: This guide explains how to link directly to a heading within a Discourse post or topic, enabling users to navigate long posts efficiently.

:person_raising_hand: Required user level: All users

Adding headings within long posts can make the content more readable and allow users to link directly to specific sections. This can be particularly useful for navigating extensive discussions and documentation.

Summary

This guide covers:

  • Creating headings using Markdown
  • Linking directly to specific headings in a post

Creating headings using Markdown

To create a heading in Markdown, prefix a line of text with one or more # characters. The number of # characters corresponds to the heading level. Here are some examples:

## This is a level 2 heading
Here is a short paragraph afterwards.

### This is a level 3 heading
Here is another short paragraph.

When rendered, it looks like this:


This is a level 2 heading

Here is a short paragraph afterwards.

This is a level 3 heading

Here is another short paragraph.


Linking directly to a heading

To share a direct link to a heading within a post:

  1. Hover over the heading to reveal a link icon next to it: link icon.
  2. Click the link icon to update the URL in your browser’s address bar with the direct link to that heading.
  3. Copy the updated URL from the address bar to share it with others.

Best practices

  • Use descriptive headings to summarize content clearly.
  • Structure your post using hierarchical headings where appropriate.
  • Ensure that headings are consistent and logical for better readability.

FAQs

Can I link to any part of a post?
Yes, as long as it’s a heading properly formatted in Markdown.

Do links to headings work across different posts?
Yes! These links will direct to the header in the post when used in other topics or shared somewhere else.

Additional resources

Last edited by @JammyDodger 2024-07-09T11:12:13Z

Last checked by @hugh 2024-08-08T01:48:04Z

Check documentPerform check on document:
73 curtidas

Não estou vendo os ícones de link neste site ou no meu. Nem no FF nem no Chrome.

Aconteceu alguma mudança?

Você precisa passar o mouse sobre o título para que eles apareçam:

Eu passo o mouse e não vejo nada.

Parece haver algo ali, mas nenhum ícone é exibido.

Uma pergunta de acompanhamento…

Estou supondo que, se você alterar o texto do cabeçalho, o link será quebrado.

EDIT PARA ADICIONAR: Não só o âncora muda se o título mudar, mas se você inserir outro cabeçalho antes dos cabeçalhos existentes, o sufixo numérico no cabeçalho muda. Isso parece frágil a ponto de ser inútil.

A única solução segura seria envolver os cabeçalhos em tags a html e dar-lhe um id, correto?

Edição novamente para adicionar: Tentei envolver o texto do cabeçalho em tags a e apenas colocar tags vazias antes do texto do cabeçalho. Nenhum dos IDs funcionou. Eu também tentei spans em vez disso com a mesma falha.

Sim, consigo encontrá-lo no DOM como um before:

Estou no Windows 11.
A única maneira que consigo fazer o ícone de link aparecer é copiando o link e, em seguida, abrindo esse link (com o # e o id) em uma nova aba e indo para lá. Então, o ícone de link é exibido o tempo todo (sem pairar o mouse), mas ainda assim, nenhum dos outros ícones de link aparecerá ao pairar o mouse.

É permitido dar um “bump” nisso? Estou me perguntando se estou perdendo algo óbvio sobre como inserir links em uma postagem.