aboutsummaryrefslogtreecommitdiff
path: root/haddock-library
diff options
context:
space:
mode:
authorSimon Hengel <sol@typeful.net>2014-11-02 12:19:38 +0800
committerSimon Hengel <sol@typeful.net>2014-11-03 09:34:20 +0800
commit122fe6edaeae55e77d606e6d57aa1904bbfb55c4 (patch)
tree58fa9ffca7e586963efece9f9046edb2890d44a2 /haddock-library
parentaf85d14f001cf4c2976ee659ec04101d6b054a4d (diff)
Allow an optional colon after the closing bracket of definition lists
This is to disambiguate them from markdown links and will be require with a future release.
Diffstat (limited to 'haddock-library')
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser.hs2
-rw-r--r--haddock-library/test/Documentation/Haddock/ParserSpec.hs42
2 files changed, 28 insertions, 16 deletions
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs
index ff03c7bb..99010897 100644
--- a/haddock-library/src/Documentation/Haddock/Parser.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser.hs
@@ -294,7 +294,7 @@ definitionList :: Parser (DocH mod Identifier)
definitionList = DocDefList <$> p
where
p = do
- label <- "[" *> (parseStringBS <$> takeWhile1 (`notElem` "]\n")) <* "]"
+ label <- "[" *> (parseStringBS <$> takeWhile1 (`notElem` "]\n")) <* ("]" <* optional ":")
c <- takeLine
(cs, items) <- more p
let contents = parseString . dropNLs . unlines $ c : cs
diff --git a/haddock-library/test/Documentation/Haddock/ParserSpec.hs b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
index 4373234c..a228a956 100644
--- a/haddock-library/test/Documentation/Haddock/ParserSpec.hs
+++ b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
@@ -646,7 +646,7 @@ spec = do
it "can nest definition lists" $ do
- "[a] foo\n\n [b] bar\n\n [c] baz\n qux" `shouldParseTo`
+ "[a]: foo\n\n [b]: bar\n\n [c]: baz\n qux" `shouldParseTo`
DocDefList [ ("a", "foo"
<> DocDefList [ ("b", "bar"
<> DocDefList [("c", "baz\nqux")])
@@ -661,7 +661,7 @@ spec = do
<> DocOrderedList [ DocParagraph "baz" ]
it "definition lists can come back to top level with a different list" $ do
- "[foo] foov\n\n [bar] barv\n\n1. baz" `shouldParseTo`
+ "[foo]: foov\n\n [bar]: barv\n\n1. baz" `shouldParseTo`
DocDefList [ ("foo", "foov"
<> DocDefList [ ("bar", "barv") ])
]
@@ -809,9 +809,9 @@ spec = do
context "when parsing definition lists" $ do
it "parses a simple list" $ do
unlines [
- " [foo] one"
- , " [bar] two"
- , " [baz] three"
+ " [foo]: one"
+ , " [bar]: two"
+ , " [baz]: three"
]
`shouldParseTo` DocDefList [
("foo", "one")
@@ -821,9 +821,9 @@ spec = do
it "ignores empty lines between list items" $ do
unlines [
- "[foo] one"
+ "[foo]: one"
, ""
- , "[bar] two"
+ , "[bar]: two"
]
`shouldParseTo` DocDefList [
("foo", "one")
@@ -831,13 +831,13 @@ spec = do
]
it "accepts an empty list item" $ do
- "[foo]" `shouldParseTo` DocDefList [("foo", DocEmpty)]
+ "[foo]:" `shouldParseTo` DocDefList [("foo", DocEmpty)]
it "accepts multi-line list items" $ do
unlines [
- "[foo] point one"
+ "[foo]: point one"
, " more one"
- , "[bar] point two"
+ , "[bar]: point two"
, "more two"
]
`shouldParseTo` DocDefList [
@@ -846,21 +846,33 @@ spec = do
]
it "accepts markup in list items" $ do
- "[foo] /foo/" `shouldParseTo` DocDefList [("foo", DocEmphasis "foo")]
+ "[foo]: /foo/" `shouldParseTo` DocDefList [("foo", DocEmphasis "foo")]
it "accepts markup for the label" $ do
- "[/foo/] bar" `shouldParseTo` DocDefList [(DocEmphasis "foo", "bar")]
+ "[/foo/]: bar" `shouldParseTo` DocDefList [(DocEmphasis "foo", "bar")]
it "requires empty lines between list and other paragraphs" $ do
unlines [
"foo"
, ""
- , "[foo] bar"
+ , "[foo]: bar"
, ""
, "baz"
]
`shouldParseTo` DocParagraph "foo" <> DocDefList [("foo", "bar")] <> DocParagraph "baz"
+ it "dose not require the colon (deprecated - this will be removed in a future release)" $ do
+ unlines [
+ " [foo] one"
+ , " [bar] two"
+ , " [baz] three"
+ ]
+ `shouldParseTo` DocDefList [
+ ("foo", "one")
+ , ("bar", "two")
+ , ("baz", "three")
+ ]
+
context "when parsing consecutive paragraphs" $ do
it "will not capture irrelevant consecutive lists" $ do
unlines [ " * bullet"
@@ -873,9 +885,9 @@ spec = do
, " "
, " 2. different bullet"
, " "
- , " [cat] kitten"
+ , " [cat]: kitten"
, " "
- , " [pineapple] fruit"
+ , " [pineapple]: fruit"
] `shouldParseTo`
DocUnorderedList [ DocParagraph "bullet"
, DocParagraph "different bullet"]