[ 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 摘要。