diff options
| author | Jess Robinson <[email protected]> | 2012-03-06 21:29:49 +0000 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2012-04-25 13:54:17 -0700 |
| commit | 0eb88babd07bf4492fe65ab543fdb8c5d8091198 (patch) | |
| tree | 4146f14baf714dfc2c06bd6b15b1781278b3f3e3 | |
| parent | 1a8cbab32ac2ab742ff2aabe7a149e33ff103ab2 (diff) | |
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
| -rw-r--r-- | src/Text/Pandoc/Writers/PseudoPod.hs | 44 | ||||
| -rw-r--r-- | tests/tables.pod | 377 | ||||
| -rw-r--r-- | tests/writer.pod | 96 |
3 files changed, 471 insertions, 46 deletions
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 <content> - 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 <caption> / =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<embedded link|/url> @@ -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<gt> 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: <div> + + foo </div> + + And nested without indentation: <div> <div> <div> + + foo </div> </div> <div> + + bar </div> </div> + + Interpreted markdown in a table: <table> <tr> <td> + + This is I<emphasized> </td> <td> + + And this is B<strong> </td> @@ -721,14 +742,20 @@ And this is B<strong> <script type="text/javascript">document.write('This *should not* be interpreted as markdown');</script> + + Here’s a simple block: <div> + + foo </div> + + This should be a code block, though: <div> @@ -745,16 +772,22 @@ Now, nested: <div> <div> + + foo </div> </div> </div> + + This should just be an HTML comment: <!-- Comment --> + + Multiline: <!-- @@ -766,6 +799,8 @@ Blah This is another comment. --> + + Code block: <!-- Comment --> @@ -774,6 +809,8 @@ Just plain comment, with trailing spaces on the line: <!-- foo --> + + Code: <hr /> @@ -798,6 +835,10 @@ Hr’s: <hr class="foo" id="bar"> + + + + =head1 Inline Markup This is I<emphasized>, and so I<is this>. @@ -826,6 +867,8 @@ Subscripts: HH<2>O, HH<23>O, HH<many of them>O. 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<< E<lt>http:E<sol>E<sol>example.comE<sol>E<gt> >> or here: <http://example.com/> + + =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<movie|movie.jpg> icon. -=head1 Footnotes - -Here is a footnote reference,N<Here is the footnote. It can go anywhere after -the footnote reference. It need not be placed at the end of the document. - -> and another.N<Here’s the long note. This one contains multiple blocks. - -Subsequent blocks are indented to show that they belong to the footnote (as -with list items). - - { <code> } -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<not> be a footnote reference, because it contains a space.[^my -note] Here is an inline note.N<This is I<easier> to type. Inline notes may -contain L<links|http://google.com> and C<< ] >> verbatim characters, as well -as [bracketed text]. +=head1 Footnotes -> +Here is a footnote reference,N<Here is the footnote. It can go anywhere after +the footnote reference. It need not be placed at the end of the document.> and +another.N<Here’s the long note. This one contains multiple blocks.> This +should I<not> be a footnote reference, because it contains a space.[^my note] +Here is an inline note.N<This is I<easier> to type. Inline notes may contain +L<links|http://google.com> and C<< ] >> verbatim characters, as well as +[bracketed text].> =begin blockquote -Notes can go in quotes.N<In quote. - -> +Notes can go in quotes.N<In quote.> =end blockquote @@ -1119,9 +1159,7 @@ Notes can go in quotes.N<In quote. =item 1. -And in list items.N<In list. - -> +And in list items.N<In list.> =back |
