From 39a7a1b9e344bfa3258a6414e75f19c1eabc30de Mon Sep 17 00:00:00 2001 From: Ɓukasz Hanuszczak Date: Wed, 27 May 2015 11:51:31 +0200 Subject: Create simple method for indentation parsing. --- haddock-library/src/Documentation/Haddock/Parser.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'haddock-library') diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs index 5c607a1a..6bb88035 100644 --- a/haddock-library/src/Documentation/Haddock/Parser.hs +++ b/haddock-library/src/Documentation/Haddock/Parser.hs @@ -382,6 +382,15 @@ takeNonEmptyLine :: Parser String takeNonEmptyLine = do (++ "\n") . decodeUtf8 <$> (takeWhile1 (/= '\n') >>= nonSpace) <* "\n" +-- | Takes indentation of first non-empty line. +-- +-- More precisely: skips all whitespace-only lines and returns indentation +-- (horizontal space, might be empty) of that non-empty line. +takeIndent :: Parser BS.ByteString +takeIndent = do + indent <- takeHorizontalSpace + "\n" *> takeIndent <|> return indent + -- | Blocks of text of the form: -- -- >> foo -- cgit v1.2.3