Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested HTML lists start with a newline #1148

Open
lcgeneralprojects opened this issue Apr 22, 2024 · 1 comment
Open

Nested HTML lists start with a newline #1148

lcgeneralprojects opened this issue Apr 22, 2024 · 1 comment

Comments

@lcgeneralprojects
Copy link

lcgeneralprojects commented Apr 22, 2024

Describe the bug
An HTML list nested in another HTML list erroneously starts with a newline.

Minimal code
Please include some minimal Python code reproducing your issue:

from fpdf import FPDF

if __name__ == '__main__':
    pdf = FPDF()
    pdf.add_page()
    pdf.write_html(f"""<ul>
        <li>First-order list item</li>
        <li><ul>
                <li>Second-order list item</li>
                <li>Second-order list item</li>
            </ul>
        </li>
    </ul>""")
    pdf.output("test_nested_lists.pdf")

Environment
Please provide the following information:

  • Operating System: Windows
  • Python version: Python 3.12.2
  • fpdf2 version used: current version of the master branch of the remote repository (latest tag is 2.7.8)
@lcgeneralprojects lcgeneralprojects changed the title Nested lists start with a newline Nested HTML lists start with a newline Apr 23, 2024
@Lucas-C Lucas-C added the html label Apr 29, 2024
@gmischler
Copy link
Collaborator

I did some analysis here, comparing the HTML specs and the actual behaviour of some popular web browsers, and fount that:

  • By the specs, every list (including nested lists) should have a margin of 1em both above and below it.
  • Browsers vary in how they implement the top margin, but usually omit the bottom margin.
  • Our current output is quite similar to what the browsers do (implementing half the spec)
  • Indent HTML lists correctly (Issue 1073) #1170 will eliminate the top margin of nested lists, technically violating the HTML specs, but looking more balanced and reasonable then what the browsers do.

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

No branches or pull requests

3 participants