From b39e6c23b16c091518c7610634b9493d7a2a38bb Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 14 2016 09:50:34 +0000 Subject: Disable the markdown extension nl2br on files in general Fixes https://pagure.io/pagure/issue/1649 --- diff --git a/pagure/doc_utils.py b/pagure/doc_utils.py index 95f47c5..7878d04 100644 --- a/pagure/doc_utils.py +++ b/pagure/doc_utils.py @@ -103,7 +103,7 @@ def convert_readme(content, ext, view_file_url=None): safe = True output = convert_doc(output, view_file_url) elif ext and ext in ['.mk', '.md', '.markdown']: - output = pagure.lib.text2markdown(output) + output = pagure.lib.text2markdown(content, readme=True) safe = True elif not ext or (ext and ext in ['.text', '.txt']): safe = True diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index e34eb1b..5e15bfd 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -2948,7 +2948,7 @@ def add_token_to_user(session, project, acls, username): return 'Token created' -def text2markdown(text, extended=True): +def text2markdown(text, extended=True, readme=False): """ Simple text to html converter using the markdown library. """ extensions = [ @@ -2961,10 +2961,14 @@ def text2markdown(text, extended=True): # All of the above are the .extra extensions - the attribute lists one 'markdown.extensions.admonition', 'markdown.extensions.codehilite', - 'markdown.extensions.nl2br', 'markdown.extensions.sane_lists', 'markdown.extensions.toc', ] + # Some extensions are disabled for READMEs and enabled otherwise + if not readme: + extensions.append( + 'markdown.extensions.nl2br', + ) if extended: # Install our markdown modifications extensions.append('pagure.pfmarkdown')