aboutsummaryrefslogtreecommitdiff
path: root/haddock-library
diff options
context:
space:
mode:
Diffstat (limited to 'haddock-library')
-rw-r--r--haddock-library/CHANGES.md7
-rw-r--r--haddock-library/haddock-library.cabal2
-rw-r--r--haddock-library/src/CompatPrelude.hs3
-rw-r--r--haddock-library/src/Documentation/Haddock/Markup.hs2
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser.hs26
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser/Identifier.hs5
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser/Monad.hs4
-rw-r--r--haddock-library/src/Documentation/Haddock/Types.hs13
-rw-r--r--haddock-library/test/Documentation/Haddock/Parser/UtilSpec.hs3
-rw-r--r--haddock-library/test/Documentation/Haddock/ParserSpec.hs85
10 files changed, 93 insertions, 57 deletions
diff --git a/haddock-library/CHANGES.md b/haddock-library/CHANGES.md
index 5b400d7c..b3482209 100644
--- a/haddock-library/CHANGES.md
+++ b/haddock-library/CHANGES.md
@@ -1,3 +1,10 @@
+## Changes in version 1.11.0
+
+ * Add support for linking identifiers with a quote between backticks (#1408)
+
+## Changes in version 1.10.0
+
+ * Add support for labeled module references (#1360)
## Changes in version 1.9.0
* Fix build-time regression for `base < 4.7` (#1119)
diff --git a/haddock-library/haddock-library.cabal b/haddock-library/haddock-library.cabal
index f6d88c81..261cbb1f 100644
--- a/haddock-library/haddock-library.cabal
+++ b/haddock-library/haddock-library.cabal
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: haddock-library
-version: 1.9.0
+version: 1.10.0
synopsis: Library exposing some functionality of Haddock.
description: Haddock is a documentation-generation tool for Haskell
diff --git a/haddock-library/src/CompatPrelude.hs b/haddock-library/src/CompatPrelude.hs
index 60fa94d9..71a99559 100644
--- a/haddock-library/src/CompatPrelude.hs
+++ b/haddock-library/src/CompatPrelude.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE CPP #-}
-#if !MIN_VERSION_base(4,5,0)
+#ifdef __HLINT__
+#elif !MIN_VERSION_base(4,5,0)
# error This module doesn't provide compat-shims for versions prior to base-4.5
#endif
diff --git a/haddock-library/src/Documentation/Haddock/Markup.hs b/haddock-library/src/Documentation/Haddock/Markup.hs
index 0919737f..28c5c2ca 100644
--- a/haddock-library/src/Documentation/Haddock/Markup.hs
+++ b/haddock-library/src/Documentation/Haddock/Markup.hs
@@ -22,7 +22,7 @@ markup m (DocEmphasis d) = markupEmphasis m (markup m d)
markup m (DocBold d) = markupBold m (markup m d)
markup m (DocMonospaced d) = markupMonospaced m (markup m d)
markup m (DocUnorderedList ds) = markupUnorderedList m (map (markup m) ds)
-markup m (DocOrderedList ds) = markupOrderedList m (map (markup m) ds)
+markup m (DocOrderedList ds) = markupOrderedList m (map (\(index, a) -> (index, markup m a)) ds)
markup m (DocDefList ds) = markupDefList m (map (markupPair m) ds)
markup m (DocCodeBlock d) = markupCodeBlock m (markup m d)
markup m (DocHyperlink (Hyperlink u l)) = markupHyperlink m (Hyperlink u (fmap (markup m) l))
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs
index de336d45..19c92721 100644
--- a/haddock-library/src/Documentation/Haddock/Parser.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser.hs
@@ -78,7 +78,7 @@ overIdentifier f d = g d
g (DocMonospaced x) = DocMonospaced $ g x
g (DocBold x) = DocBold $ g x
g (DocUnorderedList x) = DocUnorderedList $ fmap g x
- g (DocOrderedList x) = DocOrderedList $ fmap g x
+ g (DocOrderedList x) = DocOrderedList $ fmap (\(index, a) -> (index, g a)) x
g (DocDefList x) = DocDefList $ fmap (\(y, z) -> (g y, g z)) x
g (DocCodeBlock x) = DocCodeBlock $ g x
g (DocHyperlink (Hyperlink u x)) = DocHyperlink (Hyperlink u (fmap g x))
@@ -173,11 +173,11 @@ encodedChar = "&#" *> c <* ";"
-- Once we have checked for any of these and tried to parse the
-- relevant markup, we can assume they are used as regular text.
specialChar :: [Char]
-specialChar = "_/<@\"&'`# "
+specialChar = "_/<@\"&'`#[ "
-- | Plain, regular parser for text. Called as one of the last parsers
-- to ensure that we have already given a chance to more meaningful parsers
--- before capturing their characers.
+-- before capturing their characters.
string' :: Parser (DocH mod a)
string' = DocString . unescape . T.unpack <$> takeWhile1_ (`notElem` specialChar)
where
@@ -361,7 +361,7 @@ table = do
firstRow <- parseFirstRow
let len = T.length firstRow
- -- then we parse all consequtive rows starting and ending with + or |,
+ -- then we parse all consecutive rows starting and ending with + or |,
-- of the width `len`.
restRows <- many (try (parseRestRows len))
@@ -577,10 +577,24 @@ unorderedList indent = DocUnorderedList <$> p
orderedList :: Text -> Parser (DocH mod Identifier)
orderedList indent = DocOrderedList <$> p
where
- p = (paren <|> dot) *> innerList indent p
+ p = do
+ index <- paren <|> dot
+ innerList' indent p index
dot = (decimal :: Parser Int) <* "."
paren = "(" *> decimal <* ")"
+-- | Like 'innerList' but takes the parsed index of the list item
+innerList' :: Text -> Parser [(Int, DocH mod Identifier)]
+ -> Int
+ -> Parser [(Int, DocH mod Identifier)]
+innerList' indent item index = do
+ c <- takeLine
+ (cs, items) <- more indent item
+ let contents = docParagraph . parseText . dropNLs . T.unlines $ c : cs
+ return $ case items of
+ Left p -> [(index, contents `docAppend` p)]
+ Right i -> (index, contents) : i
+
-- | Generic function collecting any further lines belonging to the
-- list entry and recursively collecting any further lists in the
-- same paragraph. Usually used as
@@ -710,7 +724,7 @@ stripSpace = fromMaybe <*> mapM strip'
Just (' ',t') -> Just t'
_ -> Nothing
--- | Parses examples. Examples are a paragraph level entitity (separated by an empty line).
+-- | Parses examples. Examples are a paragraph level entity (separated by an empty line).
-- Consecutive examples are accepted.
examples :: Parser (DocH mod a)
examples = DocExamples <$> (many (try (skipHorizontalSpace *> "\n")) *> go)
diff --git a/haddock-library/src/Documentation/Haddock/Parser/Identifier.hs b/haddock-library/src/Documentation/Haddock/Parser/Identifier.hs
index b8afb951..4c56be9b 100644
--- a/haddock-library/src/Documentation/Haddock/Parser/Identifier.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser/Identifier.hs
@@ -1,5 +1,4 @@
{-# LANGUAGE BangPatterns #-}
-{-# LANGUAGE ViewPatterns #-}
-- |
-- Module : Documentation.Haddock.Parser.Identifier
-- Copyright : (c) Alec Theriault 2019,
@@ -150,9 +149,9 @@ takeIdentifier input = listToMaybe $ do
| otherwise = Nothing
-- | Parse all but the last quote off the front of the input
- -- PRECONDITION: T.head t == '\''
+ -- PRECONDITION: T.head t `elem` ['\'', '`']
quotes :: Text -> (Int, Text)
- quotes t = let !n = T.length (T.takeWhile (== '\'') t) - 1
+ quotes t = let !n = T.length (T.takeWhile (`elem` ['\'', '`']) t) - 1
in (n, T.drop n t)
-- | Parse an operator off the front of the input
diff --git a/haddock-library/src/Documentation/Haddock/Parser/Monad.hs b/haddock-library/src/Documentation/Haddock/Parser/Monad.hs
index 2fa79961..8d6e7a1d 100644
--- a/haddock-library/src/Documentation/Haddock/Parser/Monad.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser/Monad.hs
@@ -1,10 +1,8 @@
-{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE BangPatterns #-}
-{-# LANGUAGE TypeSynonymInstances #-}
-- |
-- Module : Documentation.Haddock.Parser.Monad
-- Copyright : (c) Alec Theriault 2018-2019,
@@ -41,7 +39,7 @@ import Documentation.Haddock.Types ( Version )
import Prelude hiding (takeWhile)
import CompatPrelude
--- | The only bit of information we really care about truding along with us
+-- | The only bit of information we really care about trudging along with us
-- through parsing is the version attached to a @\@since@ annotation - if
-- the doc even contained one.
newtype ParserState = ParserState {
diff --git a/haddock-library/src/Documentation/Haddock/Types.hs b/haddock-library/src/Documentation/Haddock/Types.hs
index 252eb425..d72ab4b4 100644
--- a/haddock-library/src/Documentation/Haddock/Types.hs
+++ b/haddock-library/src/Documentation/Haddock/Types.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE CPP, DeriveFunctor, DeriveFoldable, DeriveTraversable #-}
+{-# LANGUAGE CPP, DeriveTraversable #-}
-- |
-- Module : Documentation.Haddock.Types
@@ -124,7 +124,7 @@ data DocH mod id
| DocMonospaced (DocH mod id)
| DocBold (DocH mod id)
| DocUnorderedList [DocH mod id]
- | DocOrderedList [DocH mod id]
+ | DocOrderedList [(Int, DocH mod id)]
| DocDefList [(DocH mod id, DocH mod id)]
| DocCodeBlock (DocH mod id)
| DocHyperlink (Hyperlink (DocH mod id))
@@ -154,7 +154,7 @@ instance Bifunctor DocH where
bimap f g (DocMonospaced doc) = DocMonospaced (bimap f g doc)
bimap f g (DocBold doc) = DocBold (bimap f g doc)
bimap f g (DocUnorderedList docs) = DocUnorderedList (map (bimap f g) docs)
- bimap f g (DocOrderedList docs) = DocOrderedList (map (bimap f g) docs)
+ bimap f g (DocOrderedList docs) = DocOrderedList (map (\(index, a) -> (index, bimap f g a)) docs)
bimap f g (DocDefList docs) = DocDefList (map (bimap f g *** bimap f g) docs)
bimap f g (DocCodeBlock doc) = DocCodeBlock (bimap f g doc)
bimap f g (DocHyperlink (Hyperlink url lbl)) = DocHyperlink (Hyperlink url (fmap (bimap f g) lbl))
@@ -180,7 +180,7 @@ instance Bifoldable DocH where
bifoldr f g z (DocMonospaced doc) = bifoldr f g z doc
bifoldr f g z (DocBold doc) = bifoldr f g z doc
bifoldr f g z (DocUnorderedList docs) = foldr (flip (bifoldr f g)) z docs
- bifoldr f g z (DocOrderedList docs) = foldr (flip (bifoldr f g)) z docs
+ bifoldr f g z (DocOrderedList docs) = foldr (flip (bifoldr f g)) z (map snd docs)
bifoldr f g z (DocDefList docs) = foldr (\(l, r) acc -> bifoldr f g (bifoldr f g acc l) r) z docs
bifoldr f g z (DocCodeBlock doc) = bifoldr f g z doc
bifoldr f g z (DocHeader (Header _ title)) = bifoldr f g z title
@@ -201,7 +201,8 @@ instance Bitraversable DocH where
bitraverse f g (DocMonospaced doc) = DocMonospaced <$> bitraverse f g doc
bitraverse f g (DocBold doc) = DocBold <$> bitraverse f g doc
bitraverse f g (DocUnorderedList docs) = DocUnorderedList <$> traverse (bitraverse f g) docs
- bitraverse f g (DocOrderedList docs) = DocOrderedList <$> traverse (bitraverse f g) docs
+ bitraverse f g (DocOrderedList docs) = DocOrderedList <$> traverseSnd (bitraverse f g) docs
+ where traverseSnd f' = traverse (\(x, a) -> (\b -> (x, b)) <$> f' a)
bitraverse f g (DocDefList docs) = DocDefList <$> traverse (bitraverse (bitraverse f g) (bitraverse f g)) docs
bitraverse f g (DocCodeBlock doc) = DocCodeBlock <$> bitraverse f g doc
bitraverse f g (DocHyperlink (Hyperlink url lbl)) = DocHyperlink <$> (Hyperlink url <$> traverse (bitraverse f g) lbl)
@@ -246,7 +247,7 @@ data DocMarkupH mod id a = Markup
, markupBold :: a -> a
, markupMonospaced :: a -> a
, markupUnorderedList :: [a] -> a
- , markupOrderedList :: [a] -> a
+ , markupOrderedList :: [(Int,a)] -> a
, markupDefList :: [(a,a)] -> a
, markupCodeBlock :: a -> a
, markupHyperlink :: Hyperlink a -> a
diff --git a/haddock-library/test/Documentation/Haddock/Parser/UtilSpec.hs b/haddock-library/test/Documentation/Haddock/Parser/UtilSpec.hs
index cb991763..716e1adc 100644
--- a/haddock-library/test/Documentation/Haddock/Parser/UtilSpec.hs
+++ b/haddock-library/test/Documentation/Haddock/Parser/UtilSpec.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Documentation.Haddock.Parser.UtilSpec (main, spec) where
@@ -5,7 +6,9 @@ import Documentation.Haddock.Parser.Monad
import Documentation.Haddock.Parser.Util
import Data.Either (isLeft)
import Test.Hspec
+#if !(MIN_VERSION_base(4,8,0))
import Control.Applicative
+#endif
main :: IO ()
main = hspec spec
diff --git a/haddock-library/test/Documentation/Haddock/ParserSpec.hs b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
index 5fa73ecd..1d227e57 100644
--- a/haddock-library/test/Documentation/Haddock/ParserSpec.hs
+++ b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
@@ -121,6 +121,9 @@ spec = do
it "can parse identifiers ending with a single quote" $ do
"'foo''" `shouldParseTo` DocIdentifier "foo'"
+ it "can parse identifiers in backticks ending with a single quote" $ do
+ "`foo'`" `shouldParseTo` DocIdentifier "foo'"
+
it "can parse an identifier containing a digit" $ do
"'f0'" `shouldParseTo` DocIdentifier "f0"
@@ -576,27 +579,37 @@ spec = do
it "turns it into a code block" $ do
"@foo@" `shouldParseTo` DocCodeBlock "foo"
- context "when a paragraph starts with a markdown link" $ do
- it "correctly parses it as a text paragraph (not a definition list)" $ do
- "[label](url)" `shouldParseTo`
- DocParagraph (hyperlink "url" "label")
+ context "when a paragraph contains a markdown link" $ do
+ it "correctly parses the link" $ do
+ "Blah [label](url)" `shouldParseTo`
+ DocParagraph ("Blah " <> hyperlink "url" "label")
- it "can be followed by an other paragraph" $ do
- "[label](url)\n\nfoobar" `shouldParseTo`
- DocParagraph (hyperlink "url" "label") <> DocParagraph "foobar"
+ context "when the paragraph starts with the markdown link" $ do
+ it "correctly parses it as a text paragraph (not a definition list)" $ do
+ "[label](url)" `shouldParseTo`
+ DocParagraph (hyperlink "url" "label")
- context "when paragraph contains additional text" $ do
- it "accepts more text after the link" $ do
- "[label](url) foo bar baz" `shouldParseTo`
- DocParagraph (hyperlink "url" "label" <> " foo bar baz")
+ it "can be followed by an other paragraph" $ do
+ "[label](url)\n\nfoobar" `shouldParseTo`
+ DocParagraph (hyperlink "url" "label") <> DocParagraph "foobar"
- it "accepts a newline right after the markdown link" $ do
- "[label](url)\nfoo bar baz" `shouldParseTo`
- DocParagraph (hyperlink "url" "label" <> " foo bar baz")
+ context "when paragraph contains additional text" $ do
+ it "accepts more text after the link" $ do
+ "[label](url) foo bar baz" `shouldParseTo`
+ DocParagraph (hyperlink "url" "label" <> " foo bar baz")
- it "can be followed by an other paragraph" $ do
- "[label](url)foo\n\nbar" `shouldParseTo`
- DocParagraph (hyperlink "url" "label" <> "foo") <> DocParagraph "bar"
+ it "accepts a newline right after the markdown link" $ do
+ "[label](url)\nfoo bar baz" `shouldParseTo`
+ DocParagraph (hyperlink "url" "label" <> " foo bar baz")
+
+ it "can be followed by an other paragraph" $ do
+ "[label](url)foo\n\nbar" `shouldParseTo`
+ DocParagraph (hyperlink "url" "label" <> "foo") <> DocParagraph "bar"
+
+ context "when the link starts on a new line not at the beginning of the paragraph" $ do
+ it "correctly parses the link" $ do
+ "Bla\n[label](url)" `shouldParseTo`
+ DocParagraph ("Bla\n" <> hyperlink "url" "label")
context "when parsing birdtracks" $ do
it "parses them as a code block" $ do
@@ -810,7 +823,7 @@ spec = do
it "can nest another type of list inside" $ do
"* foo\n\n 1. bar" `shouldParseTo`
DocUnorderedList [ DocParagraph "foo"
- <> DocOrderedList [DocParagraph "bar"]]
+ <> DocOrderedList [(1, DocParagraph "bar")]]
it "can nest a code block inside" $ do
"* foo\n\n @foo bar baz@" `shouldParseTo`
@@ -849,7 +862,7 @@ spec = do
DocUnorderedList [ DocParagraph "foo"
<> DocUnorderedList [ DocParagraph "bar" ]
]
- <> DocOrderedList [ DocParagraph "baz" ]
+ <> DocOrderedList [ (1, DocParagraph "baz") ]
it "allows arbitrary initial indent of a list" $ do
unlines
@@ -873,20 +886,20 @@ spec = do
DocDefList [ ("foo", "foov"
<> DocDefList [ ("bar", "barv") ])
]
- <> DocOrderedList [ DocParagraph "baz" ]
+ <> DocOrderedList [ (1, DocParagraph "baz") ]
it "list order is preserved in presence of nesting + extra text" $ do
"1. Foo\n\n > Some code\n\n2. Bar\n\nSome text"
`shouldParseTo`
- DocOrderedList [ DocParagraph "Foo" <> DocCodeBlock "Some code"
- , DocParagraph "Bar"
+ DocOrderedList [ (1, DocParagraph "Foo" <> DocCodeBlock "Some code")
+ , (2, DocParagraph "Bar")
]
<> DocParagraph (DocString "Some text")
"1. Foo\n\n2. Bar\n\nSome text"
`shouldParseTo`
- DocOrderedList [ DocParagraph "Foo"
- , DocParagraph "Bar"
+ DocOrderedList [ (1, DocParagraph "Foo")
+ , (2, DocParagraph "Bar")
]
<> DocParagraph (DocString "Some text")
@@ -970,9 +983,9 @@ spec = do
, " 3. three"
]
`shouldParseTo` DocOrderedList [
- DocParagraph "one"
- , DocParagraph "two"
- , DocParagraph "three"
+ (1, DocParagraph "one")
+ , (1, DocParagraph "two")
+ , (3, DocParagraph "three")
]
it "ignores empty lines between list items" $ do
@@ -982,12 +995,12 @@ spec = do
, "2. two"
]
`shouldParseTo` DocOrderedList [
- DocParagraph "one"
- , DocParagraph "two"
+ (1, DocParagraph "one")
+ , (2, DocParagraph "two")
]
it "accepts an empty list item" $ do
- "1." `shouldParseTo` DocOrderedList [DocParagraph DocEmpty]
+ "1." `shouldParseTo` DocOrderedList [(1, DocParagraph DocEmpty)]
it "accepts multi-line list items" $ do
unlines [
@@ -997,12 +1010,12 @@ spec = do
, "more two"
]
`shouldParseTo` DocOrderedList [
- DocParagraph "point one\n more one"
- , DocParagraph "point two\nmore two"
+ (1, DocParagraph "point one\n more one")
+ , (1, DocParagraph "point two\nmore two")
]
it "accepts markup in list items" $ do
- "1. /foo/" `shouldParseTo` DocOrderedList [DocParagraph (DocEmphasis "foo")]
+ "1. /foo/" `shouldParseTo` DocOrderedList [(1, DocParagraph (DocEmphasis "foo"))]
it "requires empty lines between list and other paragraphs" $ do
unlines [
@@ -1012,7 +1025,7 @@ spec = do
, ""
, "baz"
]
- `shouldParseTo` DocParagraph "foo" <> DocOrderedList [DocParagraph "bar"] <> DocParagraph "baz"
+ `shouldParseTo` DocParagraph "foo" <> DocOrderedList [(1, DocParagraph "bar")] <> DocParagraph "baz"
context "when parsing definition lists" $ do
it "parses a simple list" $ do
@@ -1099,8 +1112,8 @@ spec = do
] `shouldParseTo`
DocUnorderedList [ DocParagraph "bullet"
, DocParagraph "different bullet"]
- <> DocOrderedList [ DocParagraph "ordered"
- , DocParagraph "different bullet"
+ <> DocOrderedList [ (1, DocParagraph "ordered")
+ , (2, DocParagraph "different bullet")
]
<> DocDefList [ ("cat", "kitten")
, ("pineapple", "fruit")