heist-1.1.0.1: An Haskell template system supporting both HTML5 and XML.

Safe Haskell | None
Language | Haskell98

Heist.Splices.Markdown

Contents

- Exceptions
- Markdown Splice
- Generic pandoc splice
  - Pandoc Options
  - Lens for `PandocOptions`

Description

The "markdown" splice formats markdown content as HTML and inserts it into the document.

If the file attribute is present the contents of the tag is ignored and the file specified is converted to HTML.

Otherwise the non-markup children of the tag are processed as markdown and converted to HTML.

This splice requires that the "pandoc" executable is in your path.

You can add custom pandoc splice with `pandocSplice`. It is not limited to markdown input, and can process anything pandoc can.

For example you can create a page with generated table of contents, using heist template as pandoc template.

     <!-- _wrap.tpl -->
     <html>
       <head> <title> <pageTitle/> </title> </head>

       <div class="nav"> <pageToc/> </div>
       <apply-content/>
     </html>

And pandoc template, which would bind `pageTitle` and `pageToc` splices and applies "_wrap" template.

     <!-- _pandoc.tpl -->
     <apply template="_wrap.tpl">
       <bind tag="pageTitle"> $title$</bind>
       <bind tag="pageToc"> $toc$</bind>
       $body$
     </apply>

Bind splice pandoc splice. Set it to not wrap in div, or it will break html from _wrap.tpl

     splices = "docmarkdown" ## pandocSplice opts
       where
         opts = setPandocArgs  ["-S", "--no-wrap", "--toc"
                               , "--standalone"
                               , "--template", "_pandoc.tpl"
                               , "--html5"]
                $ setPandocWrapDiv Nothing
                $ defaultPandocOptions

And then use it to render your markdown file

     <!-- apidocs.tpl -->
     <DOCTYPE html>
     <html lang="en">
     <head>
       <link href="/static/css/site.css rel="stylesheet">
     </head>
     <body>
       <apply template="_navbar.tpl" />
       <docmarkdown file="apidocs.md"/>
     </body>

Synopsis

- data PandocMissingException
- data MarkdownException
- data NoMarkdownFileException
- markdownTag :: Text
- markdownSplice :: MonadIO m => Splice m
- pandocSplice :: MonadIO m => PandocOptions -> Splice m
- data PandocOptions
- defaultPandocOptions :: PandocOptions
- setPandocExecutable :: FilePath -> PandocOptions -> PandocOptions
- setPandocArgs :: [String] -> PandocOptions -> PandocOptions
- setPandocBaseDir :: Maybe FilePath -> PandocOptions -> PandocOptions
- setPandocWrapDiv :: Maybe Text -> PandocOptions -> PandocOptions
- pandocExecutable :: Functor f => (FilePath -> f FilePath) -> PandocOptions -> f PandocOptions
- pandocArgs :: Functor f => ([String] -> f [String]) -> PandocOptions -> f PandocOptions
- pandocBaseDir :: Functor f => (Maybe FilePath -> f (Maybe FilePath)) -> PandocOptions -> f PandocOptions
- pandocWrapDiv :: Functor f => (Maybe Text -> f (Maybe Text)) -> PandocOptions -> f PandocOptions

# Exceptions

data PandocMissingException Source #

#### Instances

Instances details

Show PandocMissingException Source # |
Instance details Defined in Heist.Splices.Markdown Methods showsPrec :: Int -> PandocMissingException -> ShowS show :: PandocMissingException -> String showList :: [PandocMissingException] -> ShowS
Exception PandocMissingException Source # |
Instance details Defined in Heist.Splices.Markdown Methods toException :: PandocMissingException -> SomeException # fromException :: SomeException -> Maybe PandocMissingException # displayException :: PandocMissingException -> String #

data MarkdownException Source #

#### Instances

Instances details

Show MarkdownException Source # |
Instance details Defined in Heist.Splices.Markdown Methods showsPrec :: Int -> MarkdownException -> ShowS show :: MarkdownException -> String showList :: [MarkdownException] -> ShowS
Exception MarkdownException Source # |
Instance details Defined in Heist.Splices.Markdown Methods toException :: MarkdownException -> SomeException # fromException :: SomeException -> Maybe MarkdownException # displayException :: MarkdownException -> String #

data NoMarkdownFileException Source #

#### Instances

Instances details

Show NoMarkdownFileException Source # |
Instance details Defined in Heist.Splices.Markdown Methods showsPrec :: Int -> NoMarkdownFileException -> ShowS show :: NoMarkdownFileException -> String showList :: [NoMarkdownFileException] -> ShowS
Exception NoMarkdownFileException Source # |
Instance details Defined in Heist.Splices.Markdown Methods toException :: NoMarkdownFileException -> SomeException # fromException :: SomeException -> Maybe NoMarkdownFileException # displayException :: NoMarkdownFileException -> String #

# Markdown Splice

markdownTag :: Text Source #

Default name for the markdown splice.

markdownSplice :: MonadIO m => Splice m Source #

Default markdown splice with executable "pandoc"

# Generic pandoc splice

pandocSplice :: MonadIO m => PandocOptions -> Splice m Source #

Implementation of the markdown splice.

## Pandoc Options

data PandocOptions Source #

#### Instances

Instances details

Eq PandocOptions Source # |
Instance details Defined in Heist.Splices.Markdown Methods (==) :: PandocOptions -> PandocOptions -> Bool (/=) :: PandocOptions -> PandocOptions -> Bool
Ord PandocOptions Source # |

Instance details

Defined in Heist.Splices.Markdown

Methods

compare :: PandocOptions -> PandocOptions -> Ordering

(<) :: PandocOptions -> PandocOptions -> Bool

(<=) :: PandocOptions -> PandocOptions -> Bool

(>) :: PandocOptions -> PandocOptions -> Bool

(>=) :: PandocOptions -> PandocOptions -> Bool

max :: PandocOptions -> PandocOptions -> PandocOptions

min :: PandocOptions -> PandocOptions -> PandocOptions

Show PandocOptions Source # |
Instance details Defined in Heist.Splices.Markdown Methods showsPrec :: Int -> PandocOptions -> ShowS show :: PandocOptions -> String showList :: [PandocOptions] -> ShowS

defaultPandocOptions :: PandocOptions Source #

Default options

setPandocExecutable :: FilePath -> PandocOptions -> PandocOptions Source #

Name of pandoc executable

setPandocArgs :: [String] -> PandocOptions -> PandocOptions Source #

Arguments passed to pandoc

setPandocBaseDir :: Maybe FilePath -> PandocOptions -> PandocOptions Source #

Base directory for input files, defaults to current template dir

setPandocWrapDiv :: Maybe Text -> PandocOptions -> PandocOptions Source #

Wrap pandoc output in div with class. Appends node attributes to div and appends class to ones specified on node.

## Lens for `PandocOptions`

pandocExecutable :: Functor f => (FilePath -> f FilePath) -> PandocOptions -> f PandocOptions Source #

pandocArgs :: Functor f => ([String] -> f [String]) -> PandocOptions -> f PandocOptions Source #

pandocBaseDir :: Functor f => (Maybe FilePath -> f (Maybe FilePath)) -> PandocOptions -> f PandocOptions Source #

pandocWrapDiv :: Functor f => (Maybe Text -> f (Maybe Text)) -> PandocOptions -> f PandocOptions Source #