# HG changeset patch # User Mads Kiilerich # Date 1473115878 -7200 # Node ID 020334bec94b0f4391ea1c813cd2ad20e3e8329f # Parent 1717a7a4ae0c102649a06a64e7ea052e16f3439f helpers: introduce ascii preserving visual markup of *bold* No matter what kind of text (code and markup) is parsed, it will at most have slightly odd styling. Nothing will be lost and it can be copy-pasted correctly. Other kinds of markup (like _underline_ and /italic/) has also been considered ... but they will too often interfere with valid code and command snippets. diff -r 1717a7a4ae0c -r 020334bec94b kallithea/lib/helpers.py --- 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 @@ -1254,6 +1254,12 @@ (?[0-9a-f]{12,40}) (?!\w|[-_]) | +# Markup of *bold text* +(?: + (?:^|(?<=\s)) + (?P [*] (?!\s) [^*\n]* (?[a-zA-Z0-9\/\=\?\&\ \:\/\.\-]*)\] | \[license\ \=>\ *(?P[a-zA-Z0-9\/\=\?\&\ \:\/\.\-]*)\] | @@ -1289,6 +1295,9 @@ 'url': url('changeset_home', repo_name=repo_name, revision=hash_), 'hash': hash_, } + bold = match_obj.group('bold') + if bold is not None: + return '*%s*' % _urlify(bold[1:-1]) if stylize: seen = match_obj.group('seen') if seen: diff -r 1717a7a4ae0c -r 020334bec94b kallithea/tests/other/test_libs.py --- 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 @@ -352,6 +352,19 @@ ("deadbeefcafe 123412341234", """deadbeefcafe 123412341234""", ""), + ("We support * markup for *bold* markup of *single or multiple* words, " + "*a bit @like http://slack.com*. " + "The first * must come after whitespace and not be followed by whitespace, " + "contain anything but * and newline until the next *, " + "which must not come after whitespace " + "and not be followed by * or alphanumerical *characters*.", + """We support * markup for *bold* markup of *single or multiple* words, """ + """*a bit @like http://slack.com*. """ + """The first * must come after whitespace and not be followed by whitespace, """ + """contain anything but * and newline until the next *, """ + """which must not come after whitespace """ + """and not be followed by * or alphanumerical *characters*.""", + "-"), # tags are covered by test_tag_extractor ]) def test_urlify_test(self, sample, expected, url_):