diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-03-28 20:07:57 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-03-28 20:09:06 -0700 |
commit | 30969974f065710d3abc8dcfcce92a84af32f1d9 (patch) | |
tree | b4594ec315d9c7198dd014b6443ecfa7555104b0 | |
parent | 38e35aaeda093cad8690fc4ef412655d7fbdb418 (diff) | |
download | pandoc-30969974f065710d3abc8dcfcce92a84af32f1d9.tar.gz |
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.)
-rw-r--r-- | src/Text/Pandoc/Readers/Haddock/Parse.y | 13 |
1 files changed, 10 insertions, 3 deletions
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 |