-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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 #334
Comments
I'm currently writing something like that for a project using a custom renderer that automatically populates an array of headlines (cf. Readme). |
@killercup can u share some more specific code? |
Sure. var marked = require('marked');
var renderer = new marked.Renderer();
var toc = []; // your table of contents as a list.
renderer.heading = function(text, level) {
var slug = text.toLowerCase().replace(/[^\w]+/g, '-');
toc.push({
level: level,
slug: slug,
title: text
});
return "<h" + level + " id=\"" + slug + "\"><a href=\"#" + slug + "\" class=\"anchor\"></a>" + text + "</h" + level + ">";
};
var convertMarkdown = function(text) {
return marked(text, {
renderer: renderer
});
}; For a complete implementation see here. This populates the |
@killercup you rock |
Note that some Markdown implementations/variants support this. Python-markdown comes to mind: However, it’s not common or standardized (sadly, there is basically no such thing as a Markdown standard). (also… +1) |
Not sure this is in keeping with the specifications being targeted. See #956 |
Would be nice to generate a table of contents from a markdown file, like http://pythonhosted.org/Markdown/extensions/toc.html
something like:
The text was updated successfully, but these errors were encountered: