Skip to content

fix(remote): keep page markup out of the first TOC entry - #170

Merged
ekalinin merged 2 commits into
masterfrom
fix/remote-first-heading
Sep 27, 2026
Merged

ekalinin merged 2 commits into
masterfrom
fix/remote-first-heading

Conversation

@ekalinin

Copy link
Copy Markdown
Owner

Summary

Fixes #166: for a GitHub file URL whose document starts with a heading, the first
TOC entry contained the page HTML, had a level-2 indent and linked to the repository
tree.

  • gh-md-toc: on file pages the first heading shares a line with the page markup,
    including the file tree <h2>. The heading grep started its match at that <h2>.
    The pattern now matches only <h1>..<h6> tags that carry
    class="heading-element". The same pattern works with grep -E and with
    pcregrep on OS/390.
  • tests/tests.bats: re-enabled the three commented-out remote tests, assertions
    unchanged: TOC for remote README.md, TOC for mixed README.md (remote/local),
    TOC for remote non-english chars (remote load), #6, #10.

Testing

The re-enabled tests fetch pages from github.com, so they depend on network access
and on GitHub page markup.

On GitHub file pages the first heading of a document shares a line with
the page markup, including the file tree <h2>. The heading grep started
its match at that <h2>, so the first entry got the page HTML, a level-2
indent and a link to the repository tree.

Match only <h1>..<h6> tags that carry class="heading-element", and
re-enable the remote tests that cover this case.

Fixes #166
@ekalinin
ekalinin merged commit 78ef9b3 into master Sep 27, 2026
1 check passed
@ekalinin
ekalinin deleted the fix/remote-first-heading branch September 27, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remote file: first heading is replaced with GitHub page HTML

1 participant