discount (empty) → 0.1
raw patch · 5 files changed
+219/−0 lines, 5 filesdep +basedep +bytestringdep +textsetup-changed
Dependencies added: base, bytestring, text
Files
- LICENSE +28/−0
- Setup.hs +2/−0
- Text/Discount.hsc +141/−0
- Text/Discount/Internal.hs +24/−0
- discount.cabal +24/−0
+ LICENSE view
@@ -0,0 +1,28 @@+This product includes software developed by+David Loren Parsons <http://www.pell.portland.or.us/~orc>++The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2012, Patrick Hurst. 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.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "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 HOLDERS 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Text/Discount.hsc view
@@ -0,0 +1,141 @@+{-# LANGUAGE ForeignFunctionInterface #-}+-- | This module is a thin wrapper around the discount+-- Markdown-processing library, by David Parsons+-- <http://www.pell.portland.or.us/~orc/Code/discount/>. It exposes+-- options that can be passed to the parser, as well as 'ByteString'+-- and 'Text' interfaces to the parser itself.++module Text.Discount (+ DiscountOption+ , module Text.Discount+ ) where++#include <mkdio.h>++import Data.ByteString+import Data.Text+import Data.Text.Encoding+import Foreign hiding (unsafePerformIO)+import System.IO.Unsafe (unsafePerformIO)+import Text.Discount.Internal++#{let mkopt opt,val = opt ":: DiscountOption;\n" opt " = DiscountOption %d", val}++-- * Parser interface+-- | Convert the ByteString String input into well-formed HTML+-- output. Note that an empty set of flags will not enable "strict"+-- markdown behavior; instead, use 'compatOptions', which will cause+-- discount to pass the markdown tests.+parseMarkdown :: [DiscountOption] -> ByteString -> ByteString+parseMarkdown opts markdown = unsafePerformIO . alloca $ \out_buf -> useAsCStringLen markdown $ \(markdown_c, len) -> do+ mmioptr <- mkd_string markdown_c (toEnum len) flag+ mkd_compile mmioptr flag+ mkd_document mmioptr out_buf+ result <- peek out_buf >>= packCString+ mkd_cleanup mmioptr+ return result++ where flag = unDiscountOption $ combineOptions opts++-- | As 'parseMarkdown', but taking 'Text' values instead. Uses UTF-8 internally.+parseMarkdownUtf8 :: [DiscountOption] -> Text -> Text+parseMarkdownUtf8 opts = decodeUtf8 . parseMarkdown opts . encodeUtf8++-- * Parser options+-- | Disables processing of links. Note that this will produce invalid+-- HTML due to a bug in discount!+#mkopt "noLinks", MKD_NOLINKS++-- | Disables image processing. Note that this will produce invalid+-- HTML due to a bug in discount!+#mkopt "noImages", MKD_NOIMAGE++-- | Disables SmartyPants processing. SmartyPants replaces quotes with+-- curly quotes (except in code blocks), replaces @(tm)@, @(r)@, and+-- @(c)@ with the relevant symbols, and replaces ellipses and+-- em/en-dashes with the appropriate symbols.+#mkopt "noSmartyPants", MKD_NOPANTS++-- | Disables raw HTML. Note that this will produce invalid HTML due+-- to a bug in discount!+#mkopt "noHtml", MKD_NOHTML++-- | Disables both superscript and relaxed emphasis (see 'noRelaxedEmphasis').+#mkopt "strict", MKD_STRICT++-- | Disable pseudoprotocol wrapping. If this is not enabled, then+-- links of the form @[foo bar](class:glarch)@ will be replaced by+-- @\<span class=\"glarch\"\>foo bar\</span\>@, and similarly for+-- @abbr:desc@ (uses @\<abbr title=\"desc\"\>@) and @id:name@ (uses @\<a+-- id=\"name\"\>@)+#mkopt "noPseudoProtocols", MKD_NO_EXT++-- | Disables converstion of @A^B@ into @A\<sup\>B\</sup\>@.+#mkopt "noSuperscripts", MKD_NOSUPERSCRIPT++-- | Disables relaxed emphasis, allowing underscores to indicate+-- emphasis in the middle of a word. With relaxed emphasis on+-- (i.e. without this option) @foo_bar_@ will parse as+-- @foo_bar_@. With it off, it parses as @foo\<em\>bar\</em\>@.+#mkopt "noRelaxedEmphasis", MKD_NORELAXED++-- | Disables PHP Markdown Extra-style tables. See the documentation+-- on PHP Markdown Extra at+-- <http://michelf.com/projects/php-markdown/extra/#table>.+#mkopt "noTables", MKD_NOTABLES++-- | Disables @~~strikethrough~~@.+#mkopt "noStrikethrough", MKD_NOSTRIKETHROUGH+++-- | Disables Pandoc-style header processing. This does not disable+-- headers like+--+-- > This+-- > ====+-- > # or this++#mkopt "noHeaders", MKD_NOHEADER++-- | Disables div-style quotes. Div-style quotes translates+--+-- > > %class%+-- > > foo+--+-- as @\<div class=\"class\"\>foo\</div\>@.+#mkopt "noDivQuotes", MKD_NODIVQUOTE++-- | Disables alphanumeric-ordered lists.+#mkopt "noAlphaLists", MKD_NOALPHALIST+++-- | Disables definition lists.+#mkopt "noDefinitionLists", MKD_NODLIST++-- | Process Markdown even inside an HTML tag.+#mkopt "tagText", MKD_TAGTEXT++-- | Only allow links that are local or that point to @http@, @https@,+-- @news@, or @ftp@ schemes.+#mkopt "safeLinks", MKD_SAFELINK++-- | Expand tabs to 4 spaces.+#mkopt "tabStop", MKD_TABSTOP++-- | Enable Markdown Extra style footnotes. See+-- <http://michelf.com/projects/php-markdown/extra/#footnotes>. For example:+--+-- > Here's some text with a footnote.[^1]+-- >+-- > [^1]: Here's a footnote with some text.+--+-- Footnotes have backlinks to their parent.+#mkopt "footnotes", MKD_EXTRA_FOOTNOTE++-- | Disables all discount features not in the original Markdown spec:+-- SmartyPants, relaxed emphasis, pseudo-protocols, strikethrough,+-- headers, alphabetical lists, definition lists, superscripts, and+-- tables.+compatOptions :: [DiscountOption]+compatOptions = [noSmartyPants, noRelaxedEmphasis, noPseudoProtocols, noStrikethrough, noHeaders, noAlphaLists, noDefinitionLists, noSuperscripts, noTables]+
+ Text/Discount/Internal.hs view
@@ -0,0 +1,24 @@+{-# LANGUAGE ForeignFunctionInterface #-}+module Text.Discount.Internal where++import Data.Bits+import Foreign.C+import Foreign.Ptr+++-- |An option flag to be passed to the discount parser.+newtype DiscountOption = DiscountOption { unDiscountOption :: CInt } deriving (Eq, Show)++data MMIOT = MMIOT+type MMIOPtr = Ptr MMIOT++foreign import ccall unsafe "mkdio.h mkd_string" mkd_string :: CString -> CInt -> CInt -> IO MMIOPtr+foreign import ccall unsafe "mkdio.h mkd_compile" mkd_compile :: MMIOPtr -> CInt -> IO CInt+foreign import ccall unsafe "mkdio.h mkd_document" mkd_document :: MMIOPtr -> Ptr CString -> IO CInt+foreign import ccall unsafe "mkdio.h mkd_cleanup" mkd_cleanup :: MMIOPtr -> IO ()+++-- |INTERNAL USE ONLY. Combine a list of 'DiscountOption' values into+-- a single flag.+combineOptions :: [DiscountOption] -> DiscountOption+combineOptions = DiscountOption . foldr ((.|.) . unDiscountOption) 0
+ discount.cabal view
@@ -0,0 +1,24 @@+name: discount+version: 0.1+synopsis: Haskell bindings to the discount Markdown library.+description: Discount is a thin wrapper around the discount library <http://www.pell.portland.or.us/~orc/Code/discount/> for parsing Markdown. It supports both additional features such as definition lists and tables, while also having a mode for pure Markdown.+homepage: http://github.com/veinor/discount+license: MIT+license-file: LICENSE+author: Patrick Hurst+maintainer: phurst@amateurtopologist.com+category: Text+build-type: Simple+cabal-version: >=1.8++library+ extra-libraries: markdown+ exposed-modules: Text.Discount+ other-modules: Text.Discount.Internal+ build-depends: base >= 4.3 && < 5+ , text+ , bytestring >= 0.8++source-repository head+ type: git+ location: https://github.com/veinor/discount