Mercurial > libervia-backend
comparison src/tools/xml_tools.py @ 1735:b2d6f3c92842
tools: expandNewLinesToXHTML replaces two or more \n instead of each ones
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 11 Dec 2015 07:54:14 +0100 |
parents | 3770d13776e8 |
children | 3739f7779f17 |
comparison
equal
deleted
inserted
replaced
1734:56fa4e7e158c | 1735:b2d6f3c92842 |
---|---|
1352 parser.parse(tmp.toXml().encode('utf-8')) | 1352 parser.parse(tmp.toXml().encode('utf-8')) |
1353 return self.result.firstChildElement() | 1353 return self.result.firstChildElement() |
1354 | 1354 |
1355 | 1355 |
1356 def expandNewLinesToXHTML(text): | 1356 def expandNewLinesToXHTML(text): |
1357 """If not present yet, add a <br /> before all \n occurences. | 1357 """Replace two or more "\n" with "\n<br />\n". |
1358 | 1358 |
1359 @param text(unicode) | 1359 @param text(unicode) |
1360 @return unicode | 1360 @return unicode |
1361 """ | 1361 """ |
1362 # if present, replace <br> (HTML), <br > and <br/> at end of line with <br /> (XHTML) | 1362 return re.sub(r"\n{2,}", "\n<br />\n", text) |
1363 return re.sub(r"<br[ ]?/?>\n", "\n", text).replace("\n", "<br />\n") | |
1364 | 1363 |
1365 | 1364 |
1366 def decapsulateDomishContent(elt): | 1365 def decapsulateDomishContent(elt): |
1367 """Return the inner content of a domish.Element. | 1366 """Return the inner content of a domish.Element. |
1368 | 1367 |