[ BUG ] TOC links break when a path with a space is one of several inputs
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
The path prefix is added in internal/core/toc/renderer.go, in Renderer.Render. Read that function and the existing renderer tests first. Encode spaces in the link prefix as %20, then confirm inputs without spaces and error messages retain their current output; the reproduction in the issue gives the expected TOC.
Written by the indexing model from the issue text.
Description
Describe the bug
With several inputs, every TOC entry links to <input>#<anchor>, with the input as given
on the command line. When the input has a space, the link is not valid Markdown, and
GitHub renders the entry as plain text. The names of GitHub wiki pages can have spaces.
The Bash version had the same bug (ekalinin/github-markdown-toc#76) and fixed it in
ekalinin/github-markdown-toc#190.
To Reproduce
mkdir "test directory"
printf '# Title one\n\n## Section\n' > "test directory/a.md"
printf '# Title two\n' > "test directory/b.md"
gh-md-toc --hide-footer "test directory/a.md" "test directory/b.md"
Actual:
* [Title one](test directory/a.md#title-one)
* [Section](test directory/a.md#section)
* [Title two](test directory/b.md#title-two)
The GitHub Markdown API renders the first entry as
<li>[Title one](test directory/a.md#title-one)</li>, without a link.
Expected behavior
As in the Bash version, every space in the link prefix is replaced with %20, and no
other character changes:
* [Title one](test%20directory/a.md#title-one)
* [Section](test%20directory/a.md#section)
* [Title two](test%20directory/b.md#title-two)
Inputs without a space give the same output as now. Messages that show the input, such
as errors, keep it as given.
Environment (please complete the following information):
- OS: macOS (darwin/arm64)
- Version: 2.0.1, current
master(dd680f7)
Additional context
- The prefix is added in
Renderer.Render(internal/core/toc/renderer.go):
link = path + link. - With
--insert, local files get bare anchors, so the TOC written into them is not
affected.
- Dominant language
- Go
- Stars
- 525
- Forks
- 89
- Avg merge
- 6m
- Merged PRs (30d)
- 1
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ekalinin/github-markdown-toc.go
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 65/100
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 55/100
All issues in ekalinin/github-markdown-toc.go
Similar issues
-
book-layout.spec fails when the similar-books rail holds other projects' booksPossibly taken @praetorianer777 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
praetorianer777/GoTome#373 ·
Maintainers usually reply within 1 day
-
/shutdown/ready can fail to return an HTTP response when readiness takes longer than the server write timeoutPossibly taken @floriankoch claimed this today. Opentriage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
envoyproxy/gateway#10562 ·
Maintainers usually reply within 1 day
-
Adding an LDAP group reports every search failure as "LDAP Group DN is not found"Possibly taken @Daksha1611 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100