changeset 6190:020334bec94b

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.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 06 Sep 2016 00:51:18 +0200
parents 1717a7a4ae0c
children 79676fef1ae0
files kallithea/lib/helpers.py kallithea/tests/other/test_libs.py
diffstat 2 files changed, 22 insertions(+), 0 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
@@ -1254,6 +1254,12 @@
 (?<!\w|[-_])
   (?P<hash>[0-9a-f]{12,40})
 (?!\w|[-_]) |
+# Markup of *bold text*
+(?:
+  (?:^|(?<=\s))
+  (?P<bold> [*] (?!\s) [^*\n]* (?<!\s) [*] )
+  (?![*\w])
+) |
 # "Stylize" markup
 \[see\ \=&gt;\ *(?P<seen>[a-zA-Z0-9\/\=\?\&\ \:\/\.\-]*)\] |
 \[license\ \=&gt;\ *(?P<license>[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 '<b>*%s*</b>' % _urlify(bold[1:-1])
         if stylize:
             seen = match_obj.group('seen')
             if seen:
--- 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",
        """<a class="revision-link" href="/repo_name/changeset/deadbeefcafe">deadbeefcafe</a> <a class="revision-link" href="/repo_name/changeset/123412341234">123412341234</a>""",
        ""),
+      ("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 <b>*bold*</b> markup of <b>*single or multiple*</b> words, """
+       """<b>*a bit <b>@like</b> <a href="http://slack.com">http://slack.com</a>*</b>. """
+       """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 <b>*characters*</b>.""",
+       "-"),
       # tags are covered by test_tag_extractor
     ])
     def test_urlify_test(self, sample, expected, url_):