Safe Haskell | None |
---|---|
Language | Haskell98 |
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>
- 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
- pandoc :: FilePath -> FilePath -> FilePath -> IO ByteString
- pandocBS :: FilePath -> ByteString -> IO ByteString
- readProcessWithExitCode' :: FilePath -> [String] -> ByteString -> IO (ExitCode, ByteString, ByteString)
Exceptions
data MarkdownException Source #
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
data PandocOptions Source #
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 #
Internal helper functions
pandocBS :: FilePath -> ByteString -> IO ByteString Source #
readProcessWithExitCode' Source #
:: FilePath | command to run |
-> [String] | any arguments |
-> ByteString | standard input |
-> IO (ExitCode, ByteString, ByteString) | exitcode, stdout, stderr |