[Feature] Warn about headings that skip a level

未关闭
#97 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
github, go
领域
backend, cli

调研方向

Read the TOC generation and filtering paths for --depth and --start-depth, along with the implementation of --numbered outline referenced in the issue. Decide whether to warn for every skipped level or only cases affected by indentation, and what link the warning should use. Done means warnings go to stderr for the retained entries, with each input checked independently and the TOC output and exit code unchanged.

由索引模型根据 Issue 内容生成。

描述

enhancement

Is your feature request related to a problem? Please describe.

When a heading skips a level (# Title followed by ### Skipped), GitHub can render its
TOC entry as text of the parent entry, on one line. The TOC is built without any notice.
The same request for the Bash version is ekalinin/github-markdown-toc#75, and it is
implemented there in ekalinin/github-markdown-toc#187.

Here it depends on the indent. TOCs rendered by the GitHub Markdown API:

Headings Indent Rendered
# Title two, then ### Skipped 2 (default) a nested list, as expected
# Title two, then ### Skipped 3 one item: Title two * Skipped
# Title, then #### Deep 2 (default) one item: Title * Deep

Describe the solution you'd like

The same warning as in the Bash version. For every TOC entry whose heading level is
greater than the level of its parent plus 1, print to stderr:

Warning: heading 'Skipped' (level 3) skips a level after 'Title two' (level 1), see https://github.com/ekalinin/github-markdown-toc/issues/75

Behavior in the Bash version:

  • The TOC does not change: on stdout and in the file with --insert. The warning never
    goes to stdout or into the file, and the exit code stays the same.
  • The parent of an entry is the nearest previous TOC entry with a lower level, as for
    --numbered outline (#92).
  • One line per such entry, in document order. An entry without a parent gets no warning.
  • It applies to every input. With several inputs each document is checked on its own,
    and each line starts with the input as given on the command line, followed by : .
  • With --depth, only the entries kept by --depth are checked, and the parent is taken
    among them.

Additional context

  • Here entries are also dropped by --start-depth. The check should use only the entries
    that stay in the TOC, as with --depth.
  • To decide: warn on every skipped level, as the Bash version does, or only when the
    indent makes GitHub render the entry as text (see the table above).
  • To decide: the link in the message points to the issue of the Bash version.
主要语言
Go
星标
525
派生
89
平均合并
6 分钟
30 天内合并 PR
1

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ekalinin/github-markdown-toc.go 的其他 Issue

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

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。