aboutsummaryrefslogtreecommitdiff
path: root/haddock-library
diff options
context:
space:
mode:
authorMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>2014-06-25 15:17:20 +0200
committerMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>2014-06-25 15:17:20 +0200
commitf5be8427d95217f4efd723575a79f8699b33d003 (patch)
treecc9c8f9890ba08d18a0962686f54ac92d472a9a0 /haddock-library
parent64aee65f62c7184f31d6778d0d3d9b6dc96e4e91 (diff)
Don't mangle append order for nested lists.
The benefit of this is that the ‘top-level’ element of such lists is properly wrapped in <p> tags so any CSS working with these will be applied properly. It also just makes more sense. Pointed out at jgm/pandoc#1346.
Diffstat (limited to 'haddock-library')
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser.hs16
-rw-r--r--haddock-library/test/Documentation/Haddock/ParserSpec.hs16
2 files changed, 10 insertions, 22 deletions
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs
index 1d98601a..805b33f8 100644
--- a/haddock-library/src/Documentation/Haddock/Parser.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser.hs
@@ -265,7 +265,7 @@ innerList item = do
(cs, items) <- more item
let contents = docParagraph . parseString . dropNLs . unlines $ c : cs
return $ case items of
- Left p -> [contents `joinPara` p]
+ Left p -> [contents <> p]
Right i -> contents : i
-- | Parses definition lists.
@@ -276,21 +276,9 @@ definitionList = do
(cs, items) <- more definitionList
let contents = parseString . dropNLs . unlines $ c : cs
return $ case items of
- Left p -> [(label, contents `joinPara` p)]
+ Left p -> [(label, contents <> p)]
Right i -> (label, contents) : i
--- | If possible, appends two 'Doc's under a 'DocParagraph' rather than
--- outside of it. This allows to get structures like
---
--- @DocParagraph (DocAppend … …)@
---
--- rather than
---
--- @DocAppend (DocParagraph …) …@
-joinPara :: DocH mod id -> DocH mod id -> DocH mod id
-joinPara (DocParagraph p) c = docParagraph $ p <> c
-joinPara d p = d <> p
-
-- | Drops all trailing newlines.
dropNLs :: String -> String
dropNLs = reverse . dropWhile (== '\n') . reverse
diff --git a/haddock-library/test/Documentation/Haddock/ParserSpec.hs b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
index 6d05791b..a8c2199a 100644
--- a/haddock-library/test/Documentation/Haddock/ParserSpec.hs
+++ b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
@@ -547,34 +547,34 @@ spec = do
context "when parsing paragraphs nested in lists" $ do
it "can nest the same type of list" $ do
"* foo\n\n * bar" `shouldParseTo`
- DocUnorderedList [ DocParagraph $ "foo"
+ DocUnorderedList [ DocParagraph "foo"
<> DocUnorderedList [DocParagraph "bar"]]
it "can nest another type of list inside" $ do
"* foo\n\n 1. bar" `shouldParseTo`
- DocUnorderedList [ DocParagraph $ "foo"
+ DocUnorderedList [ DocParagraph "foo"
<> DocOrderedList [DocParagraph "bar"]]
it "can nest a code block inside" $ do
"* foo\n\n @foo bar baz@" `shouldParseTo`
- DocUnorderedList [ DocParagraph $ "foo"
+ DocUnorderedList [ DocParagraph "foo"
<> DocCodeBlock "foo bar baz"]
"* foo\n\n @\n foo bar baz\n @" `shouldParseTo`
- DocUnorderedList [ DocParagraph $ "foo"
+ DocUnorderedList [ DocParagraph "foo"
<> DocCodeBlock "foo bar baz\n"]
it "can nest more than one level" $ do
"* foo\n\n * bar\n\n * baz\n qux" `shouldParseTo`
- DocUnorderedList [ DocParagraph $ "foo"
- <> DocUnorderedList [ DocParagraph $ "bar"
+ DocUnorderedList [ DocParagraph "foo"
+ <> DocUnorderedList [ DocParagraph "bar"
<> DocUnorderedList [DocParagraph "baz\nqux"]
]
]
it "won't fail on not fully indented paragraph" $ do
"* foo\n\n * bar\n\n * qux\nquux" `shouldParseTo`
- DocUnorderedList [ DocParagraph $ "foo"
+ DocUnorderedList [ DocParagraph "foo"
<> DocUnorderedList [ DocParagraph "bar" ]
, DocParagraph "qux\nquux"]
@@ -589,7 +589,7 @@ spec = do
it "can come back to top level with a different list" $ do
"* foo\n\n * bar\n\n1. baz" `shouldParseTo`
- DocUnorderedList [ DocParagraph $ "foo"
+ DocUnorderedList [ DocParagraph "foo"
<> DocUnorderedList [ DocParagraph "bar" ]
]
<> DocOrderedList [ DocParagraph "baz" ]