From 05297eb59be5a75614a3c95c06fe70f1de2a24f0 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Wed, 13 Feb 2019 10:10:24 -0500 Subject: [PATCH] Prevent stripping newlines in the middle of markdown submissions --- rtv/terminal.py | 2 +- tests/test_terminal.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/rtv/terminal.py b/rtv/terminal.py index b1faf0e..7a73266 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -912,7 +912,7 @@ class Terminal(object): flags = re.MULTILINE | re.DOTALL pattern = ''.format(token=TOKEN) text = re.sub(pattern, '', text, flags=flags) - return re.sub( '^[\s\n]*\n', '', text, flags=flags).rstrip() + return re.sub('\A[\s\n]*\n', '', text, flags=flags).rstrip() def clear_screen(self): """ diff --git a/tests/test_terminal.py b/tests/test_terminal.py index 7eac2a4..a7e4e78 100644 --- a/tests/test_terminal.py +++ b/tests/test_terminal.py @@ -709,6 +709,10 @@ def test_terminal_strip_instructions(terminal): text = '\n \n code\n block\n' assert terminal.strip_instructions(text) == ' code\n block' + # However, blank lines in the middle of comment should not be stripped + text = 'paragraph 1\n\nparagraph 2\n' + assert terminal.strip_instructions(text) == 'paragraph 1\n\nparagraph 2' + def test_terminal_get_link_pages(terminal):