binarytree icon indicating copy to clipboard operation
binarytree copied to clipboard

Anchor link for headers with "and"

Open lifeparticle opened this issue 1 year ago • 6 comments

Steps to Reproduce:

  1. Create a markdown file with:
    ## Mention people and teams
    ## Reference issues and pull requests
    
  2. View it on GitHub.

Expected: #mention-people-and-teams #reference-issues-and-pull-requests

Actual: #mention-people-andteams #reference-issues-and-pullrequests

Impact: Broken navigation links.

lifeparticle avatar Jun 10 '24 12:06 lifeparticle

https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-readmes#auto-generated-table-of-contents-for-readme-files

Image

lifeparticle avatar Jun 10 '24 12:06 lifeparticle

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/markdown \
  -d '{"text":"# Reference issues and pull requests \n # Mention people and teams", "mode": "markdown"}'
<div class="markdown-heading"><h1 class="heading-element">Reference issues and pull requests</h1><a id="user-content-reference-issues-and-pull-requests" class="anchor" aria-label="Permalink: Reference issues and pull requests" href="#reference-issues-and-pull-requests"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>

<div class="markdown-heading"><h1 class="heading-element">Mention people and teams</h1><a id="user-content-mention-people-and-teams" class="anchor" aria-label="Permalink: Mention people and teams" href="#mention-people-and-teams"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>

markdown api

lifeparticle avatar Jun 12 '24 07:06 lifeparticle

Looks to be a non-issue it was caused by the introduction of the ASCII character code 160 the non-breaking space. When generating the anchor navigation links, GitHub's markdown parser converts spaces to hyphens. In this particular case it was not happening due to the space character not being the standard ASCII space character code 30

DEC OCT HEX BIN Symbol HTML Number HTML Name Description
32 040 20 00100000 SP &#32;   Space
160 240 A0 10100000 NBSP &#160; &nbsp; Non-breaking space

MajorKeen avatar Jun 14 '24 05:06 MajorKeen

Other spaces characters to look out for but in the Unicode space are:

Code HTML Entity UTF-8 Encoding UTF-16 Encoding UTF-32 Encoding
U+2003 &#8195;&#x2003;
&emsp;
0xE2 0x80 0x83 0x2003 0x00002003
U+2002  
 
 
0xE2 0x80 0x82 0x2002 0x00002002

A list of other possible spaces in Unicode can be found at the below link: https://www.compart.com/en/unicode/category/Zs

MajorKeen avatar Jun 14 '24 06:06 MajorKeen

@MajorKeen many thanks for your detailed explanation, it make sense now. I will try to handle these special cases in the TOC generator.

lifeparticle avatar Jun 14 '24 07:06 lifeparticle

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/markdown \
  -d '{"text":"# Reference issues and pull&nbsp;requests \n # Mention people and teams", "mode": "markdown"}'
<div class="markdown-heading"><h1 class="heading-element">Reference issues and pull requests</h1><a id="user-content-reference-issues-and-pullrequests" class="anchor" aria-label="Permalink: Reference issues and pull requests" href="#reference-issues-and-pullrequests"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>

<div class="markdown-heading"><h1 class="heading-element">Mention people and teams</h1><a id="user-content-mention-people-and-teams" class="anchor" aria-label="Permalink: Mention people and teams" href="#mention-people-and-teams"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>

lifeparticle avatar Jun 14 '24 13:06 lifeparticle