[ BUG ] TOC links break when a path with a space is one of several inputs

Aperta Adatta ai principianti
#100 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
cli

Direzione di ricerca

Il prefisso del percorso viene aggiunto in internal/core/toc/renderer.go, in Renderer.Render. Leggi prima quella funzione e i test esistenti del renderer. Codifica gli spazi nel prefisso del link come %20, poi verifica che gli input senza spazi e i messaggi di errore mantengano l’output attuale; la riproduzione nell’issue mostra il TOC previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

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.
Lingua principale
Go
Stelle
525
Fork
89
Merge medio
6m
PR unite (30g)
1

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ekalinin/github-markdown-toc.go

Tutte le issue di ekalinin/github-markdown-toc.go

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.