diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-12-17 15:34:25 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-12-17 15:34:25 +0000 |
commit | 751aa15abcf945a40f4169a9e6a8640c36a801a5 (patch) | |
tree | c4e21bb021cbd1cd20bd43834621323b0ae7ad6b | |
parent | 9ff729fc1e0855820215c0b2c07164705e2ce53f (diff) | |
download | pandoc-751aa15abcf945a40f4169a9e6a8640c36a801a5.tar.gz |
Fixed problems in RST and markdown output due to bug in pretty-1.0.1.0
+ Added hang' function to Text.Pandoc.Shared; this will be used instead
of hang, which doesn't work properly in pretty-1.0.1.0. When pretty
is upgraded, we can go back to hang.
See http://article.gmane.org/gmane.comp.lang.haskell.general/16687
+ Use hang' (and some different techniques) in RST and markdown writers.
Some output is now a bit different.
+ Modify test suites accordingly.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1515 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r-- | Text/Pandoc/Shared.hs | 13 | ||||
-rw-r--r-- | Text/Pandoc/Writers/Markdown.hs | 4 | ||||
-rw-r--r-- | Text/Pandoc/Writers/RST.hs | 10 | ||||
-rw-r--r-- | tests/writer.markdown | 6 | ||||
-rw-r--r-- | tests/writer.rst | 14 |
5 files changed, 28 insertions, 19 deletions
diff --git a/Text/Pandoc/Shared.hs b/Text/Pandoc/Shared.hs index f8c5e8d17..c607a4e5b 100644 --- a/Text/Pandoc/Shared.hs +++ b/Text/Pandoc/Shared.hs @@ -87,7 +87,8 @@ module Text.Pandoc.Shared ( KeyTable, lookupKeySrc, refsMatch, - -- * Native format prettyprinting + -- * Prettyprinting + hang', prettyPandoc, -- * Pandoc block and inline list processing orderedListMarkers, @@ -106,7 +107,7 @@ module Text.Pandoc.Shared ( import Text.Pandoc.Definition import Text.ParserCombinators.Parsec -import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text ) +import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text, nest ) import qualified Text.PrettyPrint.HughesPJ as PP import Text.Pandoc.CharacterReferences ( characterReference ) import Data.Char ( toLower, toUpper, ord, isLower, isUpper ) @@ -729,9 +730,13 @@ refsMatch [] x = null x refsMatch x [] = null x -- --- Native format prettyprinting +-- Prettyprinting -- - + +-- | A version of hang that works like the version in pretty-1.0.0.0 +hang' :: Doc -> Int -> Doc -> Doc +hang' d1 n d2 = d1 $$ (nest n d2) + -- | Indent string as a block. indentBy :: Int -- ^ Number of spaces to indent the block -> Int -- ^ Number of spaces (rel to block) to indent first line diff --git a/Text/Pandoc/Writers/Markdown.hs b/Text/Pandoc/Writers/Markdown.hs index 787700603..8f703a7d5 100644 --- a/Text/Pandoc/Writers/Markdown.hs +++ b/Text/Pandoc/Writers/Markdown.hs @@ -95,7 +95,7 @@ noteToMarkdown :: WriterOptions -> Int -> [Block] -> State WriterState Doc noteToMarkdown opts num blocks = do contents <- blockListToMarkdown opts blocks let marker = text "[^" <> text (show num) <> text "]:" - return $ hang marker (writerTabStop opts) contents + return $ hang' marker (writerTabStop opts) contents -- | Escape special characters for Markdown. escapeString :: String -> String @@ -257,7 +257,7 @@ blockToMarkdown opts (DefinitionList items) = do bulletListItemToMarkdown :: WriterOptions -> [Block] -> State WriterState Doc bulletListItemToMarkdown opts items = do contents <- blockListToMarkdown opts items - return $ hang (text "- ") (writerTabStop opts) contents + return $ hang' (text "- ") (writerTabStop opts) contents -- | Convert ordered list item (a list of blocks) to markdown. orderedListItemToMarkdown :: WriterOptions -- ^ options diff --git a/Text/Pandoc/Writers/RST.hs b/Text/Pandoc/Writers/RST.hs index 460a11852..91826cbcd 100644 --- a/Text/Pandoc/Writers/RST.hs +++ b/Text/Pandoc/Writers/RST.hs @@ -100,8 +100,8 @@ notesToRST notes = noteToRST :: Int -> [Block] -> State WriterState Doc noteToRST num note = do contents <- blockListToRST note - let marker = text ".. [" <> text (show num) <> text "] " - return $ hang marker 3 contents + let marker = text ".. [" <> text (show num) <> text "]" + return $ marker $$ nest 3 contents -- | Return RST representation of picture reference table. pictTableToRST :: KeyTable -> State WriterState Doc @@ -169,7 +169,7 @@ blockToRST (Para inlines) = do return $ contents <> text "\n" blockToRST (RawHtml str) = let str' = if "\n" `isSuffixOf` str then str ++ "\n" else str ++ "\n\n" in - return $ hang (text "\n.. raw:: html\n") 3 $ vcat $ map text (lines str') + return $ (text "\n.. raw:: html\n") $$ (nest 3 $ vcat $ map text (lines str')) blockToRST HorizontalRule = return $ text "--------------\n" blockToRST (Header level inlines) = do contents <- inlineListToRST inlines @@ -236,7 +236,7 @@ blockToRST (DefinitionList items) = do bulletListItemToRST :: [Block] -> State WriterState Doc bulletListItemToRST items = do contents <- blockListToRST items - return $ hang (text "- ") 3 contents + return $ (text "- ") <> contents -- | Convert ordered list item (a list of blocks) to RST. orderedListItemToRST :: String -- ^ marker for list item @@ -244,7 +244,7 @@ orderedListItemToRST :: String -- ^ marker for list item -> State WriterState Doc orderedListItemToRST marker items = do contents <- blockListToRST items - return $ hang (text marker) (length marker + 1) contents + return $ (text marker <> char ' ') <> contents -- | Convert defintion list item (label, list of blocks) to RST. definitionListItemToRST :: ([Inline], [Block]) -> State WriterState Doc diff --git a/tests/writer.markdown b/tests/writer.markdown index 9c79bfb66..6bbfe257c 100644 --- a/tests/writer.markdown +++ b/tests/writer.markdown @@ -700,8 +700,10 @@ indented. [links](http://google.com) and `]` verbatim characters, as well as [bracketed text]. -[^4]: In quote. +[^4]: + In quote. -[^5]: In list. +[^5]: + In list. diff --git a/tests/writer.rst b/tests/writer.rst index 72877d7a7..408ca357c 100644 --- a/tests/writer.rst +++ b/tests/writer.rst @@ -621,7 +621,7 @@ LaTeX ===== -- +- - :math:`$2+2=4$` - :math:`$x \in y$` - :math:`$\alpha \wedge \omega$` @@ -819,11 +819,11 @@ note] Here is an inline note. [3]_ This paragraph should not be part of the note, as it is not indented. -.. [1] +.. [1] Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document. -.. [2] +.. [2] Here's the long note. This one contains multiple blocks. Subsequent blocks are indented to show that they belong to the @@ -836,14 +836,16 @@ indented. If you want, you can indent every line, but you can also be lazy and just indent the first line of each block. -.. [3] +.. [3] This is *easier* to type. Inline notes may contain `links <http://google.com>`_ and ``]`` verbatim characters, as well as [bracketed text]. -.. [4] In quote. +.. [4] + In quote. -.. [5] In list. +.. [5] + In list. .. |lalune| image:: lalune.jpg |