Mercurial > p > roundup > code
diff roundup/cgi/templating.py @ 7561:91725f12b239
Support markdown2 2.4.10, 2.4.8- and exclude 2.4.9
Handle these changes to markdown2
version 2.4.9 broke links like (issue1)[issue1]: raise error if used
Version 2.4.10 changed how filtering of schemes is done: adapt to new
method
Mail url's in markdown are formatted
[label](mailto:user@something.com). The markdown format wrapper uses
the plain text formatter to turn issue1 and user@something.com into
markdown formatted strings to be htmlized by the markdown formatters.
However when the plain text formatter saw (mailto:user@something.com)
it made it (mailto:<user@something.com>). This is broken as the enamil
address shouldn't have the angle brackets. By modifying the email
pattern to include an optional mailto:, all three markdown formatters
do the right thing and I don't end up with href="<user@something.com>"
in the link.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 23 Jul 2023 16:50:35 -0400 |
| parents | d267b0454500 |
| children | 448dad050c9e |
line wrap: on
line diff
--- a/roundup/cgi/templating.py Sun Jul 23 16:11:23 2023 -0400 +++ b/roundup/cgi/templating.py Sun Jul 23 16:50:35 2023 -0400 @@ -61,10 +61,49 @@ import markdown2 import re - class Markdown(markdown2.Markdown): - # don't allow disabled protocols in links - _safe_protocols = re.compile('(?!' + ':|'.join([ - re.escape(s) for s in _disable_url_schemes]) + # Note: version 2.4.9 does not work with Roundup as it breaks + # [issue1](issue1) formatted links. + + # Versions 2.4.8 and 2.4.10 use different methods to filter + # allowed schemes. 2.4.8 uses a pre-compiled regexp while + # 2.4.10 uses a regexp string that it compiles. + + markdown2_vi = markdown2.__version_info__ + if markdown2_vi > (2, 4, 9): + # Create the filtering regexp. + # Allowed default is same as what hyper_re supports. + + # pathed_schemes are terminated with :// + pathed_schemes = [ 'http', 'https', 'ftp', 'ftps' ] + # non_pathed are terminated with a : + non_pathed_schemes = [ "mailto" ] + + for disabled in _disable_url_schemes: + try: + pathed_schemes.remove(disabled) + except ValueError: # if disabled not in list + pass + try: + non_pathed_schemes.remove(disabled) + except ValueError: + pass + + re_list = [] + for scheme in pathed_schemes: + re_list.append(r'(?:%s)://' % scheme) + for scheme in non_pathed_schemes: + re_list.append(r'(?:%s):' % scheme) + + enabled_schemes = r"|".join(re_list) + class Markdown(markdown2.Markdown): + _safe_protocols = enabled_schemes + elif markdown2_vi == (2, 4, 9): + raise RuntimeError("Unsupported version - markdown2 v2.4.9\n") + else: + class Markdown(markdown2.Markdown): + # don't allow disabled protocols in links + _safe_protocols = re.compile('(?!' + ':|'.join([ + re.escape(s) for s in _disable_url_schemes]) + ':)', re.IGNORECASE) def _extras(config): @@ -1639,7 +1678,7 @@ (:[\d]{1,5})? # port (/[\w\-$.+!*(),;:@&=?/~\\#%]*)? # path etc. )| - (?P<email>[-+=%/\w\.]+@[\w\.\-]+)| + (?P<email>(?:mailto:)?[-+=%/\w\.]+@[\w\.\-]+)| (?P<item>(?P<class>[A-Za-z_]+)(\s*)(?P<id>\d+)(?P<fragment>\#[^][\#%^{}"<>\s]+)?) )''', re.X | re.I) protocol_re = re.compile('^(ht|f)tp(s?)://', re.I)
