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

Merged
merged 1 commit into from Mar 29, 2012

Projects

None yet

2 participants

@FSX

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

@FSX FSX Do not nest the fist list in a table of contents.
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).
fa0bd49
@vmg vmg commented on the diff Mar 29, 2012
html/html.c
@@ -491,6 +491,11 @@ static inline void escape_href(struct buf *ob, const uint8_t *source, size_t len
{
struct html_renderopt *options = opaque;
+ if (options->toc_data.header_count == 0) {
+ options->toc_data.level_offset = level - 1;
@vmg
vmg Mar 29, 2012

Why are you storing the offset in the toc_data instead of using a local variable?

@FSX
FSX Mar 29, 2012

Because the offset is used to change the levels of all the headers. Not just the first one.

@vmg
Owner

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

@vmg vmg merged commit cd77aea into vmg:master Mar 29, 2012
@FSX

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment