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

未關閉 適合新手
#201 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
github, markdown, shell
領域
cli, tooling

研究方向

從 gh-md-toc 中的 gh_toc_grab 開始。issue 指出,它會先連接選取的行,再用 grep 搜尋標題。使用提供的 test.md 範例重現問題,接著檢查本機檔案和 stdin 輸入的 TOC 中是否都包含帶有連結或行內程式碼的標題。預期的三個項目依序出現即表示完成。

由索引模型根據 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 分鐘
30 天內合併 PR
21

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

ekalinin/github-markdown-toc 的其他 Issue

查看 ekalinin/github-markdown-toc 的全部 Issue

相似的 Issue

更多 Shell/Bash Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。