aboutsummaryrefslogtreecommitdiff
path: root/haddock-library
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2015-12-25 11:03:11 +0100
committerBen Gamari <ben@smart-cactus.org>2015-12-25 11:03:11 +0100
commit0104ef892820383845b3dce44c46899fec2f04f0 (patch)
tree81eba131303296aeb5ef5c880504cab0932dcab2 /haddock-library
parent2d4680f12f8c9cd647049eb1e3e56531bd44e880 (diff)
parent3f50b955324bd4b42f88a421f0203bc46a3ccf64 (diff)
Merge remote-tracking branch 'idontgetoutmuch/ghc-head' into ghc-head
Diffstat (limited to 'haddock-library')
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser.hs22
-rw-r--r--haddock-library/src/Documentation/Haddock/Types.hs2
-rw-r--r--haddock-library/test/Documentation/Haddock/ParserSpec.hs4
3 files changed, 27 insertions, 1 deletions
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs
index ca9e9d8d..123f5612 100644
--- a/haddock-library/src/Documentation/Haddock/Parser.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser.hs
@@ -73,6 +73,8 @@ overIdentifier f d = g d
g (DocCodeBlock x) = DocCodeBlock $ g x
g (DocHyperlink x) = DocHyperlink x
g (DocPic x) = DocPic x
+ g (DocMathInline x) = DocMathInline x
+ g (DocMathDisplay x) = DocMathDisplay x
g (DocAName x) = DocAName x
g (DocProperty x) = DocProperty x
g (DocExamples x) = DocExamples x
@@ -113,7 +115,9 @@ parseStringBS = snd . parse p
where
p :: Parser (DocH mod Identifier)
p = docConcat <$> many (monospace <|> anchor <|> identifier <|> moduleName
- <|> picture <|> markdownImage <|> hyperlink <|> bold
+ <|> picture <|> mathDisplay <|> mathInline
+ <|> markdownImage
+ <|> hyperlink <|> bold
<|> emphasis <|> encodedChar <|> string'
<|> skipSpecialChar)
@@ -224,6 +228,22 @@ picture :: Parser (DocH mod a)
picture = DocPic . makeLabeled Picture . decodeUtf8
<$> disallowNewline ("<<" *> takeUntil ">>")
+-- | Inline math parser, surrounded by \\( and \\).
+--
+-- >>> 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 . decodeUtf8
+ <$> disallowNewline ("\\(" *> takeUntil "\\)")
+
+-- | Display math parser, surrounded by \\[ and \\].
+--
+-- >>> parseString "\\[\\int_{-\\infty}^{\\infty} e^{-x^2/2} = \\sqrt{2\\pi}\\]"
+-- DocMathDisplay "\\int_{-\\infty}^{\\infty} e^{-x^2/2} = \\sqrt{2\\pi}"
+mathDisplay :: Parser (DocH mod a)
+mathDisplay = DocMathDisplay . decodeUtf8
+ <$> ("\\[" *> takeUntil "\\]")
+
markdownImage :: Parser (DocH mod a)
markdownImage = fromHyperlink <$> ("!" *> linkParser)
where
diff --git a/haddock-library/src/Documentation/Haddock/Types.hs b/haddock-library/src/Documentation/Haddock/Types.hs
index 4ef89658..4d5bb68a 100644
--- a/haddock-library/src/Documentation/Haddock/Types.hs
+++ b/haddock-library/src/Documentation/Haddock/Types.hs
@@ -71,6 +71,8 @@ data DocH mod id
| DocCodeBlock (DocH mod id)
| DocHyperlink Hyperlink
| DocPic Picture
+ | DocMathInline String
+ | DocMathDisplay String
| DocAName String
| DocProperty String
| DocExamples [Example]
diff --git a/haddock-library/test/Documentation/Haddock/ParserSpec.hs b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
index 2ef414fb..1169eb49 100644
--- a/haddock-library/test/Documentation/Haddock/ParserSpec.hs
+++ b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
@@ -208,6 +208,10 @@ spec = do
it "supports title for deprecated picture syntax" $ do
"<<b a z>>" `shouldParseTo` image "b" "a z"
+ context "when parsing display math" $ do
+
+ it "accepts markdown syntax for display math containing newlines" $ do
+ "\\[\\pi\n\\pi\\]" `shouldParseTo` DocMathDisplay "\\pi\n\\pi"
context "when parsing anchors" $ do
it "parses a single word anchor" $ do