From fc7fd1875d31dbfd37eaa058177e534b4fc6bc25 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Sat, 22 Feb 2014 21:15:34 +0100 Subject: Strip a single leading space from bird tracks (#201) This makes bird tracks in the form > foo > bar > bat parse as if they had been written as >foo >bar >bat ie. without the leading whitespace in front of every line. Ideally we also want to look into how leading whitespace affects code blocks written using the @ @ syntax, which are currently unaffected by this patch. --- src/Haddock/Parser.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Haddock/Parser.hs b/src/Haddock/Parser.hs index e9bed2a5..a6ad817c 100644 --- a/src/Haddock/Parser.hs +++ b/src/Haddock/Parser.hs @@ -302,10 +302,19 @@ takeNonEmptyLine = do (++ "\n") . decodeUtf8 <$> (takeWhile1 (/= '\n') >>= nonSpace) <* "\n" birdtracks :: Parser (Doc a) -birdtracks = DocCodeBlock . DocString . intercalate "\n" <$> many1 line +birdtracks = DocCodeBlock . DocString . intercalate "\n" . stripSpace <$> many1 line where line = skipHorizontalSpace *> ">" *> takeLine +-- | Strip leading spaces, but ignore blank lines. If any of the lines don't +-- start with a ' ', however, we don't touch the block. +stripSpace :: [String] -> [String] +stripSpace = fromMaybe <*> mapM strip + where + strip (' ':xs) = Just xs + strip "" = Just "" + strip _ = Nothing + -- | Parses examples. Examples are a paragraph level entitity (separated by an empty line). -- Consecutive examples are accepted. examples :: Parser (Doc a) -- cgit v1.2.3