aboutsummaryrefslogtreecommitdiff
path: root/haddock-library/src/Documentation
diff options
context:
space:
mode:
authorAlina Banerjee <alinab@users.noreply.github.com>2019-08-01 16:01:39 -0500
committerAlec Theriault <alec.theriault@gmail.com>2020-03-20 20:24:17 -0400
commitdec888641006eb685a642ec489b198c61a5736dc (patch)
treed9634c3b0e1f7b656ebb572db003e7fc12590359 /haddock-library/src/Documentation
parent053c9add568dad4264f4629bff0de9b10d9316e1 (diff)
Update parsing to strip whitespace from table cells (#1074)
* Update parsing to strip leading & trailing whitespace from table cells * Update fixture data to disallow whitespaces at both ends in table cells * Add test case for whitespaces stripped from both ends of table cells * Update table reference test data for html tests
Diffstat (limited to 'haddock-library/src/Documentation')
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser.hs14
1 files changed, 7 insertions, 7 deletions
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs
index 028422a7..17240792 100644
--- a/haddock-library/src/Documentation/Haddock/Parser.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser.hs
@@ -267,7 +267,7 @@ picture = DocPic . makeLabeled Picture
-- >>> parseString "\\(\\int_{-\\infty}^{\\infty} e^{-x^2/2} = \\sqrt{2\\pi}\\)"
-- DocMathInline "\\int_{-\\infty}^{\\infty} e^{-x^2/2} = \\sqrt{2\\pi}"
mathInline :: Parser (DocH mod a)
-mathInline = DocMathInline . T.unpack
+mathInline = DocMathInline . T.unpack
<$> disallowNewline ("\\(" *> takeUntil "\\)")
-- | Display math parser, surrounded by \\[ and \\].
@@ -492,7 +492,7 @@ tableStepFour rs hdrIndex cells = case hdrIndex of
-- extract cell contents given boundaries
extract :: Int -> Int -> Int -> Int -> Text
extract x y x2 y2 = T.intercalate "\n"
- [ T.take (x2 - x + 1) $ T.drop x $ rs !! y'
+ [ T.stripEnd $ T.stripStart $ T.take (x2 - x + 1) $ T.drop x $ rs !! y'
| y' <- [y .. y2]
]
@@ -579,7 +579,7 @@ definitionList indent = DocDefList <$> p
Right i -> (label, contents) : i
-- | Drops all trailing newlines.
-dropNLs :: Text -> Text
+dropNLs :: Text -> Text
dropNLs = T.dropWhileEnd (== '\n')
-- | Main worker for 'innerList' and 'definitionList'.
@@ -653,7 +653,7 @@ takeNonEmptyLine = do
--
-- More precisely: skips all whitespace-only lines and returns indentation
-- (horizontal space, might be empty) of that non-empty line.
-takeIndent :: Parser Text
+takeIndent :: Parser Text
takeIndent = do
indent <- takeHorizontalSpace
choice' [ "\n" *> takeIndent
@@ -711,14 +711,14 @@ examples = DocExamples <$> (many (try (skipHorizontalSpace *> "\n")) *> go)
substituteBlankLine "<BLANKLINE>" = ""
substituteBlankLine xs = xs
-nonEmptyLine :: Parser Text
+nonEmptyLine :: Parser Text
nonEmptyLine = try (mfilter (T.any (not . isSpace)) takeLine)
takeLine :: Parser Text
takeLine = try (takeWhile (/= '\n') <* endOfLine)
endOfLine :: Parser ()
-endOfLine = void "\n" <|> Parsec.eof
+endOfLine = void "\n" <|> Parsec.eof
-- | Property parser.
--
@@ -800,7 +800,7 @@ autoUrl :: Parser (DocH mod a)
autoUrl = mkLink <$> url
where
url = mappend <$> choice' [ "http://", "https://", "ftp://"] <*> takeWhile1 (not . isSpace)
-
+
mkLink :: Text -> DocH mod a
mkLink s = case T.unsnoc s of
Just (xs,x) | x `elem` (",.!?" :: String) -> DocHyperlink (mkHyperlink xs) `docAppend` DocString [x]