markdown-0.1.16/ 0000755 0000000 0000000 00000000000 13014511122 011575 5 ustar 00 0000000 0000000 markdown-0.1.16/LICENSE 0000644 0000000 0000000 00000002767 13014511122 012616 0 ustar 00 0000000 0000000 Copyright (c)2011, Michael Snoyman All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Michael Snoyman nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. markdown-0.1.16/markdown.cabal 0000644 0000000 0000000 00000004200 13014511122 014377 0 ustar 00 0000000 0000000 Name: markdown Version: 0.1.16 Synopsis: Convert Markdown to HTML, with XSS protection Description: This library leverages existing high-performance libraries (attoparsec, blaze-html, text, and conduit), and should integrate well with existing codebases. Homepage: https://github.com/snoyberg/markdown License: BSD3 License-file: LICENSE Author: Michael Snoyman Maintainer: michael@snoyman.com Category: Web Build-type: Simple Extra-source-files: test/examples/*.html , test/examples/*.md , test/Tests/*.html , test/Tests/*.text Cabal-version: >=1.8 Library Exposed-modules: Text.Markdown Text.Markdown.Block Text.Markdown.Inline other-modules: Text.Markdown.Types Build-depends: base >= 4 && < 5 , blaze-markup >= 0.6 , blaze-html >= 0.4 , attoparsec >= 0.10 , transformers >= 0.2.2 , conduit >= 1.1 , conduit-extra >= 1.1 , text , data-default >= 0.3 , xss-sanitize >= 0.3.3 , containers , xml-types , xml-conduit ghc-options: -Wall test-suite test hs-source-dirs: test main-is: main.hs other-modules: Block Inline type: exitcode-stdio-1.0 ghc-options: -Wall build-depends: markdown , base >= 4 && < 5 , hspec >= 1.3 , blaze-html , text , transformers , conduit , conduit-extra , containers , filepath , directory source-repository head type: git location: git://github.com/snoyberg/markdown.git markdown-0.1.16/Setup.hs 0000644 0000000 0000000 00000000056 13014511122 013232 0 ustar 00 0000000 0000000 import Distribution.Simple main = defaultMain markdown-0.1.16/test/ 0000755 0000000 0000000 00000000000 13014511122 012554 5 ustar 00 0000000 0000000 markdown-0.1.16/test/Block.hs 0000644 0000000 0000000 00000007103 13014511122 014143 0 ustar 00 0000000 0000000 {-# LANGUAGE OverloadedStrings #-} module Block ( blockSpecs ) where import Test.Hspec import Data.Text (Text) import Data.Conduit import qualified Data.Conduit.List as CL import Text.Markdown (def, MarkdownSettings(..)) import Text.Markdown.Block import Data.Functor.Identity (runIdentity) checkWith :: MarkdownSettings -> Text -> [Block Text] -> Expectation checkWith ms md blocks = runIdentity (yield md $$ toBlocks ms =$ CL.consume) `shouldBe` blocks check :: Text -> [Block Text] -> Expectation check = checkWith def blockSpecs :: Spec blockSpecs = do describe "tilde code" $ do it "simple" $ check "~~~haskell\nfoo\n\nbar\n~~~" [BlockCode (Just "haskell") "foo\n\nbar"] it "no lang" $ check "~~~\nfoo\n\nbar\n~~~" [BlockCode Nothing "foo\n\nbar"] it "no close" $ check "~~~\nfoo\n\nbar\n" [BlockPara " ~~~\nfoo", BlockPara "bar"] describe "list" $ do it "simple unordered" $ check "* foo\n\n* bar\n\n*\t\tqux" [ BlockList Unordered (Right [BlockPara "foo"]) , BlockList Unordered (Right [BlockPara "bar"]) , BlockList Unordered (Right [BlockPara "qux"]) ] it "simple ordered" $ check "1. foo\n\n3. bar\n\n17.\t\tqux" [ BlockList Ordered (Right [BlockPara "foo"]) , BlockList Ordered (Right [BlockPara "bar"]) , BlockList Ordered (Right [BlockPara "qux"]) ] it "nested" $ check "* foo\n* \n 1. bar\n 2. baz" [ BlockList Unordered (Left "foo") , BlockList Unordered (Right [ BlockList Ordered $ Left "bar" , BlockList Ordered $ Left "baz" ]) ] it "with blank" $ check "* foo\n\n bar\n\n* baz" [ BlockList Unordered $ Right [ BlockPara "foo" , BlockPara "bar" ] , BlockList Unordered $ Right [ BlockPara "baz" ] ] it "without whitespace" $ check "*foo\n\n1.bar" [ BlockPara "*foo" , BlockPara "1.bar" ] describe "blockquote" $ do it "simple" $ check "> foo\n>\n> * bar" [ BlockQuote [ BlockPara "foo" , BlockList Unordered $ Left "bar" ] ] it "blank" $ check "> foo\n\n> * bar" [ BlockQuote [BlockPara "foo"] , BlockQuote [BlockList Unordered $ Left "bar"] ] it "require blank before blockquote" $ check "foo\n> bar" [ BlockPara "foo\n> bar" ] it "no blank before blockquote" $ checkWith def { msBlankBeforeBlockquote = False } "foo\n> bar" [ BlockPara "foo", BlockQuote [BlockPara "bar"]] describe "indented code" $ do it "simple" $ check " foo\n bar\n" [ BlockCode Nothing "foo\nbar" ] it "blank" $ check " foo\n\n bar\n" [ BlockCode Nothing "foo\n\nbar" ] it "extra space" $ check " foo\n\n bar\n" [ BlockCode Nothing "foo\n\n bar" ] describe "html" $ do it "simple" $ check "
Hello world!
" [ BlockHtml "Hello world!
" ] it "multiline" $ check "Hello world!\n
" [ BlockHtml "Hello world!\n
" ] markdown-0.1.16/test/Inline.hs 0000644 0000000 0000000 00000006022 13014511122 014326 0 ustar 00 0000000 0000000 {-# LANGUAGE OverloadedStrings #-} module Inline ( inlineSpecs ) where import Test.Hspec import Text.Markdown.Inline import Data.Text (Text) import Data.Monoid (mempty) check :: Text -> [Inline] -> Expectation check md ins = toInline mempty md `shouldBe` ins inlineSpecs :: Spec inlineSpecs = do describe "raw text" $ do it "simple" $ check "raw text" [InlineText "raw text"] it "multiline" $ check "raw\ntext" [InlineText "raw\ntext"] describe "italic" $ do it "asterisk" $ check "raw *text*" [InlineText "raw ", InlineItalic [InlineText "text"]] it "underline" $ check "raw _text_" [InlineText "raw ", InlineItalic [InlineText "text"]] it "multiline" $ check "*raw\ntext*" [InlineItalic [InlineText "raw\ntext"]] it "mismatched" $ check "*foo* *bar" [InlineItalic [InlineText "foo"], InlineText " *bar"] describe "bold" $ do it "asterisk" $ check "raw **text**" [InlineText "raw ", InlineBold [InlineText "text"]] it "underline" $ check "raw __text__" [InlineText "raw ", InlineBold [InlineText "text"]] it "multiline" $ check "**raw\ntext**" [InlineBold [InlineText "raw\ntext"]] it "mismatched" $ check "**foo** *bar" [InlineBold [InlineText "foo"], InlineText " *bar"] describe "nested" $ do it "bold inside italic" $ check "*i __ib__ i*" [InlineItalic [InlineText "i ", InlineBold [InlineText "ib"], InlineText " i"]] it "bold inside italic swap" $ check "_i **ib** i_" [InlineItalic [InlineText "i ", InlineBold [InlineText "ib"], InlineText " i"]] it "italic inside bold" $ check "**b _ib_ b**" [InlineBold [InlineText "b ", InlineItalic [InlineText "ib"], InlineText " b"]] it "italic inside bold swap" $ check "__b *ib* b__" [InlineBold [InlineText "b ", InlineItalic [InlineText "ib"], InlineText " b"]] describe "code" $ do it "takes all characters" $ check "`foo*__*bar` baz`" [ InlineCode "foo*__*bar" , InlineText " baz`" ] describe "escaping" $ do it "asterisk" $ check "\\*foo*\\\\" [InlineText "*foo*\\"] describe "links" $ do it "simple" $ check "[bar](foo)" [InlineLink "foo" Nothing [InlineText "bar"]] it "title" $ check "[bar](foo \"baz\")" [InlineLink "foo" (Just "baz") [InlineText "bar"]] {- it "escaped href" $ check "" "[bar](foo\\) \"baz\")" it "escaped title" $ check "" "[bar](foo\\) \"baz\\\"\")" it "inside a paragraph" $ check "Hello bar World
" "Hello [bar](foo) World" it "not a link" $ check "Not a [ link
" "Not a [ link" -} markdown-0.1.16/test/main.hs 0000644 0000000 0000000 00000026615 13014511122 014046 0 ustar 00 0000000 0000000 {-# 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.IO as TIO 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 Data.List (isInfixOf, isSuffixOf) import Data.Maybe (fromMaybe) import System.Directory (getDirectoryContents) import System.FilePath ((>), replaceExtension) 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 "line break" $ do it "is inserted for a single newline after two spaces" $ check "Hello
World!
Hello
World!
Q1
Q2
P2
" "> Q1 \nQ2\n\nP2" it "consumes all trailing whitespace on the previous line" $ check "Hello
World!
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)) }
"*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" it "new tab" $ checkSet def { msLinkNewTab = True } "" "[bar](foo)" {- 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 "Hello World
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
[1]hello
" "{1}hello" it "references" $ check "[1]hello
" "{^1}hello" describe "examples" $ sequence_ examples describe "John Gruber's test suite" $ sequence_ gruber it "comments without spaces #22" $ check "" "" describe "no follow" $ do it "external 1" $ checkSet (setNoFollowExternal def) "" "[example](http://example.com)" it "external 2" $ checkSet (setNoFollowExternal def) "" "[example](//example.com)" it "internal" $ checkSet (setNoFollowExternal def) "" "[example](/foo)" getExamples :: IO [Spec] getExamples = do files <- getDirectoryContents dir mapM go $ filter (".md" `isSuffixOf`) files where dir = "test/examples" go basename = do let fp = dir > basename input <- TIO.readFile fp output <- TIO.readFile $ replaceExtension fp "html" let (checker, stripper) | "-spec" `isInfixOf` fp = (check', dropFinalLF) | otherwise = (check, T.strip) return $ it basename $ checker (fromStrict $ stripper output) (fromStrict input) dropFinalLF t = fromMaybe t $ T.stripSuffix "\n" t getGruber :: IO [Spec] getGruber = do files <- getDirectoryContents dir mapM go $ filter (".text" `isSuffixOf`) files where dir = "test/Tests" go basename = do let fp = dir > basename input <- TIO.readFile fp output <- TIO.readFile $ replaceExtension fp "html" return $ it basename $ checkNoNL (fromStrict $ T.strip output) (fromStrict input) markdown-0.1.16/test/examples/ 0000755 0000000 0000000 00000000000 13014511122 014372 5 ustar 00 0000000 0000000 markdown-0.1.16/test/examples/closing-tags.html 0000644 0000000 0000000 00000000035 13014511122 017650 0 ustar 00 0000000 0000000foo
foo
markdown-0.1.16/test/examples/double-backtick.html 0000644 0000000 0000000 00000000246 13014511122 020305 0 ustar 00 0000000 0000000This is a paragraph with double `backtick` inside
with space.
This is a paragraph with double `backtick` inside
without space.
1 < 2 & 2 > 1, also 1 < 2 & 2 > 1 ý &#xP; …
markdown-0.1.16/test/examples/entities.md 0000644 0000000 0000000 00000000111 13014511122 016531 0 ustar 00 0000000 0000000 1 < 2 & 2 > 1, also 1 < 2 & 2 > 1 ý P; … markdown-0.1.16/test/examples/fence-whitespace.html 0000644 0000000 0000000 00000000046 13014511122 020472 0 ustar 00 0000000 0000000foo
bar
markdown-0.1.16/test/examples/fence-whitespace.md 0000644 0000000 0000000 00000000020 13014511122 020116 0 ustar 00 0000000 0000000 foo
```
bar
```
markdown-0.1.16/test/examples/html-blocks-spec1.html 0000644 0000000 0000000 00000000115 13014511122 020505 0 ustar 00 0000000 0000000 hi |
okay.
markdown-0.1.16/test/examples/html-blocks-spec1.md 0000644 0000000 0000000 00000000110 13014511122 020134 0 ustar 00 0000000 0000000hi |