aboutsummaryrefslogtreecommitdiff
path: root/haddock-library/src/Documentation/Haddock
diff options
context:
space:
mode:
authorDominic Steinitz <dominic@steinitz.org>2015-05-16 12:32:23 +0100
committerDominic Steinitz <dominic@steinitz.org>2015-12-21 07:19:16 +0000
commite01e4790402204af02ab0127ef5b633fb7748cd4 (patch)
tree88be1e3c3b74ec27db6e02264dba9f32d58a32d3 /haddock-library/src/Documentation/Haddock
parent2bdfda1fb2e0de696ca8c6f7a152b2f85a541be9 (diff)
Handle inline math with mathjax.
Diffstat (limited to 'haddock-library/src/Documentation/Haddock')
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser.hs16
-rw-r--r--haddock-library/src/Documentation/Haddock/Types.hs1
2 files changed, 16 insertions, 1 deletions
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs
index ca9e9d8d..919ea37f 100644
--- a/haddock-library/src/Documentation/Haddock/Parser.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser.hs
@@ -73,6 +73,7 @@ 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 (DocAName x) = DocAName x
g (DocProperty x) = DocProperty x
g (DocExamples x) = DocExamples x
@@ -113,7 +114,8 @@ parseStringBS = snd . parse p
where
p :: Parser (DocH mod Identifier)
p = docConcat <$> many (monospace <|> anchor <|> identifier <|> moduleName
- <|> picture <|> markdownImage <|> hyperlink <|> bold
+ <|> picture <|> mathDisplay <|> markdownImage
+ <|> hyperlink <|> bold
<|> emphasis <|> encodedChar <|> string'
<|> skipSpecialChar)
@@ -224,6 +226,18 @@ picture :: Parser (DocH mod a)
picture = DocPic . makeLabeled Picture . decodeUtf8
<$> disallowNewline ("<<" *> takeUntil ">>")
+-- FIXME: I have just copied the code for `picture` but it is not
+-- clear why we should disallow a newline (if that is what
+-- `disallowNewline` does)
+
+-- | Inline math parser, surrounded by \$\$ and \$\$.
+--
+-- >>> parseString "$$\int_{-infty}^{infty} e^{-x^2/2} = \sqrt{2\pi}$$"
+-- DocMathInline (DocString "\int_{-infty}^{infty} e^{-x^2/2} = \sqrt{2\pi}")
+mathDisplay :: Parser (DocH mod a)
+mathDisplay = DocMathInline . decodeUtf8
+ <$> disallowNewline ("$$" *> 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..2b1e7f26 100644
--- a/haddock-library/src/Documentation/Haddock/Types.hs
+++ b/haddock-library/src/Documentation/Haddock/Types.hs
@@ -71,6 +71,7 @@ data DocH mod id
| DocCodeBlock (DocH mod id)
| DocHyperlink Hyperlink
| DocPic Picture
+ | DocMathInline String
| DocAName String
| DocProperty String
| DocExamples [Example]