markdown-0.1.17.4/Text/ 0000755 0000000 0000000 00000000000 13252405552 012701 5 ustar 00 0000000 0000000 markdown-0.1.17.4/Text/Markdown/ 0000755 0000000 0000000 00000000000 13256413103 014456 5 ustar 00 0000000 0000000 markdown-0.1.17.4/test/ 0000755 0000000 0000000 00000000000 13350661306 012734 5 ustar 00 0000000 0000000 markdown-0.1.17.4/test/Tests/ 0000755 0000000 0000000 00000000000 12677401324 014041 5 ustar 00 0000000 0000000 markdown-0.1.17.4/test/examples/ 0000755 0000000 0000000 00000000000 13350660574 014560 5 ustar 00 0000000 0000000 markdown-0.1.17.4/Text/Markdown.hs 0000644 0000000 0000000 00000015113 13252405552 015020 0 ustar 00 0000000 0000000 {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE RankNTypes #-} module Text.Markdown ( -- * Functions markdown -- * Settings , MarkdownSettings , defaultMarkdownSettings , msXssProtect , msStandaloneHtml , msFencedHandlers , msBlockCodeRenderer , msLinkNewTab , msBlankBeforeBlockquote , msBlockFilter , msAddHeadingId , setNoFollowExternal -- * Newtype , Markdown (..) -- * Fenced handlers , FencedHandler (..) , codeFencedHandler , htmlFencedHandler -- * Convenience re-exports , def ) where import Control.Arrow ((&&&)) import Text.Markdown.Inline import Text.Markdown.Block import Text.Markdown.Types import Prelude hiding (sequence, takeWhile) import Data.Char (isAlphaNum) import Data.Default (Default (..)) import Data.List (intercalate, isInfixOf) import Data.Maybe (isJust) import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Lazy as TL import Text.Blaze (toValue) import Text.Blaze.Html (ToMarkup (..), Html) import Text.Blaze.Html.Renderer.Text (renderHtml) import Data.Conduit import qualified Data.Conduit.List as CL import Data.Monoid (Monoid (mappend, mempty, mconcat), (<>)) import qualified Text.Blaze.Html5 as H import qualified Text.Blaze.Html5.Attributes as HA import Text.HTML.SanitizeXSS (sanitizeBalance) import qualified Data.Map as Map import Data.String (IsString) import Data.Semigroup (Semigroup) -- | A newtype wrapper providing a @ToHtml@ instance. newtype Markdown = Markdown TL.Text deriving(Eq, Ord, Monoid, Semigroup, IsString, Show) instance ToMarkup Markdown where toMarkup (Markdown t) = markdown def t -- | Convert the given textual markdown content to HTML. -- -- >>> :set -XOverloadedStrings -- >>> import Text.Blaze.Html.Renderer.Text -- >>> renderHtml $ markdown def "# Hello World!" -- "
main = putStrLn "Hello world!"
--
-- Since: 0.1.2.1
, msLinkNewTab :: Bool
-- ^ If @True@, all generated links have the attribute target=_blank set,
-- causing them to be opened in a new tab or window.
--
-- Default: @False@
--
-- Since 0.1.4
, msBlankBeforeBlockquote :: Bool
-- ^ If @True@, a blank line is required before the start of a blockquote. Standard
-- markdown syntax does not require a blank line before a blockquote, but it is all
-- too easy for a > to end up at the beginning of a line by accident.
--
-- Default: @True@
--
-- Since 0.1.5
, msBlockFilter :: [Block [Inline]] -> [Block [Inline]]
-- ^ A function to filter and/or modify parsed blocks before they are
-- written to Html
--
-- Default: @id@
--
-- Since 0.1.7
, msAddHeadingId :: Bool
-- ^ If @True@, an @id@ attribute is added to the heading tag with the value equal to
-- the text with only valid CSS identifier characters.
--
-- > ## Executive Summary
--
-- > 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 <- decodeUtf8 <$> B.readFile fp output <- decodeUtf8 <$> B.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 <- decodeUtf8 <$> B.readFile fp output <- decodeUtf8 <$> B.readFile (replaceExtension fp "html") return $ it basename $ checkNoNL (fromStrict $ T.strip output) (fromStrict input) markdown-0.1.17.4/test/Block.hs 0000644 0000000 0000000 00000007033 13252373420 014323 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 checkWith :: MarkdownSettings -> Text -> [Block Text] -> Expectation checkWith ms md blocks = runConduitPure (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.17.4/test/Inline.hs 0000644 0000000 0000000 00000006022 12677401324 014511 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.17.4/LICENSE 0000644 0000000 0000000 00000002767 12677401324 013001 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.17.4/Setup.hs 0000644 0000000 0000000 00000000056 12677401324 013415 0 ustar 00 0000000 0000000 import Distribution.Simple main = defaultMain markdown-0.1.17.4/markdown.cabal 0000644 0000000 0000000 00000004401 13350667364 014574 0 ustar 00 0000000 0000000 Name: markdown Version: 0.1.17.4 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 , ChangeLog.md , README.md Cabal-version: >=1.8 Library Exposed-modules: Text.Markdown Text.Markdown.Block Text.Markdown.Inline other-modules: Text.Markdown.Types Build-depends: base >= 4.9 && < 5 , blaze-markup >= 0.6 , blaze-html >= 0.4 , attoparsec >= 0.10 , transformers >= 0.2.2 , conduit >= 1.2.8 , 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 , bytestring , call-stack , text , transformers , conduit , conduit-extra , containers , filepath , directory source-repository head type: git location: git://github.com/snoyberg/markdown.git markdown-0.1.17.4/test/examples/list-blocks.html 0000644 0000000 0000000 00000000311 12677401324 017664 0 ustar 00 0000000 0000000This is a paragraph.
Another paragraph.
Non-paragraph.
Item.
foo
bar
markdown-0.1.17.4/test/examples/html-blocks-spec7.html 0000644 0000000 0000000 00000000156 12677401324 020703 0 ustar 00 0000000 0000000
markdown-0.1.17.4/test/examples/html-blocks-spec6.html 0000644 0000000 0000000 00000000030 12677401324 020671 0 ustar 00 0000000 0000000
markdown-0.1.17.4/test/examples/multiline-paragraphs.html 0000644 0000000 0000000 00000000430 13350652776 021600 0 ustar 00 0000000 0000000 This is a multiline paragraph.
Multiline paragraph in a list.
The purpose of classy prelude is not to encourage writing polymorphic code based on the typeclasses provided. Though it is certainly possible to write code such as:
hi |
okay.
markdown-0.1.17.4/test/examples/entities.html 0000644 0000000 0000000 00000000121 12677402753 017270 0 ustar 00 0000000 00000001 < 2 & 2 > 1, also 1 < 2 & 2 > 1  ý &#xP; …
markdown-0.1.17.4/test/examples/sublists.html 0000644 0000000 0000000 00000000143 12677401324 017311 0 ustar 00 0000000 0000000Markdown
this is lazy
foo
This is a paragraph with double `backtick` inside
with space.
This is a paragraph with double `backtick` inside
without space.