diff --git a/render/html.c b/render/html.c
index 4c2ca52..4c1a472 100755
--- a/render/html.c
+++ b/render/html.c
@@ -278,11 +278,11 @@ rndr_header(struct buf *ob, struct buf *text, int level, void *opaque)
if (ob->size)
bufputc(ob, '\n');
- if (options->flags & HTML_TOC) {
- bufprintf(ob, "", options->toc_data.header_count++);
- }
+ if (options->flags & HTML_TOC)
+ bufprintf(ob, "", level, options->toc_data.header_count++);
+ else
+ bufprintf(ob, "", level);
- bufprintf(ob, "", level);
if (text) bufput(ob, text->data, text->size);
bufprintf(ob, "\n", level);
}