From 93c3e27731321294a204c465f8b917946db38c85 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Thu, 6 Jan 2011 21:05:28 -0800
Subject: [PATCH] pandoc:  Add newline to output unless standalone.

This avoids output that does not end with a newline, which
is inconvenient when working with many tools.

Updated tests accordingly.
---
 src/pandoc.hs                                    | 8 ++++++--
 tests/markdown-citations.chicago-author-date.txt | 2 +-
 tests/markdown-citations.ieee.txt                | 2 +-
 tests/markdown-citations.txt                     | 2 +-
 tests/markdown-reader-more.native                | 1 +
 tests/s5.fragment.html                           | 2 +-
 tests/tables-rstsubset.native                    | 1 +
 tests/tables.context                             | 2 +-
 tests/tables.docbook                             | 2 +-
 tests/tables.html                                | 2 +-
 tests/tables.latex                               | 1 +
 tests/tables.man                                 | 2 +-
 tests/tables.markdown                            | 1 +
 tests/tables.mediawiki                           | 1 +
 tests/tables.native                              | 1 +
 tests/tables.opendocument                        | 2 +-
 tests/tables.org                                 | 1 +
 tests/tables.plain                               | 1 +
 tests/tables.rst                                 | 1 +
 tests/tables.rtf                                 | 1 +
 tests/tables.texinfo                             | 2 +-
 tests/tables.textile                             | 1 +
 22 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/src/pandoc.hs b/src/pandoc.hs
index 373919e05..e77200e43 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -813,6 +813,10 @@ main = do
 
   writerOutput <- writer writerOptions doc''
 
+  let writerOutput' = if standalone
+                         then writerOutput
+                         else writerOutput `B.snoc` 10
+
   if outputFile == "-"
-     then B.putStr writerOutput
-     else B.writeFile (encodeString outputFile) writerOutput
+     then B.putStr writerOutput'
+     else B.writeFile (encodeString outputFile) writerOutput'
diff --git a/tests/markdown-citations.chicago-author-date.txt b/tests/markdown-citations.chicago-author-date.txt
index 93cf6ce7c..11d84dadc 100644
--- a/tests/markdown-citations.chicago-author-date.txt
+++ b/tests/markdown-citations.chicago-author-date.txt
@@ -40,4 +40,4 @@ Doe, John, and Jenny Roe. 2007. Why Water Is Wet. In *Third Book*, ed. Sam Smith
 
 [^2]: Some citations (see Doe 2006, chap. 3; Doe and Roe 2007; Doe 2005).
 
-[^3]: Like a citation without author: (2005), and now Doe with a locator (2006, 44).
\ No newline at end of file
+[^3]: Like a citation without author: (2005), and now Doe with a locator (2006, 44).
diff --git a/tests/markdown-citations.ieee.txt b/tests/markdown-citations.ieee.txt
index 87f3e134a..0fd9335ad 100644
--- a/tests/markdown-citations.ieee.txt
+++ b/tests/markdown-citations.ieee.txt
@@ -40,4 +40,4 @@
 
 [^2]: Some citations [1]-[3].
 
-[^3]: Like a citation without author: [1], and now Doe with a locator [2].
\ No newline at end of file
+[^3]: Like a citation without author: [1], and now Doe with a locator [2].
diff --git a/tests/markdown-citations.txt b/tests/markdown-citations.txt
index 485ddf1d3..e2864d365 100644
--- a/tests/markdown-citations.txt
+++ b/tests/markdown-citations.txt
@@ -34,4 +34,4 @@
 
 [^2]: Some citations [see @item2 chap. 3; @item3; @item1].
 
-[^3]: Like a citation without author: [-@item1], and now Doe with a locator [-@item2 p. 44].
\ No newline at end of file
+[^3]: Like a citation without author: [-@item1], and now Doe with a locator [-@item2 p. 44].
diff --git a/tests/markdown-reader-more.native b/tests/markdown-reader-more.native
index 6fce927c1..fdd589c1e 100644
--- a/tests/markdown-reader-more.native
+++ b/tests/markdown-reader-more.native
@@ -49,3 +49,4 @@ Pandoc (Meta {docTitle = [Str "Title",Space,Str "spanning",Space,Str "multiple",
 , Header 2 [Str "Curly",Space,Str "smart",Space,Str "quotes"]
 , Para [Quoted DoubleQuote [Str "Hi"]]
 , Para [Quoted SingleQuote [Str "Hi"]] ]
+
diff --git a/tests/s5.fragment.html b/tests/s5.fragment.html
index cc111566a..9845e1409 100644
--- a/tests/s5.fragment.html
+++ b/tests/s5.fragment.html
@@ -14,4 +14,4 @@
     >$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span
     ></li
   ></ul
->
\ No newline at end of file
+>
diff --git a/tests/tables-rstsubset.native b/tests/tables-rstsubset.native
index 631da7b68..7202be8f6 100644
--- a/tests/tables-rstsubset.native
+++ b/tests/tables-rstsubset.native
@@ -116,3 +116,4 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
   , [ Plain [Str "row"] ]
   , [ Plain [Str "5",Str ".",Str "0"] ]
   , [ Plain [Str "Here",Str "'",Str "s",Space,Str "another",Space,Str "one",Str ".",Space,Str "Note",Space,Str "the",Space,Str "blank",Space,Str "line",Space,Str "between",Space,Str "rows",Str "."] ] ] ] ]
