[英]Converting Carriage Return to HTML Break
I am importing an xml file of blog posts into Django. 我正在将一个博客帖子的xml文件导入Django。
Part of this process requires me to convert escaped html characters back to their html form by using replace: 此过程的一部分要求我使用replace将转义的html字符转换回其html表单:
s = s.replace("<", "<")
My problem is that the xml file, when viewed with vim, contains carriage returns in the form of "^M" -- I'd like to convert these carriage returns to break tags, but 我的问题是,当用vim查看时,xml文件包含“^ M”形式的回车 - 我想将这些回车转换为break标签,但是
s = s.replace("^M", "<br />")
does nothing. 什么也没做。
I tried converting all of these tags in the xml file with vim, but then my minidom importer breaks. 我尝试用vim在xml文件中转换所有这些标签,但随后我的minidom导入器中断了。
Any idea on how I can accomplish this conversion using replace? 有关如何使用替换完成此转换的任何想法?
Using one or both of these should work: 使用其中一个或两个应该工作:
s = s.replace("\r\n", "<br />")
s = s.replace("\n", "<br />")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.