Changeset - 4e2e6371f79a
[Not reviewed]
default
0 4 0
Mads Kiilerich - 9 years ago 2016-09-06 00:51:18
madski@unity3d.com
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.
4 files changed with 26 insertions and 52 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/helpers.py
Show inline comments
 
@@ -1299,12 +1299,13 @@ def urlify_text(s, repo_name=None, link_
 
    if stylize:
 
        s = desc_stylize(s)
 
    s = _urlify_text(s)
 
    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)
 

	
 

	
 
def _urlify_changeset_replace_f(repo_name):
 
    from pylons import url  # doh, we need to re-import url to mock it later
 
    def urlify_changeset_replace(match_obj):
kallithea/tests/functional/test_files.py
Show inline comments
 
@@ -96,17 +96,17 @@ class TestFilesController(TestController
 
        self.log_user()
 
        response = self.app.get(url(controller='files', action='index',
 
                                    repo_name=HG_REPO,
 
                                    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>""")
 

	
 
    def test_file_source_history(self):
 
        self.log_user()
kallithea/tests/models/test_dump_html_mails.ref.html
Show inline comments
 
@@ -91,15 +91,13 @@ View Comment: http://comment.org
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -250,15 +248,13 @@ View Comment: http://comment.org
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -427,15 +423,13 @@ View Comment: http://comment.org
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -604,15 +598,13 @@ View Comment: http://comment.org
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -725,14 +717,13 @@ Subject: Test Message
 
                </tr>
 
                <tr>
 
                    <td></td>
 
                    <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>
 
                    <td></td>
 
                </tr>
 
                <tr>
 
@@ -983,14 +974,13 @@ View Pull Request: http://pr.org/7
 
            </div>
 
        </td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td>
 
            <div>Changesets:</div>
 
@@ -1157,14 +1147,13 @@ View Pull Request: http://pr.org/7
 
            </div>
 
        </td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td>
 
            <div>Changesets:</div>
 
@@ -1314,15 +1303,13 @@ View Comment: http://pr.org/comment
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -1479,15 +1466,13 @@ View Comment: http://pr.org/comment
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -1662,15 +1647,13 @@ View Comment: http://pr.org/comment
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -1845,15 +1828,13 @@ View Comment: http://pr.org/comment
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -2027,15 +2008,13 @@ View Comment: http://pr.org/comment
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -2209,15 +2188,13 @@ View Comment: http://pr.org/comment
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -2397,15 +2374,13 @@ View Comment: http://pr.org/comment
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
@@ -2585,15 +2560,13 @@ View Comment: http://pr.org/comment
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <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>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
kallithea/tests/other/test_libs.py
Show inline comments
 
@@ -305,15 +305,15 @@ class TestLibs(TestController):
 
       """url[ffffffffffff] some text traalaa"""),
 
       ("""Multi line
 
       123123123123
 
       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):
 
        def fake_url(self, *args, **kwargs):
 
            return '/some-url'
 

	
 
@@ -339,14 +339,14 @@ class TestLibs(TestController):
 
      ("http://imgur.com/foo.gif inline http://imgur.com/foo.gif ending http://imgur.com/foo.gif",
 
       """url[http://imgur.com/foo.gif] inline url[http://imgur.com/foo.gif] ending url[http://imgur.com/foo.gif]""",
 
       "http://imgur.com/foo.gif"),
 
      ("""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",
 
       """<b>@mention</b> <b>@someone</b>""",
 
       ""),
 
      ("deadbeefcafe 123412341234",
0 comments (0 inline, 0 general)