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

オープン 初心者向け
#201 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
github, markdown, shell
領域
cli, tooling

調査の方向性

issueで選択した行を見出しのgrepの前に結合すると説明されている、gh-md-toc の gh_toc_grab から始めます。提供された test.md の例を使って再現し、ローカルファイルとstdinの両方で、リンクまたはインラインコードを含む見出しがTOCに含まれることを確認します。期待される3つの項目が順番どおりに表示されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Shell
スター
3.3k
フォーク
2.7k
平均マージ
1時間 56分
マージ済み PR(30日)
21

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ekalinin/github-markdown-toc のほかの issue

ekalinin/github-markdown-toc の issue をすべて見る

似ている issue

Shell/Bash の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。