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

Add new TableOfContents Page variable (Markdown only) #173

Closed
wants to merge 1 commit into from
Closed

Add new TableOfContents Page variable (Markdown only) #173

wants to merge 1 commit into from

Conversation

nwidger
Copy link
Contributor

@nwidger nwidger commented Jan 18, 2014

Added TableOfContents field to hugolib.Page struct. New function
getTableOfContents is used in convertMarkdown to set the TableOfContents
field.

Added new test file hugolib/page_toc_test.go with a simple test of the
new functionality.

Pull request for issue #153.

Added TableOfContents field to hugolib.Page struct.  New function
getTableOfContents is used in convertMarkdown to set the TableOfContents
field.

Added new test file hugolib/page_toc_test.go with a simple test of the
new functionality.
@nwidger
Copy link
Contributor Author

nwidger commented Jan 20, 2014

My only concern with the patch as it stands is that the generated TOC stored in the .TableOfContents page variable links to anchors which don't exist in the normal .Content variable since that is generated without the HTML_TOC flag. Passing HTML_TOC when generating .Content generates a TOC with working links but forces the TOC to appear at the top of the page. I don't know how important being able to customize the placement of the TOC is, but perhaps instead of adding a new page variable we could just introduce a new configuration variable that determines if HTML_TOC is passed in when generating .Content.

@spf13
Copy link
Contributor

spf13 commented Jan 20, 2014

I think best thing to do is parse the output and place it in another variable. Does that make sense?

I'll try to spend some time digging into this and understand it better.

Steve Francia
spf13.com
@spf13

On Jan 20, 2014, at 5:38 PM, nwidger notifications@github.com wrote:

My only concern with the patch as it stands is that the generated TOC stored in the .TableOfContents page variable links to anchors which don't exist in the normal .Content variable since that is generated without the HTML_TOC flag. Passing HTML_TOC when generating .Content generates a TOC with working links but forces the TOC to appear at the top of the page. I don't know how important being able to customize the placement of the TOC is, but perhaps instead of adding a new page variable we could just introduce a new configuration variable that determines if HTML_TOC is passed in when generating .Content.


Reply to this email directly or view it on GitHub.

@nwidger
Copy link
Contributor Author

nwidger commented Jan 20, 2014

Yes, that's definitely one possibility, although it'd certainly be a bit more fragile if the blackfriday package changes its output. Currently, it generates the TOC wrapped in a nav element:

<nav>
<ul>
<li>
<ul>
<li><a href="#toc_0">Blah blah blah</a></li>
<li><a href="#toc_1">Blah blah blah</a></li>
<li><a href="#toc_2">Blah blah blah</a></li>
</ul></li>
</ul>
</nav>

A simple regexp could certainly be written to rip this out of the output and store it in .TableOfContents.

@spf13
Copy link
Contributor

spf13 commented Jan 27, 2014

Working on merging this in as part of a general refactor. Should merge in shortly.

@nwidger
Copy link
Contributor Author

nwidger commented Jan 27, 2014

Awesome!

@spf13
Copy link
Contributor

spf13 commented Jan 29, 2014

Merged. If you could checkout head and play with it to give some feedback that would be appreciated.

@spf13 spf13 closed this Jan 29, 2014
@nwidger
Copy link
Contributor Author

nwidger commented Jan 29, 2014

Awesome, will do!

On Tue, Jan 28, 2014 at 11:42 PM, Steve Francia notifications@github.comwrote:

Merged. If you could checkout head and play with it to give some feedback
that would be appreciated.

Reply to this email directly or view it on GitHubhttps://github.com//pull/173#issuecomment-33556165
.

@nwidger
Copy link
Contributor Author

nwidger commented Jan 30, 2014

So the whole thing works really well, I think. My only gripe is the extra <ul> layer that the TOC gets wrapped around. Right now, the TOC winds up looking like this:

<nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#toc_0">Blah blah blah</a>
        <li><a href="#toc_1">Blah blah blah!</a></li>
        <li><a href="#toc_2">Blah blah blah</a></li>
        <li><a href="#toc_3">Blah blah blah</a></li>
        <li><a href="#toc_4">Blah blah blah</a></li>
      </ul>
  </ul>
</nav>

when really I think most people would just want:

<nav id="TableOfContents">
  <ul>
    <li><a href="#toc_0">Blah blah blah</a>
    <li><a href="#toc_1">Blah blah blah!</a></li>
    <li><a href="#toc_2">Blah blah blah</a></li>
    <li><a href="#toc_3">Blah blah blah</a></li>
    <li><a href="#toc_4">Blah blah blah</a></li>
  </ul>
</nav>

See what I mean?

@spf13
Copy link
Contributor

spf13 commented Jan 30, 2014

This is straight from BlackFriday. If you use h1 tags it uses that top UL.
I don't think we can change it.

For me the ideal would be to use whatever the largest h used as the base rather than always going off h1.
Perhaps a patch upstream would help.

Steve Francia
spf13.com
@spf13

On Jan 30, 2014, at 8:49 AM, nwidger notifications@github.com wrote:

So the whole thing works really well, I think. My only gripe is the extra

@nwidger
Copy link
Contributor Author

nwidger commented Jan 30, 2014

I thought that might be the case but didn't check the source. Thanks for adding the feature, it'll definitely come in handy for me. :)

@nwidger
Copy link
Contributor Author

nwidger commented Jan 30, 2014

Actually it appears there's been a change in the way we use blackfriday. Previously, we simply called blackfriday.MarkdownCommon, defined here:

https://github.com/russross/blackfriday/blob/0c38d23ca25d46a03814024113a488baca6b201c/markdown.go#L227

but now markdownRender calls blackfriday.Markdown, but passes different flags/extensions:

https://github.com/spf13/hugo/blob/master/hugolib/page.go#L587

I am using Markdown tables, which no longer work since we don't pass EXTENSION_TABLES into blackfriday.Markdown. I think we should change markdownRender to use the same flags/extensions as blackfriday.MarkdownCommon.

@spf13
Copy link
Contributor

spf13 commented Jan 30, 2014

Agree (mostly). We should include all the ones than enable more features, like tables. 
We should also include skip scripts which isn’t on by default but hinders our users. 

Care to make a PR?

Best,
Steve

-- 
Steve Francia
http://stevefrancia.com
http://spf13.com
http://twitter.com/spf13

From: nwidger nwidger
Reply: spf13/hugo reply@reply.github.com
Date: January 30, 2014 at 10:00:48 AM
To: spf13/hugo hugo@noreply.github.com
Subject:  Re: [hugo] Add new TableOfContents Page variable (Markdown only) (#173)
Actually it appears there's been a change in the way we use blackfriday. Previously, we simply called blackfriday.MarkdownCommon, defined here:

https://github.com/russross/blackfriday/blob/0c38d23ca25d46a03814024113a488baca6b201c/markdown.go#L227

but now markdownRender calls blackfriday.Markdown, but passes different flags/extensions:

https://github.com/spf13/hugo/blob/master/hugolib/page.go#L587

I am using Markdown tables, which no longer work since we don't pass EXTENSION_TABLES into blackfriday.Markdown. I think we should change markdownRender to use the same flags/extensions as blackfriday.MarkdownCommon.


Reply to this email directly or view it on GitHub.

@nwidger
Copy link
Contributor Author

nwidger commented Jan 30, 2014

Sure, I'll try to get to that tonight.

moorereason pushed a commit to moorereason/hugo that referenced this pull request Sep 13, 2019
Add request-id to verbose log messages
moorereason pushed a commit to moorereason/hugo that referenced this pull request Sep 13, 2019
@github-actions
Copy link

github-actions bot commented Mar 9, 2022

This pull request 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 Mar 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants