diff options
author | Niklas Haas <git@nand.wakku.to> | 2014-02-22 21:15:34 +0100 |
---|---|---|
committer | Niklas Haas <git@nand.wakku.to> | 2014-02-22 21:31:03 +0100 |
commit | fc7fd1875d31dbfd37eaa058177e534b4fc6bc25 (patch) | |
tree | 15cad6ae08c535594a452e67cbe2ddc785ba7676 /src/Haddock/Parser.hs | |
parent | 91e2c21cfdaca7913dbfec17bdd7712c0c1ed732 (diff) |
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.
Diffstat (limited to 'src/Haddock/Parser.hs')
-rw-r--r-- | src/Haddock/Parser.hs | 11 |
1 files changed, 10 insertions, 1 deletions
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) |