+
diff --git a/tests/tables.context b/tests/tables.context
index a280cc285..20f7ceedb 100644
--- a/tests/tables.context
+++ b/tests/tables.context
@@ -172,4 +172,4 @@ Multiline table without column headers:
 \NC Here's another one. Note the blank line between rows.
 \NC\AR
 \HL
-\stoptable
\ No newline at end of file
+\stoptable
diff --git a/tests/tables.docbook b/tests/tables.docbook
index a24964600..6483a97c0 100644
--- a/tests/tables.docbook
+++ b/tests/tables.docbook
@@ -399,4 +399,4 @@
       </td>
     </tr>
   </tbody>
-</informaltable>
\ No newline at end of file
+</informaltable>
diff --git a/tests/tables.html b/tests/tables.html
index 93944828c..e4dd6be58 100644
--- a/tests/tables.html
+++ b/tests/tables.html
@@ -298,4 +298,4 @@
       ></tr
     ></tbody
   ></table
->
\ No newline at end of file
+>
diff --git a/tests/tables.latex b/tests/tables.latex
index 5dac8e2a0..7f29b72c3 100644
--- a/tests/tables.latex
+++ b/tests/tables.latex
@@ -175,3 +175,4 @@ Second
 \\
 \end{tabular}
 \end{center}
+
diff --git a/tests/tables.man b/tests/tables.man
index 5f57ae5a7..35922b4df 100644
--- a/tests/tables.man
+++ b/tests/tables.man
@@ -264,4 +264,4 @@ T}@T{
 Here\[aq]s another one.
 Note the blank line between rows.
 T}
-.TE
\ No newline at end of file
+.TE
diff --git a/tests/tables.markdown b/tests/tables.markdown
index d1bbf168f..4b5754cf9 100644
--- a/tests/tables.markdown
+++ b/tests/tables.markdown
@@ -75,3 +75,4 @@ Multiline table without column headers:
                                       rows.
   ----------- ---------- ------------ --------------------------
 
+
diff --git a/tests/tables.mediawiki b/tests/tables.mediawiki
index d0e5c7b9e..4836ecd79 100644
--- a/tests/tables.mediawiki
+++ b/tests/tables.mediawiki
@@ -209,3 +209,4 @@ Multiline table without column headers:
 </tr>
 </tbody>
 </table>
+
diff --git a/tests/tables.native b/tests/tables.native
index 498273582..79024f651 100644
--- a/tests/tables.native
+++ b/tests/tables.native
@@ -113,3 +113,4 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
   , [ Plain [Str "row"] ]
   , [ Plain [Str "5",Str ".",Str "0"] ]
   , [ Plain [Str "Here",Str "'",Str "s",Space,Str "another",Space,Str "one",Str ".",Space,Str "Note",Space,Str "the",Space,Str "blank",Space,Str "line",Space,Str "between",Space,Str "rows",Str "."] ] ] ] ]
+
diff --git a/tests/tables.opendocument b/tests/tables.opendocument
index ef6176e91..e103dee12 100644
--- a/tests/tables.opendocument
+++ b/tests/tables.opendocument
@@ -393,4 +393,4 @@ headers:</text:p>
       blank line between rows.</text:p>
     </table:table-cell>
   </table:table-row>
-</table:table>
\ No newline at end of file
+</table:table>
diff --git a/tests/tables.org b/tests/tables.org
index 9eaf5e706..8d9100d07 100644
--- a/tests/tables.org
+++ b/tests/tables.org
@@ -49,3 +49,4 @@ Multiline table without column headers:
 
 | First    | row   | 12.0   | Example of a row that spans multiple lines.             |
 | Second   | row   | 5.0    | Here's another one. Note the blank line between rows.   |
+
diff --git a/tests/tables.plain b/tests/tables.plain
index d1bbf168f..4b5754cf9 100644
--- a/tests/tables.plain
+++ b/tests/tables.plain
@@ -75,3 +75,4 @@ Multiline table without column headers:
                                       rows.
   ----------- ---------- ------------ --------------------------
 
+
diff --git a/tests/tables.rst b/tests/tables.rst
index 25d5932ea..e77f69d97 100644
--- a/tests/tables.rst
+++ b/tests/tables.rst
@@ -88,3 +88,4 @@ Multiline table without column headers:
 |             |            |              | the blank line between     |
 |             |            |              | rows.                      |
 +-------------+------------+--------------+----------------------------+
+
diff --git a/tests/tables.rtf b/tests/tables.rtf
index 011724967..e7c1e9f60 100644
--- a/tests/tables.rtf
+++ b/tests/tables.rtf
@@ -357,3 +357,4 @@
 }
 \intbl\row}
 {\pard \ql \f0 \sa180 \li0 \fi0 \par}
+
diff --git a/tests/tables.texinfo b/tests/tables.texinfo
index 70256d814..b82006f1a 100644
--- a/tests/tables.texinfo
+++ b/tests/tables.texinfo
@@ -155,4 +155,4 @@ Second
  @tab row
  @tab 5.0
  @tab Here's another one. Note the blank line between rows.
-@end multitable
\ No newline at end of file
+@end multitable
diff --git a/tests/tables.textile b/tests/tables.textile
index d05cd4f9a..ccb34cf58 100644
--- a/tests/tables.textile
+++ b/tests/tables.textile
@@ -209,3 +209,4 @@ Multiline table without column headers:
 </tr>
  </tbody>
  </table>
+