diff options
Diffstat (limited to 'haddock-library')
-rw-r--r-- | haddock-library/src/Documentation/Haddock/Parser.hs | 22 | ||||
-rw-r--r-- | haddock-library/src/Documentation/Haddock/Types.hs | 2 | ||||
-rw-r--r-- | haddock-library/test/Documentation/Haddock/ParserSpec.hs | 4 |
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 |