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

Open Beginner friendly
#99 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
83/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
backend

Research direction

The issue points to internal/utils/utils.go and internal/adapters/tocgrabber_re.go; start by reading Utils.RemoveStuff and RegexpExtractor.Extract, then compare the raw URL output with the expected examples. Done means TOC entry text strips HTML tags while keeping their inner text and the existing rendered entities, without changing the anchors. The blob URL path is unaffected according to the issue.

Written by the indexing model from the issue text.

Description

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).
Dominant language
Go
Stars
525
Forks
89
Avg merge
6m
Merged PRs (30d)
1

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ekalinin/github-markdown-toc.go

All issues in ekalinin/github-markdown-toc.go

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.