[ BUG ] Headings are missing from the TOC when GitHub puts a line break after the heading tag

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

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
github, markdown, shell
Área
cli, tooling

Línea de trabajo

Empieza con gh_toc_grab en gh-md-toc, que, según indica el issue, une las líneas seleccionadas antes de buscar encabezados con grep. Reproduce el problema usando el ejemplo test.md proporcionado y comprueba después que los encabezados con enlaces o código en línea se incluyan en el TOC tanto para un archivo local como para stdin. La tarea está terminada cuando aparecen las tres entradas esperadas en orden.

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

Descripción

bug

Describe the bug

Some headings are missing from the TOC, without any warning. For these headings the HTML from GitHub has a line break right after the opening heading tag:

<div class="markdown-heading"><h2 class="heading-element">
<a href="https://example.com" rel="nofollow">link</a> here</h2><a id="user-content-link-here" class="anchor" aria-label="Permalink: link here" href="#link-here"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>

gh_toc_grab joins a line with the next one only when the next one starts with </h or <span. So <h2 class="heading-element"> stays on its own line, the heading text and the anchor are on the next line, and grep '<h[1-6][^>]*class="heading-element".*</a' does not find the heading.

To Reproduce

cat > test.md <<'MD'
# Top

## [link](https://example.com) here

## `"q'` and *em*

## Last
MD
./gh-md-toc test.md

Output:

Table of Contents
=================

* [Top](#top)
   * [Last](#last)

The HTML from https://api.github.com/markdown/raw for the two missing headings:

<div class="markdown-heading"><h2 class="heading-element">
<a href="https://example.com" rel="nofollow">link</a> here</h2><a id="user-content-link-here" class="anchor" aria-label="Permalink: link here" href="#link-here"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<div class="markdown-heading"><h2 class="heading-element">
<code>"q'</code> and <em>em</em>
</h2><a id="user-content-q-and-em" class="anchor" aria-label="Permalink: &quot;q' and em" href="#q-and-em"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>

cat test.md | ./gh-md-toc - gives the same two entries.

Expected behavior

* [Top](#top)
   * [link here](#link-here)
   * ["q' and em](#q-and-em)
   * [Last](#last)

Environment (please complete the following information):

  • OS: macOS (Darwin 24.6.0)
  • Version: 0.11.0 (master at 34828c5)

Additional context

Found while looking into #153: a heading that starts with inline code can be missing too. Checked with a local file and stdin, not with a remote URL.

Lenguaje dominante
Shell
Estrellas
3.3k
Forks
2.7k
Merge medio
1 h 56 min
PR fusionados (30 d)
21

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

Todos los issues de ekalinin/github-markdown-toc

Issues similares

Más issues de Shell/Bash

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.