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
751aa15fiddlosopher
Text/Pandoc/Shared.hs+9−4
@@ -87,7 +87,8 @@ module Text.Pandoc.Shared (
87 KeyTable,
87 KeyTable,
88 lookupKeySrc,
88 lookupKeySrc,
89 refsMatch,
89 refsMatch,
90− -- * Native format prettyprinting
90+ -- * Prettyprinting
91+ hang',
91 prettyPandoc,
92 prettyPandoc,
92 -- * Pandoc block and inline list processing
93 -- * Pandoc block and inline list processing
93 orderedListMarkers,
94 orderedListMarkers,
@@ -106,7 +107,7 @@ module Text.Pandoc.Shared (
106
107
107import Text.Pandoc.Definition
108import Text.Pandoc.Definition
108import Text.ParserCombinators.Parsec
109import Text.ParserCombinators.Parsec
109−import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text )
110+import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text, nest )
110import qualified Text.PrettyPrint.HughesPJ as PP
111import qualified Text.PrettyPrint.HughesPJ as PP
111import Text.Pandoc.CharacterReferences ( characterReference )
112import Text.Pandoc.CharacterReferences ( characterReference )
112import Data.Char ( toLower, toUpper, ord, isLower, isUpper )
113import Data.Char ( toLower, toUpper, ord, isLower, isUpper )
@@ -729,9 +730,13 @@ refsMatch [] x = null x
729refsMatch x [] = null x
730refsMatch x [] = null x
730
731
731--
732--
732−-- Native format prettyprinting
733+-- Prettyprinting
733--
734--
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+
735-- | Indent string as a block.
740-- | Indent string as a block.
736indentBy :: Int -- ^ Number of spaces to indent the block
741indentBy :: Int -- ^ Number of spaces to indent the block
737 -> Int -- ^ Number of spaces (rel to block) to indent first line
742 -> 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
95noteToMarkdown opts num blocks = do
95noteToMarkdown opts num blocks = do
96 contents <- blockListToMarkdown opts blocks
96 contents <- blockListToMarkdown opts blocks
97 let marker = text "[^" <> text (show num) <> text "]:"
97 let marker = text "[^" <> text (show num) <> text "]:"
98− return $ hang marker (writerTabStop opts) contents
98+ return $ hang' marker (writerTabStop opts) contents
99
99
100-- | Escape special characters for Markdown.
100-- | Escape special characters for Markdown.
101escapeString :: String -> String
101escapeString :: String -> String
@@ -257,7 +257,7 @@ blockToMarkdown opts (DefinitionList items) = do
257bulletListItemToMarkdown :: WriterOptions -> [Block] -> State WriterState Doc
257bulletListItemToMarkdown :: WriterOptions -> [Block] -> State WriterState Doc
258bulletListItemToMarkdown opts items = do
258bulletListItemToMarkdown opts items = do
259 contents <- blockListToMarkdown opts items
259 contents <- blockListToMarkdown opts items
260− return $ hang (text "- ") (writerTabStop opts) contents
260+ return $ hang' (text "- ") (writerTabStop opts) contents
261
261
262-- | Convert ordered list item (a list of blocks) to markdown.
262-- | Convert ordered list item (a list of blocks) to markdown.
263orderedListItemToMarkdown :: WriterOptions -- ^ options
263orderedListItemToMarkdown :: WriterOptions -- ^ options
Text/Pandoc/Writers/RST.hs+5−5
@@ -100,8 +100,8 @@ notesToRST notes =
100noteToRST :: Int -> [Block] -> State WriterState Doc
100noteToRST :: Int -> [Block] -> State WriterState Doc
101noteToRST num note = do
101noteToRST num note = do
102 contents <- blockListToRST note
102 contents <- blockListToRST note
103− let marker = text ".. [" <> text (show num) <> text "] "
103+ let marker = text ".. [" <> text (show num) <> text "]"
104− return $ hang marker 3 contents
104+ return $ marker $$ nest 3 contents
105
105
106-- | Return RST representation of picture reference table.
106-- | Return RST representation of picture reference table.
107pictTableToRST :: KeyTable -> State WriterState Doc
107pictTableToRST :: KeyTable -> State WriterState Doc
@@ -169,7 +169,7 @@ blockToRST (Para inlines) = do
169 return $ contents <> text "\n"
169 return $ contents <> text "\n"
170blockToRST (RawHtml str) =
170blockToRST (RawHtml str) =
171 let str' = if "\n" `isSuffixOf` str then str ++ "\n" else str ++ "\n\n" in
171 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'))
173blockToRST HorizontalRule = return $ text "--------------\n"
173blockToRST HorizontalRule = return $ text "--------------\n"
174blockToRST (Header level inlines) = do
174blockToRST (Header level inlines) = do
175 contents <- inlineListToRST inlines
175 contents <- inlineListToRST inlines
@@ -236,7 +236,7 @@ blockToRST (DefinitionList items) = do
236bulletListItemToRST :: [Block] -> State WriterState Doc
236bulletListItemToRST :: [Block] -> State WriterState Doc
237bulletListItemToRST items = do
237bulletListItemToRST items = do
238 contents <- blockListToRST items
238 contents <- blockListToRST items
239− return $ hang (text "- ") 3 contents
239+ return $ (text "- ") <> contents
240
240
241-- | Convert ordered list item (a list of blocks) to RST.
241-- | Convert ordered list item (a list of blocks) to RST.
242orderedListItemToRST :: String -- ^ marker for list item
242orderedListItemToRST :: String -- ^ marker for list item
@@ -244,7 +244,7 @@ orderedListItemToRST :: String -- ^ marker for list item
244 -> State WriterState Doc
244 -> State WriterState Doc
245orderedListItemToRST marker items = do
245orderedListItemToRST marker items = do
246 contents <- blockListToRST items
246 contents <- blockListToRST items
247− return $ hang (text marker) (length marker + 1) contents
247+ return $ (text marker <> char ' ') <> contents
248
248
249-- | Convert defintion list item (label, list of blocks) to RST.
249-- | Convert defintion list item (label, list of blocks) to RST.
250definitionListItemToRST :: ([Inline], [Block]) -> State WriterState Doc
250definitionListItemToRST :: ([Inline], [Block]) -> State WriterState Doc
tests/writer.markdown+4−2
@@ -700,8 +700,10 @@ indented.
700 [links](http://google.com) and `]` verbatim characters, as well as
700 [links](http://google.com) and `]` verbatim characters, as well as
701 [bracketed text].
701 [bracketed text].
702
702
703+[^4]:
703−[^4]: In quote.
704+ In quote.
704
705
706+[^5]:
705−[^5]: In list.
707+ In list.
706
708
707
709
tests/writer.rst+8−6
@@ -621,7 +621,7 @@ LaTeX
621=====
621=====
622
622
623
623
624−-
624+-
625- :math:`$2+2=4$`
625- :math:`$2+2=4$`
626- :math:`$x \in y$`
626- :math:`$x \in y$`
627- :math:`$\alpha \wedge \omega$`
627- :math:`$\alpha \wedge \omega$`
@@ -819,11 +819,11 @@ note] Here is an inline note. [3]_
819This paragraph should not be part of the note, as it is not
819This paragraph should not be part of the note, as it is not
820indented.
820indented.
821
821
822−.. [1]
822+.. [1]
823 Here is the footnote. It can go anywhere after the footnote
823 Here is the footnote. It can go anywhere after the footnote
824 reference. It need not be placed at the end of the document.
824 reference. It need not be placed at the end of the document.
825
825
826−.. [2]
826+.. [2]
827 Here's the long note. This one contains multiple blocks.
827 Here's the long note. This one contains multiple blocks.
828
828
829 Subsequent blocks are indented to show that they belong to the
829 Subsequent blocks are indented to show that they belong to the
@@ -836,14 +836,16 @@ indented.
836 If you want, you can indent every line, but you can also be lazy
836 If you want, you can indent every line, but you can also be lazy
837 and just indent the first line of each block.
837 and just indent the first line of each block.
838
838
839−.. [3]
839+.. [3]
840 This is *easier* to type. Inline notes may contain
840 This is *easier* to type. Inline notes may contain
841 `links <http://google.com>`_ and ``]`` verbatim characters, as well
841 `links <http://google.com>`_ and ``]`` verbatim characters, as well
842 as [bracketed text].
842 as [bracketed text].
843
843
844+.. [4]
844−.. [4] In quote.
845+ In quote.
845
846
847+.. [5]
846−.. [5] In list.
848+ In list.
847
849
848
850
849.. |lalune| image:: lalune.jpg
851.. |lalune| image:: lalune.jpg