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

Safe HaskellNone
LanguageHaskell98

Heist.Splices.Markdown

Contents

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

Exceptions

Markdown Splice

markdownTag :: Text Source #

Default name for the markdown splice.

markdownSplice :: MonadIO m => Splice m Source #

Default markdown splice with executable "pandoc" and options "-S --no-wrap"

Generic pandoc splice

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

Implementation of the markdown splice.

Pandoc Options

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

Internal helper functions

readProcessWithExitCode' Source #

Arguments

:: FilePath

command to run

-> [String]

any arguments

-> ByteString

standard input

-> IO (ExitCode, ByteString, ByteString)

exitcode, stdout, stderr