Better plain text to html conversion

Replace \n and space characters instead of just wrapping the whole text
in pre and having to set a css style
This commit is contained in:
miruka 2019-08-17 15:05:05 -04:00
parent 5e63331f8b
commit ec17e36911

View File

@ -43,4 +43,7 @@ def guess_mime(file: IO) -> Optional[str]:
def plain2html(text: str) -> str:
return "<pre>%s</pre>" % html.escape(text)
return html.escape(text)\
.replace(" ", "&nbsp;")\
.replace("\n", "<br>")\
.replace("\t", "&nbsp;" * 4)