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

URL in title breaks ToC #7158

Open
thomwiggers opened this issue Apr 11, 2020 · 17 comments
Open

URL in title breaks ToC #7158

thomwiggers opened this issue Apr 11, 2020 · 17 comments
Labels
Milestone

Comments

@thomwiggers
Copy link

Steps to reproduce the behavior:

# some nice stuff ([url][])

[url]: https://google.com

in a docs page with toc=true.

What version of Hugo are you using (hugo version)?

$ hugo version
Hugo Static Site Generator v0.68.3-157669A0/extended linux/amd64 BuildDate: 2020-03-24T12:13:38Z

Result:

image

(Page source at https://github.com/thomwiggers/thomwiggers.nl/blob/new-site/content/teaching/hacking-in-c-2020/syllabus.md)

Does this issue reproduce with the latest release?

yes

(Originally reported at HugoBlox/hugo-blox-builder#1637)

@stale
Copy link

stale bot commented Aug 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Aug 9, 2020
@thomwiggers
Copy link
Author

Still happens

@stale stale bot removed the Stale label Aug 17, 2020
@stale
Copy link

stale bot commented Dec 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Dec 19, 2020
@thomwiggers
Copy link
Author

Still happens

@stale stale bot removed the Stale label Dec 19, 2020
@davidsneighbour
Copy link
Contributor

davidsneighbour commented Dec 19, 2020

Of course it still happens. It's because the concept of a "table of contents" does not support the concept of "links in headlines" because each item in a ToC is a link to a section and you can't have links within links. That is happening in other applications too.

The silence in response to your issue is because it's impossible to add a system, that changes this behaviour. HTML could be stripped from the header, but then again formatting like bold or italic would disappear too. Move the link out of your headline and please stop removing the stale label.

@thomwiggers
Copy link
Author

thomwiggers commented Dec 19, 2020

For starters, that's quite a hostile and toxic reply.

Markdown supports links in headings just fine. That should not justify the ToC HTML breaking. I'd be fine with URLs being stripped from the ToC text and there's no reason why that should not work or be incompatible with other HTML in the headers.

@github-actions
Copy link

github-actions bot commented Mar 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@github-actions github-actions bot added the Stale label Mar 8, 2022
@thomwiggers
Copy link
Author

image

Still happens

@github-actions github-actions bot removed the Stale label Mar 9, 2022
@github-actions
Copy link

github-actions bot commented Mar 9, 2023

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@github-actions github-actions bot added the Stale label Mar 9, 2023
@thomwiggers
Copy link
Author

still happens

@thomwiggers
Copy link
Author

I dug a bit in the Hugo source code, and the problem seems to be

tocHeading.Title = headingText.String()

Which just takes the arbitrary HTML content of the title, but probably should sanitize it first.

@github-actions github-actions bot removed the Stale label Mar 10, 2023
Copy link

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@github-actions github-actions bot added the Stale label Mar 10, 2024
@thomwiggers
Copy link
Author

Still happens.

@github-actions github-actions bot removed the Stale label Mar 12, 2024
@jmooring
Copy link
Member

git clone --single-branch -b hugo-github-issue-7158 https://github.com/jmooring/hugo-testing hugo-github-issue-7158
cd hugo-github-issue-7158
hugo server

@jmooring jmooring added the Bug label Apr 29, 2024
@thomwiggers
Copy link
Author

For reference, @jmooring's POC shows the following:

image

@jmooring
Copy link
Member

jmooring commented Apr 29, 2024

@thomwiggers This is not a cheap problem to solve. We'd need to parse the heading and walk the HTML nodes, using something like net/html, and remove all anchor elements but keep their inner HTML. Stripping all HTML tags is obviously not an option (e.g., markdown might be ## My _emphasized_ heading).

Having said that, GitHub's automatic TOC for README files handles this case just fine. GitHub's automatic TOC for README file simplifies the problem by stripping all HTML tags, which is not an acceptable approach.

@thomwiggers
Copy link
Author

Yeah, that makes sense, especially as doing it on the presumably-already-parsed Markdown level will probably not be sufficient (e.g. ## <a href="stuff">test</a>)

@bep bep added this to the v0.126.0 milestone Apr 30, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants