diff roundup/cgi/templating.py @ 6336:6f89cdc7c938

issue2551108 - fix markdown formatted designator links Designators like 'issue1' are automatically hyperlinked. However if typed as [issue1](issue1) or [issue1](https://example.com/issue1) they get mangled. Stop that mangling.
author John Rouillard <rouilj@ieee.org>
date Fri, 12 Mar 2021 01:30:22 -0500
parents fd0bdcbc68e4
children a7e7314fb7d9
line wrap: on
line diff
--- a/roundup/cgi/templating.py	Wed Mar 10 17:09:16 2021 -0500
+++ b/roundup/cgi/templating.py	Fri Mar 12 01:30:22 2021 -0500
@@ -1691,6 +1691,23 @@
                 s = match.group(group)
                 return '<%s>' % s
         if match.group('id') and len(match.group('id')) < 10:
+            # Pass through markdown style links:
+            #     [issue1](https://....)
+            #     [issue1](issue1)
+            # as 'issue1'. Don't convert issue1 into a link.
+            # https://issues.roundup-tracker.org/issue2551108
+            start = match.start('item') - 1
+            end = match.end('item')
+            if start >= 0:
+                prefix = match.string[start]
+                if end < len(match.string):
+                    suffix = match.string[end]
+                    if (prefix, suffix) in {('[', ']')}:
+                        if match.string[end+1] == '(': # find following (
+                            return match.group(0)
+                    if (prefix, suffix) in {('(',')')}:
+                        if match.string[start-1] == ']':
+                            return match.group(0)
             return self._hyper_repl_item(match,'[%(item)s](%(cls)s%(id)s)')
         else:
             # just return the matched text

Roundup Issue Tracker: http://roundup-tracker.org/