lifeparticle / binarytree

🕰 We Provide an Array of Developer Productivity Tools Designed To Help You Save Time
https://binarytree.dev
Apache License 2.0
37 stars 13 forks source link

Anchor link for headers with "and" #470

Open lifeparticle opened 5 months ago

lifeparticle commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago
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

MajorKeen commented 5 months ago

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 \   Space
160 240 A0 10100000 NBSP Non-breaking space
MajorKeen commented 5 months ago

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 \ 
\ 
\ 
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

lifeparticle commented 5 months ago

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

lifeparticle commented 5 months ago
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>