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

Asciidoc TOC stripped in 0.15 #1687

Closed
jbarrez opened this issue Dec 8, 2015 · 20 comments
Closed

Asciidoc TOC stripped in 0.15 #1687

jbarrez opened this issue Dec 8, 2015 · 20 comments
Assignees
Milestone

Comments

@jbarrez
Copy link

jbarrez commented Dec 8, 2015

See discussion thread here: https://discuss.gohugo.io/t/asciidoc-toc-stripped-in-0-15/2231

In 0.15, the TOC (table of con tent) of an asciidoc file is stripped away, while in 0.14 this wasn't the case. This is caused by this commit: b23b546. Would it be possible to make this hardcoded setting configurable?

@jbarrez
Copy link
Author

jbarrez commented Dec 8, 2015

Duplicates in a way #1685. However, that particular issue about docs.

@anthonyfok anthonyfok added the Bug label Dec 11, 2015
@anthonyfok anthonyfok added this to the v0.16 milestone Dec 11, 2015
@anthonyfok
Copy link
Member

I took a first look at the problem, and found some interesting twists.

My first question is: The table of content (TOC) is generated within <body>, not <head>, and shouldn't be stripped by --no-header-footer, which keeps everything inside the <body> intact. Then, what is going on?

It turns out that AsciiDoc does not generate the TOC statically, but rather uses JavaScript to generates the TOC on-the-fly! With the --no-header-footer option, the related JavaScript is not loaded, and

I am happy to report, however, that Asciidoctor is not affected by this issue: Asciidoctor generates the full TOC as static HTML regardless of the --no-header-footer setting. According to http://asciidoctor.org/docs/asciidoc-asciidoctor-diffs/#table-of-contents-toc:

  • Asciidoctor reifies the ToC in the header of the document instead of relying on JavaScript to create it

So, while we look at how to fix this issue #1687 in Hugo code, could you please install Asciidoctor and give it a try and see using Asciidoctor instead of AsciiDoc solves your problem? :-)

Thanks!
Anthony

@jbarrez
Copy link
Author

jbarrez commented Dec 17, 2015

Hi Anthony, thanks for digging into this.

We are using asciidoctor, however we were using 1.5.2. Switching to 1.5.3 (and Hugo 0.15), I could see the behaviour you described above: the ToC gets created in the HTML. Had to do some css changes to get it properly on the screen, but all now works as before.

Sorry for your time spent on this - I should have checked if the asciidoctor version was the problem here before thinking it was a Hugo problem.

@jbarrez jbarrez closed this as completed Dec 17, 2015
@anthonyfok anthonyfok reopened this Dec 17, 2015
@anthonyfok
Copy link
Member

Hi Joram, no need to apologize! In fact, thank you for bringing this to our attention. I would consider it (at least a partial) regression. And I didn't even know the older Asciidoctor 1.5.2 is affected too, and so is AsciiDoc (all versions), so definitely Hugo can check the program name and version too before choosing the right command-line flags. ;-)

Oh! Indeed! Asciidoctor's ToC rendering behaviour is very new. From Asciidoctor's changelog entry for 1.5.3:

Thanks again! Re-opening this issue.

Cheers,
Anthony

@ypnos
Copy link
Contributor

ypnos commented Jan 11, 2016

I would rather have .TableOfContents to work on Asciidoc files than the custom asciidoc(tor) ToC that does not fit into the theme.
Couldn't this be done by parsing the HTML output of asciidoc? It's all <h?> elements with slug ids.

@bep
Copy link
Member

bep commented Jan 11, 2016

Could be done? Sure. Will it? Probably not.

@moorereason moorereason modified the milestones: future, v0.16 May 7, 2016
@PierreR
Copy link

PierreR commented Oct 28, 2016

Does it mean there is no way to get the toc into the sidebar of the hugo learning theme for instance. That would make such combo useless.

@digitalcraftsman
Copy link
Member

digitalcraftsman commented Oct 28, 2016

A hacky workaround would be to use regular expressions. This is neither an elegant nor a performent approach but it should do the job. You can use the findRE template function to find headings. findRE returns a list of matches in a given string. The docs feature an example on how this can be done.

@PierreR
Copy link

PierreR commented Oct 28, 2016

@digitalcraftsman Thanks for the suggestion. At this point, I will probably leave it for another time hoping a fix will come soonish.

@bep
Copy link
Member

bep commented Apr 9, 2017

@anthonyfok what is the status of this? Any prospect of a fix?

@bep bep modified the milestones: future, v0.23 Jun 8, 2017
@bep
Copy link
Member

bep commented Jun 8, 2017

@anthonyfok what is the status of this? Any prospect of a fix?

@bep bep modified the milestones: v0.23, v0.24, v0.25 Jun 16, 2017
@bep bep added this to the v0.66 milestone Jan 30, 2020
@bep bep modified the milestones: v0.66, v0.67 Mar 2, 2020
@bep bep modified the milestones: v0.67, v0.68 Mar 9, 2020
@bep bep modified the milestones: v0.68, v0.69 Mar 20, 2020
npiganeau added a commit to npiganeau/hugo that referenced this issue Mar 26, 2020
Fill the .TableOfContents template variable when writing Asciidoc content.
This is done by letting Asciidoc render its TOC as HTML, then extract this
HTML rendered TOC, parse it into a tableofcontents.Root and finally remove
it from the HTML content.
This aims to stay in the logic that the Asciidoc parsing is entirely done
by the external helper.

See gohugoio#1687
@bep bep modified the milestones: v0.69, v0.70 Apr 8, 2020
@bep bep modified the milestones: v0.70, v0.71 Apr 28, 2020
npiganeau added a commit to npiganeau/hugo that referenced this issue May 16, 2020
Fill the .TableOfContents template variable when writing Asciidoc content.
This is done by letting Asciidoc render its TOC as HTML, then extract this
HTML rendered TOC, parse it into a tableofcontents.Root and finally remove
it from the HTML content.
This aims to stay in the logic that the Asciidoc parsing is entirely done
by the external helper.

See gohugoio#1687
@bep bep modified the milestones: v0.71, v0.72 May 18, 2020
@bep bep modified the milestones: v0.72, v0.73 May 31, 2020
@bep bep modified the milestones: v0.73, v0.74 Jun 23, 2020
@bep bep modified the milestones: v0.74, v0.75 Jul 13, 2020
npiganeau added a commit to npiganeau/hugo that referenced this issue Aug 24, 2020
Fill the .TableOfContents template variable when writing Asciidoc content.
This is done by letting Asciidoc render its TOC as HTML, then extract this
HTML rendered TOC, parse it into a tableofcontents.Root and finally remove
it from the HTML content.
This aims to stay in the logic that the Asciidoc parsing is entirely done
by the external helper.

See gohugoio#1687
npiganeau added a commit to npiganeau/hugo that referenced this issue Aug 30, 2020
Fill the .TableOfContents template variable when writing Asciidoc content.
This is done by letting Asciidoc render its TOC as HTML, then extract this
HTML rendered TOC, parse it into a tableofcontents.Root and finally remove
it from the HTML content.
This aims to stay in the logic that the Asciidoc parsing is entirely done
by the external helper.

See gohugoio#1687
bep pushed a commit that referenced this issue Sep 6, 2020
Fill the .TableOfContents template variable when writing Asciidoc content.
This is done by letting Asciidoc render its TOC as HTML, then extract this
HTML rendered TOC, parse it into a tableofcontents.Root and finally remove
it from the HTML content.
This aims to stay in the logic that the Asciidoc parsing is entirely done
by the external helper.

See #1687
@bep bep closed this as completed Sep 6, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.