[Feature] Numbered TOC: --numbered list|outline

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

还没有人认领这个 Issue。

评估

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

调研方向

Trace the CLI option parsing and TOC-generation entry points, then compare their depth, start-depth, indent, and multi-input behavior with the requested numbered modes. Done means both list and outline numbering work as specified, default output is unchanged, invalid combinations return exit code 1, and skipped entries are not numbered.

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

描述

enhancement

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

The TOC is always a bullet list (* [...]), and there is no way to get a numbered TOC.
The same request for the Bash version was ekalinin/github-markdown-toc#26, and it is
implemented there in ekalinin/github-markdown-toc#177.

Describe the solution you'd like

The same option as in the Bash version: --numbered <TYPE> with two types.

  • list: a markdown ordered list, every marker is 1.. GitHub numbers the items
    itself, and shows nested lists as i., then a.:

    1. [Title one](#title-one)
       1. [Section](#section)
    1. [Title two](#title-two)
    
  • outline: bullets with a hierarchical number at the start of the link text:

    * [1. Title one](#title-one)
       * [1.1. Section](#section)
    * [2. Title two](#title-two)
    

    The number follows the heading tree: the parent of an entry is the nearest previous
    entry with a lower level. So a skipped level does not add a part: # then ###
    gives 1. and 1.1., not 1.0.1..

Behavior in the Bash version:

  • Without --numbered the output does not change.
  • Only the entries kept by --depth are numbered.
  • With several inputs, the numbers of each document start from 1..
  • An unknown type is an error with exit code 1.
  • --numbered list with --indent less than 3 is an error: a child of 1. is nested
    only when it is indented 3 to 6 spaces more than the parent, otherwise GitHub renders
    one flat list.

Describe alternatives you've considered

  • Real counters in list (1., 2., 3.): GitHub uses only the first number of a
    list, and a two-digit marker (10.) needs an indent of 4 for its children.
  • A number before the link (* 2.1. [Section](#section)): GitHub parses 2.1. as an
    ordered list marker inside the bullet.
  • One counter per heading level instead of the tree: it gives the same number twice for
    #, ###, ## (1.1. and 1.1.).

Additional context

Differences from the Bash version to decide on:

  • The default --indent here is 2, so the Bash rule above would make
    --numbered list fail without an explicit --indent 3.
  • Entries here are indented relative to the top level of the document and to
    --start-depth. Entries skipped by --start-depth should not be numbered either.
主要语言
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 摘要。