marianoguerra / rst2html5

transform restructuredtext documents to html5 + twitter's bootstrap css, deck.js or reveal.js
http://marianoguerra.github.com/rst2html5
MIT License
177 stars 51 forks source link

fix placement of <span> tags for additional ids #39

Closed ntamas closed 10 years ago

ntamas commented 11 years ago

rst2html5 places <span> tags containing additional IDs for a section incorrectly (after the closing </section> tag instead of right at the beginning of the <section>). Also, rst2html5 creates unnecessary empty <span> tags after inline internal references. This patch fixes both issues.

To reproduce the issues, try filtering the following document through an unpatched rst2html5:

.. _foo:

First section
-------------

Second section
--------------

Third section
-------------

`This link`_ should lead back to the first section but leads to the second
section instead using ``rst2html5``. It works as expected using ``rst2html``.

.. _This link: foo_

rst2html5 produces the following HTML output (irrelevant parts omitted):

<span class="target"></span>
<section id="first-section">
    <header><h2>First section</h2></header>
</section>
<span id="foo"></span>
<section id="second-section">
    <header><h2>Second section</h2></header>
</section>
<section id="third-section">
    <header><h2>Third section</h2></header>
    <p>
        <a class="reference internal" href="#foo">This link</a> should lead back to the first section but leads to the second section instead using <code>rst2html5</code>. It works as expected using <code>rst2html</code>.
    </p>
    <span class="target" id="this-link"></span>
</section>

Note the misplaced <span id="foo"> which appears before the second section and not before the first one. Also note the extra <span class="target"> tags.

After patching rst2html5 according to this pull request, the following (correct) output is produced:

<section id="first-section">
    <span id="foo"></span>
    <header><h2>First section</h2></header>
</section>

<section id="second-section">
    <header><h2>Second section</h2></header>
</section>

<section id="third-section">
    <header><h2>Third section</h2></header>
    <p>
        <a class="reference internal" href="#foo">This link</a> should lead back to the first section but leads to the second section instead using <code>rst2html5</code>. It works as expected using <code>rst2html</code>.
    </p>
</section>
marianoguerra commented 10 years ago

thanks! sorry for taking so long I didn't get a notification or I missed it

thanks for contributing!