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

Abierto Apto para principiantes
#100 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
84/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
cli

Línea de trabajo

El prefijo de ruta se añade en internal/core/toc/renderer.go, dentro de Renderer.Render. Lee primero esa función y las pruebas existentes del renderizador. Codifica los espacios del prefijo del enlace como %20 y luego confirma que las entradas sin espacios y los mensajes de error mantienen su salida actual; la reproducción del issue muestra el TOC esperado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Go
Estrellas
525
Forks
89
Merge medio
6 min
PR fusionados (30 d)
1

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ekalinin/github-markdown-toc.go

Todos los issues de ekalinin/github-markdown-toc.go

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.