Repository navigation
fix(toc): link TOC entries to the heading anchor and strip heading tags - #185
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #40, fixes #67: a heading that contains a link gets a TOC entry that links to the
wrong place, and its text keeps the raw HTML that GitHub renders for the heading.
## On <sub><sub>[Go to Top](#top)</sub></sub>* [On <sub><sub><a href="#top">Go to Top</a></sub></sub>](#top)* [On Go to Top](#on-go-to-top)## [My issue](https://github.com/ekalinin/github-markdown-toc/issues/67)* [<a href="https://...">My issue</a>](https://github.com/ekalinin/github-markdown-toc/issues/67)* [My issue](#my-issue)## See [docs](#top) here* [See <a href="#top">docs</a> here](#top)* [See docs here](#see-docs-here)## A  B* [A <a ...><img ...></a> B](x.png)* [A B](#a--b)## Linux vs. Samba ***permissions**** [Linux vs. Samba <em><strong>permissions</strong></em>](#linux-vs-samba-permissions)* [Linux vs. Samba permissions](#linux-vs-samba-permissions)gh-md-toc(gh_toc_grab):hrefof the heading line, so a link in the heading text camebefore the heading's own anchor.
href_regexnow matches the anchor element(
class="anchor"), andhrefis taken from it, in both awk branches (default andOS/390).
common_awk_script; the textinside them is kept. HTML entities stay as GitHub renders them
(
Tom & Jerry <3). It is done ontextin awk, not withsedover the line,which would also remove the anchor element.
expressions.
tests/tests.bats: a new test on a new fixturetest_headingmarkup.md. The Repairing setext heading support, certain uses of backticks after GitHub API format changes #145 testnow expects
* [Title two](#title-two)instead of* [<em>Title two</em>](#title-two),and the same line is updated in the TOC of
test_setextwithformatting.md, because thattest runs with
--hide-footer(--insert) and rewrites the fixture.openspec: thefix-heading-markupchange (proposal, design, specs, tasks), notarchived yet.
Output change: entries of headings with inline formatting or inline HTML (
*em*,**strong**,<sub>, links, images) lose the tags, so a TOC that--insertput intosuch a file changes on the next run. Entries of headings without tags do not change.
Not included: decoding HTML entities, collapsing the spaces left by a removed element
(
A B, as in GitHub's ownaria-label), keeping backticks in entries (#153), theseparate OS/390 text regex.
Testing
it (macOS, BSD awk and sed).
README.md, every other fixture and the four remote pages from theremote-tocspec is byte-for-byte the same as with the script frommaster.make lintpasses.