[ BUG ] TOC entry text keeps the HTML of links, images and formatting in a heading

未关闭 适合新手
#99 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
83/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
backend

调研方向

issue 指向 internal/utils/utils.go 和 internal/adapters/tocgrabber_re.go;先阅读 Utils.RemoveStuff 和 RegexpExtractor.Extract,然后将原始 URL 输出与预期示例进行比较。完成标准是:TOC 条目文本去除 HTML 标签,同时保留标签内部文本和现有的已渲染实体,且不更改锚点。根据 issue,blob URL 路径不受影响。

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

描述

bug

Describe the bug

For a local file, STDIN or a raw URL, the text of a TOC entry is the HTML that GitHub
renders for the heading, with only <code> removed. A heading with a link, an image,
emphasis or inline HTML gives an entry with tags in its text. The anchors are correct.
The Bash version had the same bug (ekalinin/github-markdown-toc#40,
ekalinin/github-markdown-toc#67) and fixed it in ekalinin/github-markdown-toc#185.

To Reproduce

The test file of the Bash version:

gh-md-toc --hide-header --hide-footer "https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/tests/test%20directory/test_headingmarkup.md"

Actual:

* [Top](#top)
  * [On <sub><sub><a href="\#top">Go to Top</a></sub></sub>](#on-go-to-top)
  * [<a href="https://github\.com/ekalinin/github\-markdown\-toc/issues/67">My issue</a>](#my-issue)
  * [See <a href="\#top">docs</a> here](#see-docs-here)
  * [Linux vs\. Samba <em><strong>permissions</strong></em>](#linux-vs-samba-permissions)
  * [A <a target="\_blank" rel="noopener noreferrer" href="x\.png"><img src="x\.png" alt="img" style="max\-width: 100%;"></a> B](#a--b)
  * [Tom &amp; Jerry &lt;3](#tom--jerry-3)

Expected behavior

All HTML tags are removed, the text inside them is kept, and HTML entities stay as GitHub
renders them, as in the Bash version:

* [Top](#top)
  * [On Go to Top](#on-go-to-top)
  * [My issue](#my-issue)
  * [See docs here](#see-docs-here)
  * [Linux vs\. Samba permissions](#linux-vs-samba-permissions)
  * [A  B](#a--b)
  * [Tom &amp; Jerry &lt;3](#tom--jerry-3)

Environment (please complete the following information):

  • OS: macOS (darwin/arm64)
  • Version: 2.0.1, current master (dd680f7)

Additional context

  • utils.RemoveStuff (internal/utils/utils.go) removes only <code> and </code>. It
    is applied to the heading text in RegexpExtractor.Extract
    (internal/adapters/tocgrabber_re.go).
  • The blob URL of the same file is not affected: its text comes from the JSON payload
    (JSONExtractor).
主要语言
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 摘要。