How to fix HTML email numbered list causing tabs after list exceeds 99?

Viewed 182

I have a Python script that uses smtplib, email.mime.multipart, and email.mime.text to send an email with a numbered list. After the list exceeds 99 it inserts tabs after the number and messes up the formatting.

The only thing that has worked so far has been inserting a line break after each number to keep formatting consistent, but it doesn't look as good.

for i in range(0:200):
    body_row = '<li>First line here <br>Second line here</li>'
    body_total += body_row
body_total = "Total List" + "<ol>" + body_total + "</ol>" + "<br>"

The output looks like this:

99. First line here
    Second line here
100.    First line here
    Second line here
101.    First line here
    Second line here

Does anyone know of an easy way to fix this other than my line break solution?

2 Answers

Your question has little do with Python programming, as it is primarily about how to format something in HTML.

I think the answer is to use the HTML <ol> ordered list tag, which will do what you want (and you don't have to explicitly number the elements yourself).

<ol>
    <li>
        First line here<br />
        Second line here
    </li>
    <li>
        First line here<br />
        Second line here
    </li>
    <li>
        First line here<br />
        Second line here
    </li>
    <li>
        First line here<br />
        Second line here
    </li>
       .
       .
       .
</ol>

Result rendered by a web browser:

screenshot of result rendered by a web browser

An alternative way. My first attempt at python so go easy on me with this one.

print """<table width="100%" border="0" cellspacing="0" cellpadding="0">  
    <tbody>"""
for x in range(0, 200):
    rowData = """        <tr>
        <td> %d</td> 
        <td>first line<br> second line</td> 
    </tr>""" % (x)
    print rowData

print """    </tbody> 
</table>"""

I used print to see how my table structure is, you can change these to variables. The structure above will ensure your numbers are right on all email clients and the columns will be the same across all as well. Below is a screenshot of how the output will look.

enter image description here

Related