[ BUG ] --insert and --stdout fill every <!--ts--> / <!--te--> pair, also in code blocks

Offen
#194 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
70/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
bash, markdown, shell
Bereich
cli, documentation

Rechercherichtung

Start with the marker check and the two sed edits described in the issue, then reproduce the behavior with the provided test.md example and --stdout. Compare the output with the expected behavior: marker pairs inside fenced code blocks should remain unchanged. Check --insert --no-backup on a copy of the README as well; done means both modes update the intended TOC while preserving the examples.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug

Describe the bug

--insert and --stdout put the TOC between every <!--ts--> / <!--te--> pair in the file. Marker lines inside fenced code blocks count too, so examples that show the markers are overwritten.

The marker check (grep -Fxq "<!--ts-->") only tests that a marker line exists. The edit (sed "/<\!--ts-->/,/<\!--te-->/{//!d;}", then sed "/<\!--ts-->/r ...") runs on every line that has a marker.

To Reproduce

printf '<!--ts-->\n<!--te-->\n\n# Title\n\nPut these lines into a file:\n\n```\n<!--ts-->\n<!--te-->\n```\n' > test.md
./gh-md-toc --hide-footer --stdout test.md

Output:

<!--ts-->
* [Title](#title)
<!--te-->

# Title

Put these lines into a file:

```
<!--ts-->
* [Title](#title)
<!--te-->
```

The README of this repository has three pairs: the TOC (lines 31-47) and two examples in code blocks of the "Auto insert and update TOC" section (lines 318-319 and 353-369). ./gh-md-toc --hide-footer --stdout README.md puts the TOC into all three:

  • the example "Just put into a file these two lines" gets the whole TOC between its two lines;
  • the example output of grep -A15 "<\!\-\-ts" README.test.md is replaced with the TOC of README.md.

--insert --no-backup --hide-footer on a copy of README.md gives the same file as --stdout.

Expected behavior

The examples in code blocks stay unchanged.

Environment (please complete the following information):

  • OS: macOS (Darwin 24.6.0)
  • Version: 0.11.0 (master at 62e6fe4)

Additional context

Found while looking into #119.

Vorherrschende Sprache
Shell
Sterne
3.3k
Forks
2.7k
Ø Merge
1 Std. 56 Min.
Gemergte PRs (30 T.)
21

Entwicklungsumgebung

  • Enthält ein Dockerfile oder eine Docker-Compose-Datei
  • Keine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus ekalinin/github-markdown-toc

Alle Issues in ekalinin/github-markdown-toc

Ähnliche Issues

Weitere Issues zu Shell/Bash

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.