From 0eb88babd07bf4492fe65ab543fdb8c5d8091198 Mon Sep 17 00:00:00 2001 From: Jess Robinson Date: Tue, 6 Mar 2012 21:29:49 +0000 Subject: Redesign so the ending blanklines of blocks are added later, not by each output part, this allows us to cope with Notes, which are only inline in POD --- src/Text/Pandoc/Writers/PseudoPod.hs | 44 ++-- tests/tables.pod | 377 +++++++++++++++++++++++++++++++++++ tests/writer.pod | 96 ++++++--- 3 files changed, 471 insertions(+), 46 deletions(-) create mode 100644 tests/tables.pod diff --git a/src/Text/Pandoc/Writers/PseudoPod.hs b/src/Text/Pandoc/Writers/PseudoPod.hs index cfc80d605..607056243 100644 --- a/src/Text/Pandoc/Writers/PseudoPod.hs +++ b/src/Text/Pandoc/Writers/PseudoPod.hs @@ -162,7 +162,7 @@ blockToPseudoPod :: WriterOptions -- ^ Options blockToPseudoPod _ Null = return empty blockToPseudoPod opts (Plain inlines) = do contents <- inlineListToPseudoPod opts inlines - return $ contents <> blankline + return $ contents blockToPseudoPod opts (Para inlines) = do @@ -174,7 +174,7 @@ blockToPseudoPod opts (Para inlines) = do beginsWithOrderedListMarker (render Nothing contents) then text "\\" else empty - return $ esc <> contents <> blankline + return $ esc <> contents blockToPseudoPod _ (RawBlock f str) | f == "html" || f == "latex" || f == "tex" || f == "PseudoPod" = do @@ -186,12 +186,12 @@ blockToPseudoPod _ (RawBlock _ _) = return empty -- | No horizontal rules, leave a space blockToPseudoPod _ HorizontalRule = - return $ blankline <> blankline <> blankline + return $ blankline <> blankline -- | =headN - DONE blockToPseudoPod opts (Header level inlines) = do contents <- inlineListToPseudoPod opts inlines - return $ "=head" <> text (show level) <> " " <> contents <> blankline + return $ "=head" <> text (show level) <> " " <> contents {- blockToPseudoPod opts (CodeBlock (_,classes,_) str) @@ -202,7 +202,7 @@ blockToPseudoPod opts (CodeBlock (_,classes,_) str) -- | indent 3 spaces - DONE blockToPseudoPod _ (CodeBlock _ str) = return $ - nest 3 (text str) <> blankline + nest 3 (text str) {- if writerStrictMarkdown opts || attribs == nullAttr @@ -217,7 +217,7 @@ blockToPseudoPod _ (CodeBlock _ str) = return $ -- | =begin blockquote ? blockToPseudoPod opts (BlockQuote blocks) = do contents <- blockListToPseudoPod opts blocks - return $ "=begin blockquote" <> blankline <> contents <> blankline <> "=end blockquote" <> blankline + return $ "=begin blockquote" <> blankline <> contents <> blankline <> "=end blockquote" -- | =begin table / =headrow / =row / =cell / =bodyrows / =row / =cell / =end table blockToPseudoPod opts (Table caption _ _ headers rows) = do @@ -237,12 +237,12 @@ blockToPseudoPod opts (Table caption _ _ headers rows) = do then empty else "=headrow" <> blankline <> "=row" <> blankline <> "=cell " <> head' - return $ "=begin table " <> caption' <> blankline <> head'' <> blankline <> "=bodyrows" <> blankline <> rows''' <> blankline <> "=end table" <> blankline + return $ "=begin table " <> caption' <> blankline <> head'' <> blankline <> "=bodyrows" <> blankline <> rows''' <> blankline <> "=end table" -- | =over / =item * / =back blockToPseudoPod opts (BulletList items) = do contents <- mapM (bulletListItemToPseudoPod opts) items - return $ "=over" <> blankline <> cat contents <> blankline <> "=back" <> blankline + return $ "=over" <> blankline <> cat contents <> blankline <> "=back" -- | =over / =item N. / =back @@ -253,12 +253,12 @@ blockToPseudoPod opts (OrderedList attribs items) = do else m) markers contents <- mapM (\(item, num) -> orderedListItemToPseudoPod opts item num) $ zip markers' items - return $ "=over" <> blankline <> cat contents <> blankline <> "=back" <> blankline + return $ "=over" <> blankline <> cat contents <> blankline <> "=back" -- return $ cat contents <> blankline blockToPseudoPod opts (DefinitionList items) = do contents <- mapM (definitionListItemToPseudoPod opts) items - return $ "=over" <> blankline <> cat contents <> blankline <> "=back" <> blankline + return $ "=over" <> blankline <> cat contents <> blankline <> "=back" -- | bullet list -> =item * bulletListItemToPseudoPod :: WriterOptions -> [Block] -> State WriterState Doc @@ -319,8 +319,12 @@ definitionListItemToPseudoPod opts (label, defs) = do blockListToPseudoPod :: WriterOptions -- ^ Options -> [Block] -- ^ List of block elements -> State WriterState Doc -blockListToPseudoPod opts blocks = - mapM (blockToPseudoPod opts) (blocks) >>= return . cat +blockListToPseudoPod opts blocks = do + contents <- mapM (blockToPseudoPod opts) (blocks) + let makeBlank = hcat . intersperse (text("\n\n")) + let contents' = makeBlank contents + return $ contents' +-- >>= return . cat . intersperse (blankline) -- | Convert list of Pandoc inline elements to PseudoPod. inlineListToPseudoPod :: WriterOptions -> [Inline] -> State WriterState Doc @@ -433,7 +437,10 @@ inlineToPseudoPod _ (Cite _ _) = return $ text "" -- | L<> - DONE inlineToPseudoPod opts (Link txt (src, _)) = do label <- inlineListToPseudoPod opts txt - return $ "L<" <> label <> "|" <> (text src) <> ">" + let linktext = if null txt + then empty + else label <> (text "|") + return $ "L<" <> linktext <> (text src) <> ">" inlineToPseudoPod opts (Image alternate (source, tit)) = do let txt = if (null alternate) || (alternate == [Str ""]) || @@ -444,7 +451,10 @@ inlineToPseudoPod opts (Image alternate (source, tit)) = do return $ "!" <> linkPart -- | N<> -inlineToPseudoPod opts (Note blocks) = do --- contents <- blockListToPseudoPod opts blocks - contents <- mapM (blockToPseudoPod opts) blocks - return $ "N<" <> cat contents <> ">" +-- inlineToPseudoPod :: WriterOptions -> Inline -> State WriterState Doc +-- We need the converted blocks not to end in a blankline, else we get blankline ">", which the pseudopod parser does not like +inlineToPseudoPod opts (Note (block:_)) = do +-- contents <- mapM (blockToPseudoPod opts) blocks + contents <- blockToPseudoPod opts block + return $ "N<" <> contents <> ">" +-- return $ "N<" <> cat contents <> ">" diff --git a/tests/tables.pod b/tests/tables.pod new file mode 100644 index 000000000..6e990a527 --- /dev/null +++ b/tests/tables.pod @@ -0,0 +1,377 @@ +=encoding utf8 + +Simple table with caption: + +=begin table Demonstration of simple table syntax. + +=headrow + +=row + +=cell Right + + +=cell Left + + +=cell Center + + +=cell Default + +=bodyrows + +=row + +=cell 12 + + +=cell 12 + + +=cell 12 + + +=cell 12 + + +=row + +=cell 123 + + +=cell 123 + + +=cell 123 + + +=cell 123 + + +=row + +=cell 1 + + +=cell 1 + + +=cell 1 + + +=cell 1 + +=end table + +Simple table without caption: + +=begin table + +=headrow + +=row + +=cell Right + + +=cell Left + + +=cell Center + + +=cell Default + +=bodyrows + +=row + +=cell 12 + + +=cell 12 + + +=cell 12 + + +=cell 12 + + +=row + +=cell 123 + + +=cell 123 + + +=cell 123 + + +=cell 123 + + +=row + +=cell 1 + + +=cell 1 + + +=cell 1 + + +=cell 1 + +=end table + +Simple table indented two spaces: + +=begin table Demonstration of simple table syntax. + +=headrow + +=row + +=cell Right + + +=cell Left + + +=cell Center + + +=cell Default + +=bodyrows + +=row + +=cell 12 + + +=cell 12 + + +=cell 12 + + +=cell 12 + + +=row + +=cell 123 + + +=cell 123 + + +=cell 123 + + +=cell 123 + + +=row + +=cell 1 + + +=cell 1 + + +=cell 1 + + +=cell 1 + +=end table + +Multiline table with caption: + +=begin table Here's the caption. It may span multiple lines. + +=headrow + +=row + +=cell Centered Header + + +=cell Left Aligned + + +=cell Right Aligned + + +=cell Default aligned + +=bodyrows + +=row + +=cell First + + +=cell row + + +=cell 12.0 + + +=cell Example of a row that spans multiple lines. + + +=row + +=cell Second + + +=cell row + + +=cell 5.0 + + +=cell Here's another one. Note the blank line between rows. + +=end table + +Multiline table without caption: + +=begin table + +=headrow + +=row + +=cell Centered Header + + +=cell Left Aligned + + +=cell Right Aligned + + +=cell Default aligned + +=bodyrows + +=row + +=cell First + + +=cell row + + +=cell 12.0 + + +=cell Example of a row that spans multiple lines. + + +=row + +=cell Second + + +=cell row + + +=cell 5.0 + + +=cell Here's another one. Note the blank line between rows. + +=end table + +Table without column headers: + +=begin table + +=bodyrows + +=row + +=cell 12 + + +=cell 12 + + +=cell 12 + + +=cell 12 + + +=row + +=cell 123 + + +=cell 123 + + +=cell 123 + + +=cell 123 + + +=row + +=cell 1 + + +=cell 1 + + +=cell 1 + + +=cell 1 + +=end table + +Multiline table without column headers: + +=begin table + +=bodyrows + +=row + +=cell First + + +=cell row + + +=cell 12.0 + + +=cell Example of a row that spans multiple lines. + + +=row + +=cell Second + + +=cell row + + +=cell 5.0 + + +=cell Here's another one. Note the blank line between rows. + +=end table diff --git a/tests/writer.pod b/tests/writer.pod index 1eaac2cc5..bcb35bd5a 100644 --- a/tests/writer.pod +++ b/tests/writer.pod @@ -3,6 +3,8 @@ This is a set of tests for pandoc. Most of them are adapted from John Gruber’s markdown test suite. + + =head1 Headers =head2 Level 2 with an L @@ -25,6 +27,8 @@ with no blank line with no blank line + + =head1 Paragraphs Here’s a regular paragraph. @@ -38,6 +42,8 @@ Here’s one with a bullet. * criminey. There should be a hard line break\ here. + + =head1 Block Quotes E-mail style: @@ -90,6 +96,8 @@ This should not be a block quote: 2 E 1. And a following paragraph. + + =head1 Code Blocks Code: @@ -108,6 +116,8 @@ And: These should not be escaped: \$ \\ \> \[ \{ + + =head1 Lists =head2 Unordered @@ -536,6 +546,8 @@ M.A. 2007 B. Williams + + =head1 Definition Lists Tight using spaces: @@ -623,13 +635,11 @@ Multiple definitions, tight: =item apple red fruit - computer =item orange orange fruit - bank =back @@ -641,13 +651,11 @@ Multiple definitions, loose: =item apple red fruit - computer =item orange orange fruit - bank =back @@ -659,7 +667,6 @@ Blank line after term, indented marker, alternate markers: =item apple red fruit - computer =item orange @@ -685,34 +692,48 @@ sublist Simple block on one line:
+ + foo
+ + And nested without indentation:
+ + foo
+ + bar
+ + Interpreted markdown in a table: @@ -721,14 +742,20 @@ And this is B + + Here’s a simple block:
+ + foo
+ + This should be a code block, though:
@@ -745,16 +772,22 @@ Now, nested:
+ + foo
+ + This should just be an HTML comment: + + Multiline: + + Code block: @@ -774,6 +809,8 @@ Just plain comment, with trailing spaces on the line: + + Code:
@@ -798,6 +835,10 @@ Hr’s:
+ + + + =head1 Inline Markup This is I, and so I. @@ -826,6 +867,8 @@ Subscripts: HH<2>O, HH<23>O, HHO. These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d. + + =head1 Smart quotes, ellipses, dashes “Hello,” said the spider. “‘Shelob’ is my name.” @@ -845,6 +888,8 @@ Dashes between numbers: 5–7, 255–66, 1987–1999. Ellipses…and…and…. + + =head1 LaTeX =over @@ -915,6 +960,9 @@ Dog & 2 \\ Cat & 1 \\ \hline \end{tabular} + + + =head1 Special Characters Here is some unicode: @@ -985,6 +1033,8 @@ Plus: + Minus: - + + =head1 Links =head2 Explicit @@ -1077,6 +1127,8 @@ C<< Ehttp:EEexample.comEE >> or here: + + =head1 Images From “Voyage dans la Lune” by Georges Melies (1902): @@ -1085,33 +1137,21 @@ From “Voyage dans la Lune” by Georges Melies (1902): Here is a movie !L icon. -=head1 Footnotes - -Here is a footnote reference,N and another.N } -If you want, you can indent every line, but you can also be lazy and just -indent the first line of each block. -> This should I be a footnote reference, because it contains a space.[^my -note] Here is an inline note.N to type. Inline notes may -contain L and C<< ] >> verbatim characters, as well -as [bracketed text]. +=head1 Footnotes -> +Here is a footnote reference,N and +another.N This +should I be a footnote reference, because it contains a space.[^my note] +Here is an inline note.N to type. Inline notes may contain +L and C<< ] >> verbatim characters, as well as +[bracketed text].> =begin blockquote -Notes can go in quotes.N +Notes can go in quotes.N =end blockquote @@ -1119,9 +1159,7 @@ Notes can go in quotes.N +And in list items.N =back -- cgit v1.2.3
+ + This is I + + And this is B