aboutsummaryrefslogtreecommitdiff
path: root/haddock-library/src/Documentation/Haddock
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/src/Documentation/Haddock
parent2d4680f12f8c9cd647049eb1e3e56531bd44e880 (diff)
parent3f50b955324bd4b42f88a421f0203bc46a3ccf64 (diff)
Merge remote-tracking branch 'idontgetoutmuch/ghc-head' into ghc-head
Diffstat (limited to 'haddock-library/src/Documentation/Haddock')
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser.hs22
-rw-r--r--haddock-library/src/Documentation/Haddock/Types.hs2
2 files changed, 23 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]