]> git.wincent.com - docvim.git/commitdiff
Special-case empty output
authorGreg Hurrell <greg@hurrell.net>
Mon, 13 Jun 2016 04:58:04 +0000 (21:58 -0700)
committerGreg Hurrell <greg@hurrell.net>
Mon, 13 Jun 2016 04:58:04 +0000 (21:58 -0700)
Don't print a blank-line, prefer a zero-byte file.

Closes: https://github.com/wincent/docvim/issues/21
lib/Text/Docvim/Printer/Markdown.hs
lib/Text/Docvim/Printer/Vim.hs
tests/fixtures/integration/loupe/golden/markdown.golden
tests/fixtures/integration/loupe/golden/plaintext.golden
tests/fixtures/integration/terminus/golden/markdown.golden
tests/fixtures/integration/terminus/golden/plaintext.golden
tests/fixtures/integration/vim-clipper/golden/markdown.golden
tests/fixtures/integration/vim-clipper/golden/plaintext.golden

index 43becfc393535b9f5625182101ec5da88cf34885..b9e19b30621a1b4701101a8be90f738d46c9e4aa 100644 (file)
@@ -17,8 +17,12 @@ data Anchor = Anchor [Attribute] String
 data Attribute = Attribute String String
 
 markdown :: Node -> String
-markdown n = rstrip (runReader (node n) metadata) ++ "\n"
-  where metadata = Metadata (getPluginName n) (getSymbols n)
+markdown n = if null stripped
+             then ""
+             else stripped ++ "\n"
+  where
+    metadata = Metadata (getPluginName n) (getSymbols n)
+    stripped = rstrip (runReader (node n) metadata)
 
 nodes :: [Node] -> Env
 nodes ns = concat <$> mapM node ns
index 5f1d8ef3eb8889e6d9d9633512276c0be1857caa..ed4608bd0632f01b156372df1b2cf2c119f61151 100644 (file)
@@ -34,7 +34,9 @@ textwidth :: Int
 textwidth = 78
 
 vimHelp :: Node -> String
-vimHelp n = suppressTrailingWhitespace output ++ "\n"
+vimHelp n = if null suppressTrailingWhitespace
+            then ""
+            else suppressTrailingWhitespace ++ "\n"
   where metadata = Metadata (getPluginName n)
         context = Context defaultLineBreak ""
         operations = evalState (runReaderT (node n) metadata) context
@@ -44,7 +46,7 @@ vimHelp n = suppressTrailingWhitespace output ++ "\n"
         reduce acc (Slurp atom) = if atom `isSuffixOf` acc
                                   then take (length acc - length atom) acc
                                   else acc
-        suppressTrailingWhitespace str = rstrip $ intercalate "\n" (map rstrip (splitOn "\n" str))
+        suppressTrailingWhitespace = rstrip $ intercalate "\n" (map rstrip (splitOn "\n" output))
 
 -- | Helper function that appends and updates `partialLine` context,
 -- hard-wrapping if necessary to remain under `textwidth`.