diff --git a/src/Text/Pandoc/Writers/CommonMark.hs b/src/Text/Pandoc/Writers/CommonMark.hs
index 20a22e051..77562ed8a 100644
--- a/src/Text/Pandoc/Writers/CommonMark.hs
+++ b/src/Text/Pandoc/Writers/CommonMark.hs
@@ -86,7 +86,7 @@ blocksToCommonMark opts bs = do
                  then Just $ writerColumns opts
                  else Nothing
   nodes <- blocksToNodes opts bs
-  return $
+  return $ T.stripEnd $
     nodeToCommonmark cmarkOpts colwidth $
     node DOCUMENT nodes
 
diff --git a/test/command/gfm.md b/test/command/gfm.md
index 6dd080dc1..670f3cd6e 100644
--- a/test/command/gfm.md
+++ b/test/command/gfm.md
@@ -71,8 +71,6 @@ My:thumbsup:emoji:heart:
 | orange |  1.12 |
 
 The caption.
-
-
 ```
 
 ```
@@ -80,8 +78,6 @@ The caption.
 “hi”
 ^D
 "hi"
-
-
 ```
 
 ```
@@ -89,8 +85,6 @@ The caption.
 "hi"
 ^D
 “hi”
-
-
 ```
 
 ```
@@ -98,8 +92,6 @@ The caption.
 "hi"
 ^D
 "hi"
-
-
 ```
 
 ```