Genshin:for循环插入换行符

Genshi: for loop inserts line breaks

源代码:我有如下程序

import genshi
from genshi.template import MarkupTemplate

html = '''
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/">
        <head>
        </head>
        <body>
            <py:for each="i in range(3)">
                <py:choose>
                    <del py:when="i == 1">
                        ${i}
                    </del>
                    <py:otherwise>
                        ${i}
                    </py:otherwise>
                </py:choose>
            </py:for>
        </body>
    </html>
'''

template = MarkupTemplate(html)
stream = template.generate()
html = stream.render('html')

print(html)

预期输出: 数字连续打印,中间没有空格(最重要的是没有换行符)。

<html>
    <head>
    </head>
    <body>
            0<del>1</del>2
    </body>
</html>

实际输出: 输出如下:

<html>
    <head>
    </head>
    <body>
            0
            <del>1</del>
            2
    </body>
</html>

问题:如何消除换行符?我可以通过从最后的 HTML 中剥离它来处理前导空格,但我不知道如何摆脱换行符。我需要将 for 循环的内容显示为单个连续的 "word"(例如 012 而不是 0 \n 1 \n 2)。

我试过的:

不太理想,但我终于找到了可以接受的解决方案。诀窍是将给定标签的结束插入符放在下一行的下一个标签的开始插入符之前。

<body>
    <py:for each="i in range(3)"
        ><py:choose
            ><del py:when="i == 1">${i}</del
            ><py:otherwise>${i}</py:otherwise
        ></py:choose
    </py:for>
</body>

来源:https://css-tricks.com/fighting-the-space-between-inline-block-elements/

如果有人有更好的方法,我很想听听。