Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOC generator seems to get confused by anchors with the same name #39

Closed
sdondley opened this issue Feb 1, 2022 · 21 comments
Closed

TOC generator seems to get confused by anchors with the same name #39

sdondley opened this issue Feb 1, 2022 · 21 comments

Comments

@sdondley
Copy link

sdondley commented Feb 1, 2022

See vimwiki/vimwiki#1205

@patrickdavey
Copy link
Owner

I don't think I'm doing anything particular with the TOC generator. How are you actually calling the TOC Generator in vimwiki?

What is your expected output?.

looking at your html

# On This Page

- [Decoding the Gurus](#decoding-the-gurus)
- [Links](#links)                                                                         # THIS WORKS
- [What is it?](#what-is-it)
- [Hosts](#hosts)
    - [Matt Browne](#matt-browne)
        - [Links](#links-2)                                                              # THIS GOES TO WRONG "LINKS"
    - [Chris Kavnaugh](#chris-kavnaugh)
        - [Links](#links-3)                                                              # THIS GOES NOWHERE
- [What do they talk about?](#what-do-they-talk-about)
        - [Highlights of Show](#highlights-of-show)

# Decoding the Gurus

# Links

[Podcast home page](https://decoding-the-gurus.captivate.fm)
[Reddit page](https://www.reddit.com/r/DecodingTheGurus/)
[Unofficial Discord Server](https://discord.gg/z3krx3CX)


# What is it?
* It's primarily a podcast
* Started in late 2020

# Hosts
* Hosts are two researcher working in academia as professors

## Matt Browne
* psychologist
    * currently specializing in research about gambling addictions and public policy 

### Links
* [Twitter](https://twitter.com/arthurcdent)

## Chris Kavnaugh
* cultural anthropologist 
    * researches ritualistic practices

### Links
* [Twitter](https://twitter.com/C_Kavanagh)

# What do they talk about?
* Analyze popular figures in media who have acquired large followings with their sweeping worldviews
    * hosts refer to them as gurus 
    * Mostly cover controversial individuals who promulgate psuedoscience and misinformation 
    * Will occasionally cover individuals who have positive impac5
        * Carl Sagan 
    * Also sometimes interview experts on specific topics
* Frequent targets
    * Sam Harris
    * Bret Weinstein
    * Jordan Peterson
    * Joe Rogan
    * Eric Weinstein
* Help audience members identify fake experts and false arguments and generally improve their ability to think critically about information

### Highlights of Show
* interview with Sam Harris
    * Came on the rebut Chris and Matt 

...more soon

If you create that page and do view source and look carefully at the ids created for your duplicate "links" headings, you'll note they are called

             <h1>
<a id="on-this-page" class="anchor" href="#on-this-page" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>On This Page</h1>
<ul>
<li><a href="#decoding-the-gurus">Decoding the Gurus</a></li>
<li>
<a href="#links">Links</a>                                                                         # THIS WORKS</li>
<li><a href="#what-is-it">What is it?</a></li>
<li>
<a href="#hosts">Hosts</a>
<ul>
<li>
<a href="#matt-browne">Matt Browne</a>
<ul>
<li>
<a href="#links-2">Links</a>                                                              # THIS GOES TO WRONG "LINKS"</li>
</ul>
</li>
<li>
<a href="#chris-kavnaugh">Chris Kavnaugh</a>
<ul>
<li>
<a href="#links-3">Links</a>                                                              # THIS GOES NOWHERE</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#what-do-they-talk-about">What do they talk about?</a>
- <a href="#highlights-of-show">Highlights of Show</a>
</li>
</ul>
<h1>
<a id="decoding-the-gurus" class="anchor" href="#decoding-the-gurus" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Decoding the Gurus</h1>
<h1>
<a id="links" class="anchor" href="#links" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Links</h1>
<p><a href="https://decoding-the-gurus.captivate.fm">Podcast home page</a>
<a href="https://www.reddit.com/r/DecodingTheGurus/">Reddit page</a>
<a href="https://discord.gg/z3krx3CX">Unofficial Discord Server</a></p>
<h1>
<a id="what-is-it" class="anchor" href="#what-is-it" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>What is it?</h1>
<ul>
<li>It's primarily a podcast</li>
<li>Started in late 2020</li>
</ul>
<h1>
<a id="hosts" class="anchor" href="#hosts" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Hosts</h1>
<ul>
<li>Hosts are two researcher working in academia as professors</li>
</ul>
<h2>
<a id="matt-browne" class="anchor" href="#matt-browne" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Matt Browne</h2>
<ul>
<li>psychologist
<ul>
<li>currently specializing in research about gambling addictions and public policy</li>
</ul>
</li>
</ul>
<h3>
<a id="links-1" class="anchor" href="#links-1" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Links</h3>
<ul>
<li><a href="https://twitter.com/arthurcdent">Twitter</a></li>
</ul>
<h2>
<a id="chris-kavnaugh" class="anchor" href="#chris-kavnaugh" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Chris Kavnaugh</h2>
<ul>
<li>cultural anthropologist
<ul>
<li>researches ritualistic practices</li>
</ul>
</li>
</ul>
<h3>
<a id="links-2" class="anchor" href="#links-2" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Links</h3>
<ul>
<li><a href="https://twitter.com/C_Kavanagh">Twitter</a></li>
</ul>
<h1>
<a id="what-do-they-talk-about" class="anchor" href="#what-do-they-talk-about" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>What do they talk about?</h1>
<ul>
<li>Analyze popular figures in media who have acquired large followings with their sweeping worldviews
<ul>
<li>hosts refer to them as gurus</li>
<li>Mostly cover controversial individuals who promulgate psuedoscience and misinformation</li>
<li>Will occasionally cover individuals who have positive impac5
<ul>
<li>Carl Sagan</li>
</ul>
</li>
<li>Also sometimes interview experts on specific topics</li>
</ul>
</li>
<li>Frequent targets
<ul>
<li>Sam Harris</li>
<li>Bret Weinstein</li>
<li>Jordan Peterson</li>
<li>Joe Rogan</li>
<li>Eric Weinstein</li>
</ul>
</li>
<li>Help audience members identify fake experts and false arguments and generally improve their ability to think critically about information</li>
</ul>
<h3>
<a id="highlights-of-show" class="anchor" href="#highlights-of-show" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Highlights of Show</h3>
<ul>
<li>interview with Sam Harris
<ul>
<li>Came on the rebut Chris and Matt</li>
</ul>
</li>
</ul>
<p>...more soon</p>

It seems github markdown is smart enough to realise that you have two identically named link sections, but, it renames them links links-1 and links-2 not links, links-2 links-3 which is what you have.

Also, you will find that you don't really notice it linking properly even if you do correct it, because your page is too short (so it can't actually scroll the header to the top of the page anyway)

As far as I can tell there is no bug here, so I am closing this, I suggest you close the one on vimwiki/vimwiki#1205 too. Also, it's probably better practice to use uniquely named headings on your page, that would also make this entire issue moot.

@patrickdavey
Copy link
Owner

To be clear, rewrite your markdown file as this -> and I think you'll find it's working correctly

# On This Page

- [Decoding the Gurus](#decoding-the-gurus)
- [Links](#links)                                                                         # THIS WORKS
- [What is it?](#what-is-it)
- [Hosts](#hosts)
    - [Matt Browne](#matt-browne)
        - [Links](#links-1)                                                              # THIS GOES TO WRONG "LINKS"
    - [Chris Kavnaugh](#chris-kavnaugh)
        - [Links](#links-2)                                                              # THIS GOES NOWHERE
- [What do they talk about?](#what-do-they-talk-about)
        - [Highlights of Show](#highlights-of-show)

# Decoding the Gurus

# Links

[Podcast home page](https://decoding-the-gurus.captivate.fm)
[Reddit page](https://www.reddit.com/r/DecodingTheGurus/)
[Unofficial Discord Server](https://discord.gg/z3krx3CX)


# What is it?
* It's primarily a podcast
* Started in late 2020

# Hosts
* Hosts are two researcher working in academia as professors

## Matt Browne
* psychologist
    * currently specializing in research about gambling addictions and public policy 

### Links
* [Twitter](https://twitter.com/arthurcdent)

## Chris Kavnaugh
* cultural anthropologist 
    * researches ritualistic practices

### Links
* [Twitter](https://twitter.com/C_Kavanagh)

# What do they talk about?
* Analyze popular figures in media who have acquired large followings with their sweeping worldviews
    * hosts refer to them as gurus 
    * Mostly cover controversial individuals who promulgate psuedoscience and misinformation 
    * Will occasionally cover individuals who have positive impac5
        * Carl Sagan 
    * Also sometimes interview experts on specific topics
* Frequent targets
    * Sam Harris
    * Bret Weinstein
    * Jordan Peterson
    * Joe Rogan
    * Eric Weinstein
* Help audience members identify fake experts and false arguments and generally improve their ability to think critically about information

### Highlights of Show
* interview with Sam Harris
    * Came on the rebut Chris and Matt 

...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon

@sdondley
Copy link
Author

sdondley commented Feb 2, 2022

Yeah, I'm using Vimwiki TOC. Not sure which end the bug is on, the TOC generator or your module.

@patrickdavey
Copy link
Owner

Please copy the markdown in this comment #39 (comment) into your wiki and see if it works then.

As far as I can tell, the issue is with how you wrote your markdown not with vimwiki or vimwiki_markdown.

@sdondley
Copy link
Author

sdondley commented Mar 6, 2022

Your suggestion did not work.

  1. I pasted it in the markdown and removed the table of contents.
  2. Regenerated with :VimwikiTOC
  3. All the links work in vim
  4. Did ;whh to generate the html and open in browser
  5. Link still broken.

@sdondley
Copy link
Author

sdondley commented Mar 6, 2022

Output page is here: https://climatechangechat.com/decoding-the-gurus.html

@patrickdavey
Copy link
Owner

Ah, possibly :VimwikiTOC isn't well supported. Certainly this gem just converts markdown to html. What happens if you just use the markdown in #39 (comment) and just run :VimwikiToHTML as "normal" ?

@sdondley
Copy link
Author

sdondley commented Mar 6, 2022

Same problem. TOC id does not match body:

TOC HTML:

<li>
<a href="#chris-kavnaugh">Chris Kavnaugh</a>
<ul>
<li><a href="#links-3">Links</a></li>
</ul>

Corresponding HTML content:

<a id="links-2" class="anchor" href="#links-2" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Links</h3>
<ul>
<li><a href="https://twitter.com/C_Kavanagh">Twitter</a></li>
</ul>

@sdondley
Copy link
Author

sdondley commented Mar 6, 2022

And the links work perfectly fine in the markdown file in vim.

@patrickdavey
Copy link
Owner

? You're trying something different. I'm asking, if you take this markdown

# On This Page

- [Decoding the Gurus](#decoding-the-gurus)
- [Links](#links)                                                                         # THIS WORKS
- [What is it?](#what-is-it)
- [Hosts](#hosts)
    - [Matt Browne](#matt-browne)
        - [Links](#links-1)                                                              # THIS GOES TO WRONG "LINKS"
    - [Chris Kavnaugh](#chris-kavnaugh)
        - [Links](#links-2)                                                              # THIS GOES NOWHERE
- [What do they talk about?](#what-do-they-talk-about)
        - [Highlights of Show](#highlights-of-show)

# Decoding the Gurus

# Links

[Podcast home page](https://decoding-the-gurus.captivate.fm)
[Reddit page](https://www.reddit.com/r/DecodingTheGurus/)
[Unofficial Discord Server](https://discord.gg/z3krx3CX)


# What is it?
* It's primarily a podcast
* Started in late 2020

# Hosts
* Hosts are two researcher working in academia as professors

## Matt Browne
* psychologist
    * currently specializing in research about gambling addictions and public policy 

### Links
* [Twitter](https://twitter.com/arthurcdent)

## Chris Kavnaugh
* cultural anthropologist 
    * researches ritualistic practices

### Links
* [Twitter](https://twitter.com/C_Kavanagh)

# What do they talk about?
* Analyze popular figures in media who have acquired large followings with their sweeping worldviews
    * hosts refer to them as gurus 
    * Mostly cover controversial individuals who promulgate psuedoscience and misinformation 
    * Will occasionally cover individuals who have positive impac5
        * Carl Sagan 
    * Also sometimes interview experts on specific topics
* Frequent targets
    * Sam Harris
    * Bret Weinstein
    * Jordan Peterson
    * Joe Rogan
    * Eric Weinstein
* Help audience members identify fake experts and false arguments and generally improve their ability to think critically about information

### Highlights of Show
* interview with Sam Harris
    * Came on the rebut Chris and Matt 

...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon
...more soon

And then run :VimwikiToHtml it should do the correct thing.

Your example here: #39 (comment) cannot be correct, as, for example you have a twitter link which is nowhere in the source markdown, so, you have to be doing something different.

@sdondley
Copy link
Author

sdondley commented Mar 6, 2022

Why the fuck would I do that? I want to be able to use the automatically generated TOC feature. Of course I can manually write links that work as a workaround. That's not the point.

The original markdown does have a twitter link. It's there:

### Links
* [Twitter](https://twitter.com/C_Kavanagh)

@patrickdavey
Copy link
Owner

Hi Steve,

I understand this is frustrating, but, please try to stay civil. I hadn't properly understood that you were using the VimwikiTOC functionality (I don't use it myself, and you hadn't specified it in your list of steps - probably because it should have been obvious to me :)

It does seem like vimwiki is trying to correctly output the TOC links (it's great that it works with markdown at all!), and it does look like it's the github markdown conversion which is putting in slightly different ids which is the source of the issue. Unfortunately I don't have easy control over that github markdown->html conversion, and how the ids are generated.

In the short term, I can't think of an easy fix here, other than your suggested "name the headings differently", which isn't ideal.

@sdondley
Copy link
Author

sdondley commented Mar 6, 2022

The links are automatically generated by the TOC generator. So I'd have to go back and fix it every time I saved. So I'll just basically live with the broken feature. I will find a way to carry on through life, somehow.

And generally, if someone points out a problem to me which they have documented well and completely, I don't throw it back in their face with a "you do it." I try it out and see if I can reproduce. So sorry for the frustration, but you didn't seem to want to believe me that something is broken. Not all users are clueless idiots. Most are, but you should give be willing to the benefit of the doubt.

@patrickdavey
Copy link
Owner

Yip fair enough. I had actually tried to reproduce your issue (copying and pasting your HTML). The crucial piece of info which was missing (and obvious in retrospect) was that you were using VimwikiTOC to produce the table of contents. I don't use that function, so, it wasn't obvious. Once I'd worked out that was the issue then yes, I did take your sample markdown and try it.

If you can look at the vimwiki code, you might be able to tweak their TOC function to output different IDs for duplicates?

@sdondley
Copy link
Author

sdondley commented Mar 6, 2022

I think the next best thing to try is to see if it will convert using plain old wiki syntax (not use markdown) which is what vimwiki is advertised as working with.

Looking at your code, I noticed a "TableOfContentsFilter" which indicates that the underlying ruby gems may be the culprit. I don't do Ruby, though.

@patrickdavey
Copy link
Owner

Yip, that just adds the ids to the headings. However, that code is quite readable https://github.com/gjtorikian/html-pipeline/blob/main/lib/html/pipeline/toc_filter.rb and you can see where the offset is set https://github.com/gjtorikian/html-pipeline/blob/main/lib/html/pipeline/toc_filter.rb#L47. Possibly just tweaking that code would allow matching the vimwiki TOC generation (as, correct me if I'm wrong, it's "just" the offsets which are incorrect?)

I'll see if I can find some time in the next few evenings to experiment.

@sdondley
Copy link
Author

sdondley commented Mar 7, 2022

I'm not sure if it's the offsets. If I recall correctly, if I put one of the links with the same name at a different level in the outline hierarchy, it works fine. My memory is fuzzy on that, though.

@patrickdavey
Copy link
Owner

I have published version 0.8.1 which should fix this issue.

@sdondley
Copy link
Author

sdondley commented Mar 7, 2022

Nice! I'll give it a spin tomorrow.

So out of curiosity, was the TOC filter gem just not compatible with how vimwiki numbered the links?

@patrickdavey
Copy link
Owner

a653d21 commit message has it all :)

@sdondley
Copy link
Author

sdondley commented Mar 7, 2022

It works! Time to get to bed on a high note. Later. Thanks for this module.

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

No branches or pull requests

2 participants