diff options
author | John MacFarlane <jgm@berkeley.edu> | 2013-04-09 18:12:33 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2013-04-09 18:12:54 -0700 |
commit | e938fc1ae21847b548884a96be62b0932b52c5c8 (patch) | |
tree | 19f49169bcd9ba49bfc26bbf0a5861bd52007372 | |
parent | ff6394171be99c369e1755cc585151a78f086509 (diff) | |
download | pandoc-e938fc1ae21847b548884a96be62b0932b52c5c8.tar.gz |
Fixed Haddock reader bugs with list item spaces and examples.
Closes #824.
-rw-r--r-- | src/Text/Pandoc/Readers/Haddock/Parse.y | 18 | ||||
-rw-r--r-- | tests/haddock-reader.native | 4 |
2 files changed, 10 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/Haddock/Parse.y b/src/Text/Pandoc/Readers/Haddock/Parse.y index 1486106b7..27185092c 100644 --- a/src/Text/Pandoc/Readers/Haddock/Parse.y +++ b/src/Text/Pandoc/Readers/Haddock/Parse.y @@ -16,9 +16,8 @@ import Text.Pandoc.Builder import Data.Generics (everywhere, mkT) import Data.Char (isSpace) import Data.Maybe (fromMaybe) -import Data.List (stripPrefix) -import Data.Monoid (mempty) -import Data.Sequence (viewr, ViewR(..)) +import Data.List (stripPrefix, intersperse) +import Data.Monoid (mempty, mconcat) } %expect 0 @@ -72,7 +71,7 @@ olpara :: { Blocks } : '(n)' para { $2 } defpara :: { (Inlines, [Blocks]) } - : '[' seq ']' seq { ($2, [plain $4]) } + : '[' seq ']' seq { (trimInlines $2, [plain $ trimInlines $4]) } para :: { Blocks } : seq { para' $1 } @@ -130,10 +129,7 @@ happyError :: [LToken] -> Either [LToken] a happyError toks = Left toks para' :: Inlines -> Blocks -para' (Many ils) = - case viewr ils of - ils' :> Space -> para $ Many ils' - _ -> para $ Many ils +para' = para . trimInlines monospace :: Inlines -> Inlines monospace = everywhere (mkT go) @@ -161,8 +157,9 @@ makeProperty s = case strip s of -- | Create an 'Example', stripping superfluous characters as appropriate makeExample :: String -> String -> [String] -> Blocks makeExample prompt expression result = - para $ codeWith ([], ["haskell", "expr"], []) (strip expression ++ "\n") - <> codeWith ([], ["result"], []) (unlines result') + para $ codeWith ([], ["haskell","expr"], []) (strip expression) + <> linebreak + <> (mconcat $ intersperse linebreak $ map coder result') where -- 1. drop trailing whitespace from the prompt, remember the prefix (prefix, _) = span isSpace prompt @@ -178,6 +175,7 @@ makeExample prompt expression result = substituteBlankLine "<BLANKLINE>" = "" substituteBlankLine line = line + coder = codeWith ([], ["result"], []) -- | Remove all leading and trailing whitespace strip :: String -> String diff --git a/tests/haddock-reader.native b/tests/haddock-reader.native index 0214d714f..fdf0c1656 100644 --- a/tests/haddock-reader.native +++ b/tests/haddock-reader.native @@ -6,10 +6,10 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []}) ,Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "code",Space,Str "block:"] ,CodeBlock ("",["haskell"],[]) " map :: (a -> b) -> [a] -> [b]\n map _ [] = []\n map f (x:xs) = f x : map f xs\n" ,Para [Str "This",Space,Str "is",Space,Str "another",Space,Str "code",Space,Str "block:"] -,Para [Space,Code ("",[],[]) "f",Space,Code ("",[],[]) "x",Space,Code ("",[],[]) "=",Space,Code ("",[],[]) "x",Space,Code ("",[],[]) "+",Space,Code ("",[],[]) "x.",Space,Code ("",[],[]) "The",Space,Code ("",[],[]) "@...@",Space,Code ("",[],[]) "code",Space,Code ("",[],[]) "block",Space,Emph [Code ("",[],[]) "interprets markup normally"],Code ("",[],[]) ".",Space,Code ("",["haskell"],[]) "Module.Foo",Space,Code ("",[],[]) "\"Hello",Space,Code ("",[],[]) "World\""] +,Para [Code ("",[],[]) "f",Space,Code ("",[],[]) "x",Space,Code ("",[],[]) "=",Space,Code ("",[],[]) "x",Space,Code ("",[],[]) "+",Space,Code ("",[],[]) "x.",Space,Code ("",[],[]) "The",Space,Code ("",[],[]) "@...@",Space,Code ("",[],[]) "code",Space,Code ("",[],[]) "block",Space,Emph [Code ("",[],[]) "interprets markup normally"],Code ("",[],[]) ".",Space,Code ("",["haskell"],[]) "Module.Foo",Space,Code ("",[],[]) "\"Hello",Space,Code ("",[],[]) "World\""] ,Para [Str "Haddock",Space,Str "supports",Space,Str "REPL",Space,Str "examples:"] ,Para [Code ("",["haskell","expr"],[]) "fib 10",LineBreak,Code ("",["result"],[]) "55"] -,Para [Code ("",["haskell","expr"],[]) "putStrLn \"foo\\nbar\"\n",Code ("",["result"],[]) "foo",LineBreak,Code ("",["result"],[]) "bar"] +,Para [Code ("",["haskell","expr"],[]) "putStrLn \"foo\\nbar\"",LineBreak,Code ("",["result"],[]) "foo",LineBreak,Code ("",["result"],[]) "bar"] ,Para [Str "That",Space,Str "was",Space,Emph [Str "really cool"],Str "!",Space,Str "I",Space,Str "had",Space,Str "no",Space,Str "idea",Space,Code ("",[],[]) "fib",Space,Code ("",[],[]) "10",Space,Code ("",[],[]) "=",Space,Code ("",[],[]) "55",Str "."] ,Para [Str "This",Space,Str "module",Space,Str "defines",Space,Str "the",Space,Str "type",Space,Code ("",["haskell"],[]) "T",Str ".",Space,Str "The",Space,Str "identifier",Space,Code ("",["haskell"],[]) "M.T",Space,Str "is",Space,Str "not",Space,Str "in",Space,Str "scope",Space,Str "I",Space,Str "don't",Space,Str "have",Space,Str "to",Space,Str "escape",Space,Str "my",Space,Str "apostrophes;",Space,Str "great,",Space,Str "isn't",Space,Str "it?",Space,Str "This",Space,Str "is",Space,Str "a",Space,Str "reference",Space,Str "to",Space,Str "the",Space,Code ("",["haskell"],[]) "Foo",Space,Str "module."] ,Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "bulleted",Space,Str "list:"] |