git.iko.soy/typeable/pandoc
on master help sign in
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

commit751aa15abcf945a40f4169a9e6a8640c36a801a5 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateWed 17 Dec 2008, 15:34 (18 years ago) parent9ff729f
5 files changed+28−19
Text/Pandoc/Shared.hs+9−4 Text/Pandoc/Writers/Markdown.hs+2−2 Text/Pandoc/Writers/RST.hs+5−5 tests/writer.markdown+4−2 tests/writer.rst+8−6
Text/Pandoc/Shared.hs+9−4
@@ -87,7 +87,8 @@ module Text.Pandoc.Shared (
8787 KeyTable,
8888 lookupKeySrc,
8989 refsMatch,
90− -- * Native format prettyprinting
90+ -- * Prettyprinting
91+ hang',
9192 prettyPandoc,
9293 -- * Pandoc block and inline list processing
9394 orderedListMarkers,
@@ -106,7 +107,7 @@ module Text.Pandoc.Shared (
106107
107108import Text.Pandoc.Definition
108109import Text.ParserCombinators.Parsec
109−import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text )
110+import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text, nest )
110111import qualified Text.PrettyPrint.HughesPJ as PP
111112import Text.Pandoc.CharacterReferences ( characterReference )
112113import Data.Char ( toLower, toUpper, ord, isLower, isUpper )
@@ -729,9 +730,13 @@ refsMatch [] x = null x
729730refsMatch x [] = null x
730731
731732--
732−-- Native format prettyprinting
733+-- Prettyprinting
733734--
734−
735+
736+-- | A version of hang that works like the version in pretty-1.0.0.0
737+hang' :: Doc -> Int -> Doc -> Doc
738+hang' d1 n d2 = d1 $$ (nest n d2)
739+
735740-- | Indent string as a block.
736741indentBy :: Int -- ^ Number of spaces to indent the block
737742 -> Int -- ^ Number of spaces (rel to block) to indent first line
Text/Pandoc/Writers/Markdown.hs+2−2
@@ -95,7 +95,7 @@ noteToMarkdown :: WriterOptions -> Int -> [Block] -> State WriterState Doc
9595noteToMarkdown opts num blocks = do
9696 contents <- blockListToMarkdown opts blocks
9797 let marker = text "[^" <> text (show num) <> text "]:"
98− return $ hang marker (writerTabStop opts) contents
98+ return $ hang' marker (writerTabStop opts) contents
9999
100100-- | Escape special characters for Markdown.
101101escapeString :: String -> String
@@ -257,7 +257,7 @@ blockToMarkdown opts (DefinitionList items) = do
257257bulletListItemToMarkdown :: WriterOptions -> [Block] -> State WriterState Doc
258258bulletListItemToMarkdown opts items = do
259259 contents <- blockListToMarkdown opts items
260− return $ hang (text "- ") (writerTabStop opts) contents
260+ return $ hang' (text "- ") (writerTabStop opts) contents
261261
262262-- | Convert ordered list item (a list of blocks) to markdown.
263263orderedListItemToMarkdown :: WriterOptions -- ^ options
Text/Pandoc/Writers/RST.hs+5−5
@@ -100,8 +100,8 @@ notesToRST notes =
100100noteToRST :: Int -> [Block] -> State WriterState Doc
101101noteToRST num note = do
102102 contents <- blockListToRST note
103− let marker = text ".. [" <> text (show num) <> text "] "
104− return $ hang marker 3 contents
103+ let marker = text ".. [" <> text (show num) <> text "]"
104+ return $ marker $$ nest 3 contents
105105
106106-- | Return RST representation of picture reference table.
107107pictTableToRST :: KeyTable -> State WriterState Doc
@@ -169,7 +169,7 @@ blockToRST (Para inlines) = do
169169 return $ contents <> text "\n"
170170blockToRST (RawHtml str) =
171171 let str' = if "\n" `isSuffixOf` str then str ++ "\n" else str ++ "\n\n" in
172− return $ hang (text "\n.. raw:: html\n") 3 $ vcat $ map text (lines str')
172+ return $ (text "\n.. raw:: html\n") $$ (nest 3 $ vcat $ map text (lines str'))
173173blockToRST HorizontalRule = return $ text "--------------\n"
174174blockToRST (Header level inlines) = do
175175 contents <- inlineListToRST inlines
@@ -236,7 +236,7 @@ blockToRST (DefinitionList items) = do
236236bulletListItemToRST :: [Block] -> State WriterState Doc
237237bulletListItemToRST items = do
238238 contents <- blockListToRST items
239− return $ hang (text "- ") 3 contents
239+ return $ (text "- ") <> contents
240240
241241-- | Convert ordered list item (a list of blocks) to RST.
242242orderedListItemToRST :: String -- ^ marker for list item
@@ -244,7 +244,7 @@ orderedListItemToRST :: String -- ^ marker for list item
244244 -> State WriterState Doc
245245orderedListItemToRST marker items = do
246246 contents <- blockListToRST items
247− return $ hang (text marker) (length marker + 1) contents
247+ return $ (text marker <> char ' ') <> contents
248248
249249-- | Convert defintion list item (label, list of blocks) to RST.
250250definitionListItemToRST :: ([Inline], [Block]) -> State WriterState Doc
tests/writer.markdown+4−2
@@ -700,8 +700,10 @@ indented.
700700 [links](http://google.com) and `]` verbatim characters, as well as
701701 [bracketed text].
702702
703−[^4]: In quote.
703+[^4]:
704+ In quote.
704705
705−[^5]: In list.
706+[^5]:
707+ In list.
706708
707709
tests/writer.rst+8−6
@@ -621,7 +621,7 @@ LaTeX
621621=====
622622
623623
624−-
624+-
625625- :math:`$2+2=4$`
626626- :math:`$x \in y$`
627627- :math:`$\alpha \wedge \omega$`
@@ -819,11 +819,11 @@ note] Here is an inline note. [3]_
819819This paragraph should not be part of the note, as it is not
820820indented.
821821
822−.. [1]
822+.. [1]
823823 Here is the footnote. It can go anywhere after the footnote
824824 reference. It need not be placed at the end of the document.
825825
826−.. [2]
826+.. [2]
827827 Here's the long note. This one contains multiple blocks.
828828
829829 Subsequent blocks are indented to show that they belong to the
@@ -836,14 +836,16 @@ indented.
836836 If you want, you can indent every line, but you can also be lazy
837837 and just indent the first line of each block.
838838
839−.. [3]
839+.. [3]
840840 This is *easier* to type. Inline notes may contain
841841 `links <http://google.com>`_ and ``]`` verbatim characters, as well
842842 as [bracketed text].
843843
844−.. [4] In quote.
844+.. [4]
845+ In quote.
845846
846−.. [5] In list.
847+.. [5]
848+ In list.
847849
848850
849851.. |lalune| image:: lalune.jpg