From 30969974f065710d3abc8dcfcce92a84af32f1d9 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 28 Mar 2013 20:07:57 -0700 Subject: Haddock writer: use 'text' builder instead of 'str'. This articulates strings into Str, Space, allowing them to be hard-wrapped intelligently by the writers. This patch also fixes a bug with trailing spaces and newlines. (See #806.) --- src/Text/Pandoc/Readers/Haddock/Parse.y | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Haddock/Parse.y b/src/Text/Pandoc/Readers/Haddock/Parse.y index 065b9997f..26d7c287d 100644 --- a/src/Text/Pandoc/Readers/Haddock/Parse.y +++ b/src/Text/Pandoc/Readers/Haddock/Parse.y @@ -18,6 +18,7 @@ import Data.Char (isSpace) import Data.Maybe (fromMaybe) import Data.List (stripPrefix) import Data.Monoid (mempty) +import Data.Sequence (viewr, ViewR(..)) } %expect 0 @@ -74,7 +75,7 @@ defpara :: { (Inlines, [Blocks]) } : '[' seq ']' seq { ($2, [plain $4]) } para :: { Blocks } - : seq { para $1 } + : seq { para' $1 } | codepara { codeBlock $1 } | property { $1 } | examples { $1 } @@ -112,7 +113,7 @@ seq1 :: { Inlines } | elem1 { $1 } elem1 :: { Inlines } - : STRING { str $1 } + : STRING { text $1 } | '/../' { emph (str $1) } | URL { makeHyperlink $1 } | PIC { image $1 $1 mempty } @@ -128,7 +129,13 @@ strings :: { String } happyError :: [LToken] -> Maybe a happyError toks = Nothing -monospace :: Inlines -> Inlines +para' :: Inlines -> Blocks +para' (Many ils) = + case viewr ils of + ils' :> Space -> para $ Many ils' + _ -> para $ Many ils + +monospace :: Inlines -> Inlines monospace = everywhere (mkT go) where go (Str s) = Code nullAttr s -- cgit v1.2.3