diff --git a/sphinx-prompt/__init__.py b/sphinx-prompt/__init__.py
index <HASH>..<HASH> 100644
--- a/sphinx-prompt/__init__.py
+++ b/sphinx-prompt/__init__.py
@@ -103,7 +103,7 @@ class PromptDirective(rst.Directive):
                                 ).strip('\r\n')
                             )
                             statement = []
-                        line = line[len(prompt):].strip()
+                        line = line[len(prompt):].rstrip()
                         prompt_class = cache.get_prompt_class(prompt)
                         break
Only strip trailing whitespace from lines to preserve indentation.