vmg / sundown

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

TOC is not rendered correctly #18

Closed FSX closed 13 years ago

FSX commented 13 years ago

When I have the following text:

Testing the **table of contents** functionality.

## A Level Two Header

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

### A Leven Three Header

Quisque ultricies purus ut diam scelerisque nec scelerisque arcu fringilla.

#### A Leven Four Header

Praesent consequat erat vel massa lobortis facilisis.

### Another Level Three Header

Proin ut lorem a mi hendrerit ultricies.

## A Second Level Two Header

Vestibulum sollicitudin, arcu in adipiscing suscipit, dolor sem hendrerit mauris,
convallis aliquam velit felis sed mauris.

#### Another Level Four Header

Suspendisse potenti. Proin semper pellentesque porta.

### A Third Level Three Header

Suspendisse potenti. Maecenas et lacus quis justo vulputate ornare.

The following TOC is generated:

<li>
    <ul>
        <li><a href="#toc_0">A Level Two Header</a></li>
        <li>
            <ul>
                <li><a href="#toc_1">A Leven Three Header</a></li>
                <li>
                    <ul>
                        <li><a href="#toc_2">A Leven Four Header</a></li>
                    </ul>
                </li>
                <li><a href="#toc_3">Another Level Three Header</a></li>
            </ul>
        </li>
        <li><a href="#toc_4">A Second Level Two Header</a></li>
        <li>
            <ul>
                <li><a href="#toc_5">Another Level Four Header</a></li>
            </ul>
        </li>
        <li><a href="#toc_6">A Third Level Three Header</a></li>
    </ul>
</li>
</ul></li>
</ul>

When I add level 1 header at the top of the text this is generated:

<ul>
    <li><a href="#toc_0">A Level One Header</a></li>
    <li>
        <ul>
            <li><a href="#toc_1">A Level Two Header</a></li>
            <li>
                <ul>
                    <li><a href="#toc_2">A Leven Three Header</a></li>
                    <li>
                        <ul>
                            <li><a href="#toc_3">A Leven Four Header</a></li>
                        </ul>
                    </li>
                    <li><a href="#toc_4">Another Level Three Header</a></li>
                </ul>
            </li>
            <li><a href="#toc_5">A Second Level Two Header</a></li>
            <li>
                <ul>
                    <li><a href="#toc_6">Another Level Four Header</a></li>
                </ul>
            </li>
            <li><a href="#toc_7">A Third Level Three Header</a></li>
        </ul>
    </li>
</ul></li>
</ul>

There seems to be problems when a level 1 header is missing. And the </li></ul> should not be there.

And the anchors to the headers are like: <a name="toc_0"></a><h2>A Level Two Header</h2>. Isn't better to use something like this: <h2 id="toc_0">A Level Two Header</h2>?

vmg commented 13 years ago

Hey, sorry for the delay. I've just fixed this with a patch from Bruno Michel. Thanks for reporting!