diff options
author | Simon Hengel <sol@typeful.net> | 2014-11-02 12:07:24 +0800 |
---|---|---|
committer | Simon Hengel <sol@typeful.net> | 2014-11-03 09:34:19 +0800 |
commit | 58a5683d1ce759f80ca7eb3b35663b717ae2abd5 (patch) | |
tree | b78a8dfa6df0d1bce5ea7d3a30edf28ba37ba6b6 /haddock-library/src/Documentation/Haddock/Parser.hs | |
parent | 77ed6a63df3d2653401f1869f116c8854021a71e (diff) |
Allow markdown links at the beginning of a paragraph
Diffstat (limited to 'haddock-library/src/Documentation/Haddock/Parser.hs')
-rw-r--r-- | haddock-library/src/Documentation/Haddock/Parser.hs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs index e53597eb..f1fd5dda 100644 --- a/haddock-library/src/Documentation/Haddock/Parser.hs +++ b/haddock-library/src/Documentation/Haddock/Parser.hs @@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ViewPatterns #-} -- | -- Module : Documentation.Haddock.Parser -- Copyright : (c) Mateusz Kowalczyk 2013-2014, @@ -217,8 +218,9 @@ paragraph = examples <|> skipSpace *> ( <|> codeblock <|> property <|> header + <|> textParagraphThatStartsWithMarkdownLink <|> definitionList - <|> textParagraph + <|> docParagraph <$> textParagraph ) -- | Headers inside the comment denoted with @=@ signs, up to 6 levels @@ -238,7 +240,21 @@ header = do return $ DocHeader (Header (length delim) line) `docAppend` rest textParagraph :: Parser (DocH mod Identifier) -textParagraph = docParagraph . parseString . intercalate "\n" <$> many1 nonEmptyLine +textParagraph = parseString . intercalate "\n" <$> many1 nonEmptyLine + +textParagraphThatStartsWithMarkdownLink :: Parser (DocH mod Identifier) +textParagraphThatStartsWithMarkdownLink = docParagraph <$> (docAppend <$> markdownLink <*> optionalTextParagraph) + where + optionalTextParagraph :: Parser (DocH mod Identifier) + optionalTextParagraph = (docAppend <$> whitespace <*> textParagraph) <|> pure DocEmpty + + whitespace :: Parser (DocH mod a) + whitespace = DocString <$> (f <$> takeHorizontalSpace <*> optional "\n") + where + f :: BS.ByteString -> Maybe BS.ByteString -> String + f xs (fromMaybe "" -> x) + | BS.null (xs <> x) = "" + | otherwise = " " -- | Parses unordered (bullet) lists. unorderedList :: Parser (DocH mod Identifier) |