Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Can I make Markdown headings automatically numbered, instead of just replacing the '#+' with an icon?" #479

Unanswered
lsw9521 asked this question in Q&A
Discussion options

Just like turning

Heading 1......

Heading 1 1......

Heading 2......

Heading 2 1......

Heading 2 1 1......

Heading 2 1 2......

Heading 2 2......

Heading 2 2 1......

into the following format

1 Heading 1......
1.1 Heading 1 1......
2 Heading 2......
2.1 Heading 2 1......
2.1.1 Heading 2 1 1......
2.1.2 Heading 2 1 2......
2.2 Heading 2 2......
2.2.1 Heading 2 2 1......

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Yes, you can. The heading.icons value can be defined as a function that returns a string, that returned value is what we'll render for the icon. In that function you have access to a sections property which is a list of integers indicating that index information.

Based on your example here's what you would do:

require('render-markdown').setup({
 heading = {
 icons = function(ctx)
 return table.concat(ctx.sections, '.') .. ' '
 end,
 },
})

You're free to change this however you feel, maybe adding an icon in some cases, changing how the values are joined together, changing the suffix, it's all completely up to you.

You must be logged in to vote
1 reply
Comment options

Thank you so much! It works perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /