{-# LANGUAGE OverloadedStrings #-} import Text.Blaze.Html (toHtml) import Text.Blaze.Html5 (figure) import Test.Hspec import Text.Markdown import Data.Text.Lazy (Text, unpack, snoc, fromStrict) import qualified Data.Text as T import qualified Data.Text.Lazy as TL import Text.Blaze.Html.Renderer.Text (renderHtml) import Control.Monad (forM_) import qualified Data.Set as Set import qualified Data.Map as Map import qualified Filesystem.Path.CurrentOS as F import qualified Filesystem as F import Block import Inline check :: Text -> Text -> Expectation check html md = renderHtml (markdown def md) `shouldBe` html checkSet :: MarkdownSettings -> Text -> Text -> Expectation checkSet set html md = renderHtml (markdown set md) `shouldBe` html check' :: Text -> Text -> Expectation check' html md = renderHtml (markdown def { msXssProtect = False } md) `shouldBe` html checkNoNL :: Text -> Text -> Expectation checkNoNL html md = f (renderHtml $ markdown def { msXssProtect = False } md) `shouldBe` f html where f = TL.filter (/= '\n') -- FIXME add quickcheck: all input is valid main :: IO () main = do examples <- getExamples gruber <- getGruber hspec $ do describe "block" blockSpecs describe "inline" inlineSpecs describe "paragraphs" $ do it "simple" $ check "
Hello World!
" "Hello World!" it "multiline" $ check "Hello\nWorld!
" "Hello\nWorld!" it "multiple" $ check "Hello
World!
" "Hello\n\nWorld!" describe "italics" $ do it "simple" $ check "foo
" "*foo*" it "hanging" $ check "foo *
" "*foo* *" it "two" $ check "foo bar
" "*foo* *bar*" describe "italics under" $ do it "simple" $ check "foo
" "_foo_" it "hanging" $ check "foo _
" "_foo_ _" it "two" $ check "foo bar
" "_foo_ _bar_" describe "bold" $ do it "simple" $ check "foo
" "**foo**" it "hanging" $ check "foo **
" "**foo** **" it "two" $ check "foo bar
" "**foo** **bar**" describe "bold under" $ do it "simple" $ check "foo
" "__foo__" it "hanging" $ check "foo __
" "__foo__ __" it "two" $ check "foo bar
" "__foo__ __bar__" describe "html" $ do it "simple" $ check "paragraph
foo bar
baz
foo\n bar\nbaz
"
" foo\n bar\n baz"
it "custom renderer"
$ checkSet
def { msBlockCodeRenderer = (\_ (u,_) -> figure (toHtml u)) }
""
"```haskell\nfoo\n bar\nbaz\n```"
describe "escaping" $ do
it "everything"
$ check
"*foo_barbaz\\`bin
" "\\*foo\\_bar_baz_\\\\\\`bin" describe "bullets" $ do it "simple" $ check "" "> foo\n>\n> bar" describe "links" $ do it "simple" $ check "" "[bar](foo)" it "title" $ check "" "[bar](foo \"baz\")" it "escaped href" $ check "" "[bar](foo\\) \"baz\")" it "escaped title" $ check "" "[bar](foo\\) \"baz\\\"\")" it "inside a paragraph" $ check "foo
bar
Hello bar World
" "Hello [bar](foo) World" it "not a link" $ check "Not a [ link
" "Not a [ link" {- describe "github links" $ do it "simple" $ check "" "[[bar|foo]]" it "no link text" $ check "" "[[foo]]" it "escaping" $ check "" "[[bar|foo/baz bin]]" it "inside a list" $ check "" "* [[foo]]" -} describe "images" $ do it "simple" $ check "" "![foo](http://link.to/image.jpg)" it "title" $ check "" "![foo](http://link.to/image.jpg \"bar\")" it "inside a paragraph" $ check "Hello World
" "Hello ![foo](http://link.to/image.jpg) World" it "not an image" $ check "Not an ![ image
" "Not an ![ image" describe "rules" $ do let options = concatMap (\t -> [t, snoc t '\n']) [ "* * *" , "***" , "*****" , "- - -" , "---------------------------------------" , "----------------------------------" ] forM_ options $ \o -> it (unpack o) $ check "foo
bar
foo
bar
1 < 2
" "1 < 2" it "standalone" $ checkSet def { msStandaloneHtml = Set.fromList ["foo\nbar
foo
bar