Mercurial > kallithea
changeset 6183:4e2e6371f79a
helpers: in urlify_text, use <br> for newlines in pre-formatted text so it can be cut'n'pasted correctly
Before, when copying the preformatted nice looking ASCII-artsy text in a PR or
changeset description from a browser to a text editor, it would be pasted as
text without newline. Simply put, copy/paste ignores that it is inside a <pre>
/ white-space:pre-wrap section.
Instead, translate newlines to <br> which always translates to a newline when
pasted.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 06 Sep 2016 00:51:18 +0200 |
parents | 6944df7de4e1 |
children | ca830f9d01a8 |
files | kallithea/lib/helpers.py kallithea/tests/functional/test_files.py kallithea/tests/models/test_dump_html_mails.ref.html kallithea/tests/other/test_libs.py |
diffstat | 4 files changed, 26 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/helpers.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/lib/helpers.py Tue Sep 06 00:51:18 2016 +0200 @@ -1302,6 +1302,7 @@ if repo_name is not None: s = urlify_issues(s, repo_name, link_) s = MENTIONS_REGEX.sub(_mentions_replace, s) + s = s.replace('\r\n', '<br/>').replace('\n', '<br/>') return literal(s)
--- a/kallithea/tests/functional/test_files.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/tests/functional/test_files.py Tue Sep 06 00:51:18 2016 +0200 @@ -99,11 +99,11 @@ revision='8911406ad776fdd3d0b9932a2e89677e57405a48', f_path='vcs/nodes.py')) - response.mustcontain("""<div class="commit">Partially implemented <a class="issue-tracker-link" href="https://issues.example.com/vcs_test_hg/issue/16">#16</a>. filecontent/commit message/author/node name are safe_unicode now. -In addition some other __str__ are unicode as well -Added test for unicode -Improved test to clone into uniq repository. -removed extra unicode conversion in diff.</div> + response.mustcontain("""<div class="commit">Partially implemented <a class="issue-tracker-link" href="https://issues.example.com/vcs_test_hg/issue/16">#16</a>. filecontent/commit message/author/node name are safe_unicode now.<br/>""" +"""In addition some other __str__ are unicode as well<br/>""" +"""Added test for unicode<br/>""" +"""Improved test to clone into uniq repository.<br/>""" +"""removed extra unicode conversion in diff.</div> """) response.mustcontain("""<option selected="selected" value="8911406ad776fdd3d0b9932a2e89677e57405a48">default at 8911406ad776</option>""")
--- a/kallithea/tests/models/test_dump_html_mails.ref.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/tests/models/test_dump_html_mails.ref.html Tue Sep 06 00:51:18 2016 +0200 @@ -94,9 +94,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment. - - - and here it ends indented.</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.<br/><br/> - and here it ends indented.</div></div> </td> <td width="20px"></td> </tr> @@ -253,9 +251,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment. - - - and here it ends indented.</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.<br/><br/> - and here it ends indented.</div></div> </td> <td width="20px"></td> </tr> @@ -430,9 +426,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment. - - - and here it ends indented.</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.<br/><br/> - and here it ends indented.</div></div> </td> <td width="20px"></td> </tr> @@ -607,9 +601,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment. - - - and here it ends indented.</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.<br/><br/> - and here it ends indented.</div></div> </td> <td width="20px"></td> </tr> @@ -728,8 +720,7 @@ <td> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tr> - <td style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the body of the test message - - nothing interesting here except indentation.</div></td> + <td style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the body of the test message<br/> - nothing interesting here except indentation.</div></td> </tr> </table> </td> @@ -986,8 +977,7 @@ <tr><td height="10px"></td></tr> <tr> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap;color:#395fa0"><div class="formatted-fixed">This PR is awesome because it does stuff - - please approve indented!</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap;color:#395fa0"><div class="formatted-fixed">This PR is awesome because it does stuff<br/> - please approve indented!</div></div> </td> </tr> <tr><td height="15px"></td></tr> @@ -1160,8 +1150,7 @@ <tr><td height="10px"></td></tr> <tr> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap;color:#395fa0"><div class="formatted-fixed">This PR is awesome because it does stuff - - please approve indented!</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap;color:#395fa0"><div class="formatted-fixed">This PR is awesome because it does stuff<br/> - please approve indented!</div></div> </td> </tr> <tr><td height="15px"></td></tr> @@ -1317,9 +1306,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too! - - - and indented on second line</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div> </td> <td width="20px"></td> </tr> @@ -1482,9 +1469,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too! - - - and indented on second line</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div> </td> <td width="20px"></td> </tr> @@ -1665,9 +1650,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too! - - - and indented on second line</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div> </td> <td width="20px"></td> </tr> @@ -1848,9 +1831,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too! - - - and indented on second line</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div> </td> <td width="20px"></td> </tr> @@ -2030,9 +2011,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too! - - - and indented on second line</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div> </td> <td width="20px"></td> </tr> @@ -2212,9 +2191,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too! - - - and indented on second line</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div> </td> <td width="20px"></td> </tr> @@ -2400,9 +2377,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too! - - - and indented on second line</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div> </td> <td width="20px"></td> </tr> @@ -2588,9 +2563,7 @@ <tr> <td width="20px"></td> <td> - <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too! - - - and indented on second line</div></div> + <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div> </td> <td width="20px"></td> </tr>
--- a/kallithea/tests/other/test_libs.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/tests/other/test_libs.py Tue Sep 06 00:51:18 2016 +0200 @@ -308,9 +308,9 @@ some text 123123123123 sometimes ! """, - """Multi line\n""" - """ url[123123123123]\n""" - """ some text url[123123123123]\n""" + """Multi line<br/>""" + """ url[123123123123]<br/>""" + """ some text url[123123123123]<br/>""" """ sometimes !"""), ]) def test_urlify_changesets(self, sample, expected): @@ -342,8 +342,8 @@ ("""Multi line https://foo.bar.example.com some text lalala""", - """Multi line\n""" - """ url[https://foo.bar.example.com]\n""" + """Multi line<br/>""" + """ url[https://foo.bar.example.com]<br/>""" """ some text lalala""", "https://foo.bar.example.com"), ("@mention @someone",