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

Table of contents extracted from Markdown documents #69

Closed
wants to merge 6 commits into from

Conversation

mnapoli
Copy link
Member

@mnapoli mnapoli commented Dec 21, 2014

A new step extracts a table of contents from Markdown documents (list of headers) and makes it available as metadata. Uses the latest commonmark (we end up with 2 Markdown parser because this one doesn't support Markdown Extra).

With this new step, we now have this metadata available in Twig layouts:

<h1>{{ tableOfContents.title }}</h1>
<p>
    Table of contents:
</p>
{{ tableOfContents.toHtmlList() }}

API of tableOfContents:

  • title: the title of the current document (i.e. first header of level 1)
  • toHtmlList(): generates the summary as a HTML list (<ul>)

TODO:

  • Require a stable dependency in composer.json (i.e. wait for a new release of commonmark)
  • Should the metadata key be document instead of tableOfContents? (no)
  • Update to the latest CommonMark version
  • Merge master
  • The list should contain links to headers. Related to Auto-generate HTML IDs for headers #39
  • Documentation

A new step extracts a table of contents from Markdown documents (list of headers) and makes it available as file metadata.
@wysow
Copy link
Member

wysow commented Dec 25, 2014

@mnapoli seems your wish is coming true: https://github.com/thephpleague/commonmark/releases/tag/0.5.0 ;-)

@mnapoli
Copy link
Member Author

mnapoli commented Dec 25, 2014

Good!

I just noticed that the library requires mbstring, which I'm afraid will lead to conflicts later on. I've opened thephpleague/commonmark#38 to fix this.

@mnapoli mnapoli added this to the 1.1 milestone Dec 26, 2014
@mnapoli
Copy link
Member Author

mnapoli commented Dec 27, 2014

thephpleague/commonmark#38 was fixed, waiting for a new stable release to be able to use it ;)

@mnapoli mnapoli self-assigned this Dec 28, 2014
@mnapoli mnapoli modified the milestone: 1.1 Dec 28, 2014
@wysow
Copy link
Member

wysow commented Jan 5, 2015

@mnapoli seems the release of commonmark has been done right?

@mnapoli
Copy link
Member Author

mnapoli commented Jan 10, 2015

Yep cool!

I'm wondering if it's worth the effort to try and make the CommonMark parser support Markdown Extra. The thing is that it is needed to be able to link to headers, without that a table of content is kind of useless. But since CommonMark doesn't support it, it means people could end up defining IDs with Markdown Extra:

# A rapid example {#example}

But CommonMark will not parse it… The if we auto-generate title IDs from the text content (#39), here we would have a table of content linking to a-rapid-example but Parsedown would have generated an ID named example instead…

By making CommonMark support Markdown Extra, we could remove Parsedown and have a consistent behavior… It would be perfect. Still need to think about it, extending CommonMark doesn't look that easy…

@mnapoli
Copy link
Member Author

mnapoli commented Jan 19, 2015

I'm convinced now that we need Markdown Extra support in CommonMark to replace Parsedown and finish this PR.

I've opened thephpleague/commonmark#60 and hopefully I'll find some time to look into it.

@wysow
Copy link
Member

wysow commented Feb 8, 2015

@mnapoli So should we start our own extension for this?

@mnapoli
Copy link
Member Author

mnapoli commented Feb 8, 2015

@wysow yep I've tried a few times already but this is quite a challenge honestly.

Also, I had a look at https://github.com/dshafik/markua and about Markua itself and it looks quite cool! The good thing is that Markua seems to include all Markdown Extra, + a few features like the "asides" that are the just perfect for writing documentation (which makes a lot of sense since Markua has been invented for Leanpub for writing books…).

So my POV is let's use Markua instead, which would cover both Markdown and Markdown Extra. That means contributing to https://github.com/dshafik/markua to implement missing features (actually the main things we need are tables and headers IDs). If that project is not maintain anymore, we can also fork it to our organization…

What do you think? If you want to have a look into that you are most welcome, honestly I was a bit lost with the API of CommonMark…

@mnapoli
Copy link
Member Author

mnapoli commented May 31, 2016

I updated this PR. What's lacking now is linking the table of contents items to the headers (so that we can go to a header by clicking on it in the summary).

@ncarboni
Copy link

Any update of the documentation? I would love to generate a TOC based on the header in the markdown and having it appear in the default theme/readsthedoc

@mnapoli
Copy link
Member Author

mnapoli commented Apr 24, 2018

Unfortunately this PR is 2 years old and has huge changes, I might as well close it for now to avoid giving false hopes.

@mnapoli mnapoli closed this Apr 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants