markdown-0.1.17.5: Convert Markdown to HTML, with XSS protection

Safe Haskell | None
Language | Haskell2010

Text.Markdown

Contents

- Functions
- Settings
- Newtype
- Fenced handlers
- Convenience re-exports

Synopsis

- markdown :: MarkdownSettings -> Text -> Html
- data MarkdownSettings
- defaultMarkdownSettings :: MarkdownSettings
- msXssProtect :: MarkdownSettings -> Bool
- msStandaloneHtml :: MarkdownSettings -> Set Text
- msFencedHandlers :: MarkdownSettings -> Map Text (Text -> FencedHandler)
- msBlockCodeRenderer :: MarkdownSettings -> Maybe Text -> (Text, Html) -> Html
- msLinkNewTab :: MarkdownSettings -> Bool
- msBlankBeforeBlockquote :: MarkdownSettings -> Bool
- msBlockFilter :: MarkdownSettings -> [Block [Inline]] -> [Block [Inline]]
- msAddHeadingId :: MarkdownSettings -> Bool
- setNoFollowExternal :: MarkdownSettings -> MarkdownSettings
- newtype Markdown = Markdown Text
- data FencedHandler
  - = FHRaw (Text -> [Block Text])
  - | FHParsed ([Block Text] -> [Block Text])
- codeFencedHandler :: Text -> Map Text (Text -> FencedHandler)
- htmlFencedHandler :: Text -> (Text -> Text) -> (Text -> Text) -> Map Text (Text -> FencedHandler)
- def :: Default a => a

# Functions

markdown :: MarkdownSettings -> Text -> Html Source #

Convert the given textual markdown content to HTML.

    >>> :set -XOverloadedStrings
    >>> import Text.Blaze.Html.Renderer.Text
    >>> renderHtml $ markdown def "# Hello World!"
    "<h1>Hello World!</h1>"

    >>> renderHtml $ markdown def { msXssProtect = False } "<script>alert('evil')</script>"
    "<script>alert('evil')</script>"

# Settings

data MarkdownSettings Source #

A settings type providing various configuration options.

See http://www.yesodweb.com/book/settings-types for more information on settings types. In general, you can use `def`.

#### Instances

Instances details

Default MarkdownSettings Source # |
Instance details Defined in Text.Markdown.Types Methods def :: MarkdownSettings Source #

defaultMarkdownSettings :: MarkdownSettings Source #

Since: 0.1.15

msXssProtect :: MarkdownSettings -> Bool Source #

Whether to automatically apply XSS protection to embedded HTML. Default: `True`.

msStandaloneHtml :: MarkdownSettings -> Set Text Source #

HTML snippets which stand on their own. We do not require a blank line following these pieces of HTML.

Default: empty set.

Since: 0.1.2

msFencedHandlers :: MarkdownSettings -> Map Text (Text -> FencedHandler) Source #

Handlers for the special "fenced" format. This is most commonly used for fenced code, e.g.:

    ```haskell
    main = putStrLn "Hello"
    ```

This is an extension of Markdown, but a fairly commonly used one.

This setting allows you to create new kinds of fencing. Fencing goes into two categories: parsed and raw. Code fencing would be in the raw category, where the contents are not treated as Markdown. Parsed will treat the contents as Markdown and allow you to perform some kind of modifcation to it.

For example, to create a new `@@@` fencing which wraps up the contents in an `article` tag, you could use:

    def { msFencedHandlers = htmlFencedHandler "@@@" (const "<article>") (const "</article")
                 `Map.union` msFencedHandlers def
        }

Default: code fencing for ````` and `~~~`.

Since: 0.1.2

msBlockCodeRenderer :: MarkdownSettings -> Maybe Text -> (Text, Html) -> Html Source #

A rendering function through which code blocks are passed.

The arguments are the block's language, if any, and the tuple `(unrendered content, rendered content)`. For example, if you wanted to pass code blocks in your markdown text through a highlighter like `highlighting-kate`, you might do something like:

    >>> :set -XOverloadedStrings
    >>> let renderer lang (src,_) = formatHtmlBlock defaultFormatOpts $ highlightAs (maybe "text" unpack lang) $ unpack src
    >>> let md = markdown def { msBlockCodeRenderer = renderer } "``` haskell\nmain = putStrLn \"Hello world!\"\n```"
    >>> putStrLn $ renderHtml md
    <pre class="sourceCode"><code class="sourceCode">main <span class="fu">=</span> <span class="fu">putStrLn</span> <span class="st">&quot;Hello world!&quot;</span></code></pre>

Since: 0.1.2.1

msLinkNewTab :: MarkdownSettings -> Bool Source #

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 :: MarkdownSettings -> Bool Source #

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 :: MarkdownSettings -> [Block [Inline]] -> [Block [Inline]] Source #

A function to filter and/or modify parsed blocks before they are written to Html

Default: `id`

Since 0.1.7

msAddHeadingId :: MarkdownSettings -> Bool Source #

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

    <h2 id="executive-summary">Executive Summary</h2>

Default: `False`

Since 0.1.13

setNoFollowExternal :: MarkdownSettings -> MarkdownSettings Source #

For external links, add the rel="nofollow" attribute

Since: 0.1.16

# Newtype

newtype Markdown Source #

A newtype wrapper providing a `ToHtml` instance.

Constructors

Markdown Text |

#### Instances

Instances details

ToMarkup Markdown Source # |
Instance details Defined in Text.Markdown Methods toMarkup :: Markdown -> Markup Source # preEscapedToMarkup :: Markdown -> Markup Source #
Monoid Markdown Source # |
Instance details Defined in Text.Markdown Methods mempty :: Markdown Source # mappend :: Markdown -> Markdown -> Markdown Source # mconcat :: [Markdown] -> Markdown Source #
Semigroup Markdown Source # |
Instance details Defined in Text.Markdown Methods (<>) :: Markdown -> Markdown -> Markdown Source # sconcat :: NonEmpty Markdown -> Markdown Source # stimes :: Integral b => b -> Markdown -> Markdown Source #
IsString Markdown Source # |
Instance details Defined in Text.Markdown Methods fromString :: String -> Markdown Source #
Show Markdown Source # |
Instance details Defined in Text.Markdown Methods showsPrec :: Int -> Markdown -> ShowS Source # show :: Markdown -> String Source # showList :: [Markdown] -> ShowS Source #
Eq Markdown Source # |
Instance details Defined in Text.Markdown Methods (==) :: Markdown -> Markdown -> Bool Source # (/=) :: Markdown -> Markdown -> Bool Source #
Ord Markdown Source # |
Instance details Defined in Text.Markdown Methods compare :: Markdown -> Markdown -> Ordering Source # (<) :: Markdown -> Markdown -> Bool Source # (<=) :: Markdown -> Markdown -> Bool Source # (>) :: Markdown -> Markdown -> Bool Source # (>=) :: Markdown -> Markdown -> Bool Source # max :: Markdown -> Markdown -> Markdown Source # min :: Markdown -> Markdown -> Markdown Source #

# Fenced handlers

data FencedHandler Source #

See 'msFencedHandlers.

Since 0.1.2

Constructors

FHRaw (Text -> [Block Text]) | Wrap up the given raw content.
FHParsed ([Block Text] -> [Block Text]) | Wrap up the given parsed content.

codeFencedHandler Source #

Arguments

:: Text | Delimiter
-> Map Text (Text -> FencedHandler) |

Helper for creating a `FHRaw`.

Since 0.1.2

htmlFencedHandler Source #

Arguments

:: Text | Delimiter
-> (Text -> Text) | start HTML
-> (Text -> Text) | end HTML
-> Map Text (Text -> FencedHandler) |

Helper for creating a `FHParsed`.

Note that the start and end parameters take a `Text` parameter; this is the text following the delimiter. For example, with the markdown:

    @@@ foo

`foo` would be passed to start and end.

Since 0.1.2

# Convenience re-exports

def :: Default a => a Source #

The default value for this type.