vmg / sundown

Standards compliant, fast, secure markdown processing library in C
1.99k stars 385 forks source link

Do not nest the fist list in a table of contents. #100

Closed FSX closed 12 years ago

FSX commented 12 years ago

If the first header of a document is a level three header the first list is nested two times. To prevent this an offset if set when the first header is found and after that the level is changed to (level - offset).

Example

vmg commented 12 years ago

Heh, indeed. Sorry, I misread the code. Thanks for the addition!

FSX commented 12 years ago

I spotted a bug just now! When you parse multiple documents with the same renderer instance, toc_data.level_offset is only set at the first document, because toc_data.header_count is only 0 once, at the first document.

To fix this if (options->toc_data.header_count == 0) must be changed to if (options->toc_data.current_level == 0), because toc_data.current_level is 0 at the start of each document. And toc_data.level_offset will be set to the right offset at each document.