What is the method of doing nl2br in Genshi?

ⅰ亾dé卋堺 提交于 2019-12-09 23:14:18

问题


hiyas. I using Genshi+Pylons.

please teach me, how use \n to <br/>tag in Genshi?

I hope to obtain the same result as "nl2br" in php to change line.
Or, does not the solution exist?

i'm assign template to some text.

(genshi template)
<p>${c.message}</p>

Im tried. case 1:

(python code)
c.message = """
foo
bar
"""

NG. display result is "foo bar"

case 2:

(python code)
c.message = """
foo<br />
bar

"""

NG. display result is "foo<br />bar".
displayed escaped stirings!
It was a same deal as <br/> as for <br />.

Postscript.
I want to avoid using the pre tag.

thanks.
When it is not easy to read because it is not good, I'm sorry by English.


回答1:


Try this:

<py:for each="line in message.split('\n')">${line}<br /></py:for>


来源:https://stackoverflow.com/questions/2123162/what-is-the-method-of-doing-nl2br-in-genshi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!