From 0b1bb2d5749190e4f110d043a49fc6afb9a4acb7 Mon Sep 17 00:00:00 2001 From: woorst Date: Sat, 2 Feb 2019 14:45:44 -0500 Subject: [PATCH 1/2] Improve comment formatting for markdown code block --- rtv/terminal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rtv/terminal.py b/rtv/terminal.py index 6067dcc..b1faf0e 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -911,7 +911,8 @@ class Terminal(object): # Pattern can span multiple lines, allows dot to match newline chars flags = re.MULTILINE | re.DOTALL pattern = ''.format(token=TOKEN) - return re.sub(pattern, '', text, flags=flags).strip() + text = re.sub(pattern, '', text, flags=flags) + return re.sub( '^[\s\n]*\n', '', text, flags=flags).rstrip() def clear_screen(self): """ From a727110e404ccb1e30ab7211cb0a4d64ef8597da Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Sat, 2 Feb 2019 19:02:38 -0500 Subject: [PATCH 2/2] Adding test cases --- tests/test_terminal.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_terminal.py b/tests/test_terminal.py index 4889f8d..7eac2a4 100644 --- a/tests/test_terminal.py +++ b/tests/test_terminal.py @@ -701,6 +701,14 @@ def test_terminal_strip_instructions(terminal): text = ''.format(TOKEN) assert terminal.strip_instructions(text) == '' + # Whitespace at the start of the first line should be preserved + text = ' code\n block\n' + assert terminal.strip_instructions(text) == ' code\n block' + + # But blank lines should be stripped + text = '\n \n code\n block\n' + assert terminal.strip_instructions(text) == ' code\n block' + def test_terminal_get_link_pages(terminal):