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

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

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
github, markdown, shell
Ambito
cli, tooling

Direzione di ricerca

Inizia da gh_toc_grab in gh-md-toc, che, secondo quanto indicato nell’issue, unisce le righe selezionate prima di cercare i titoli con grep. Riproduci il problema usando l’esempio test.md fornito, quindi verifica che i titoli con link o codice inline siano inclusi nel TOC sia per un file locale sia per stdin. Il lavoro è completato quando compaiono le tre voci previste nell’ordine corretto.

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

Descrizione

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.

Lingua principale
Shell
Stelle
3.3k
Fork
2.7k
Merge medio
1h 56m
PR unite (30g)
21

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

Tutte le issue di ekalinin/github-markdown-toc

Issue simili

Altre issue su Shell/Bash

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.