Skip to content
Greg Weber edited this page Aug 29, 2014 · 3 revisions

From: https://github.com/snoyberg/markdown/issues/12

This adds a yaml dependency. Should it be a separate package then? What should it be called?

Or would it be better for markdown to roll its own frontmatter parser that assumes a simpler YAML

renderMarkdownFile :: FilePath
                   -> IO ((M.HashMap Text Text), Html) -- HashMap is YAML frontmatter
renderMarkdownFile filename = do
    contents <- shelly (readfile filename)
    let (frontMatter, rest) = case LT.stripPrefix "---" contents of  
            Nothing -> (mempty, contents)
            Just firstMarkerStripped ->
                LT.breakOn "---\n" (LT.stripStart firstMarkerStripped)
    let mResult = decode $ encodeUtf8 $ LT.toStrict $ frontMatter
    return (maybe M.empty id mResult, markdown def { msXssProtect = False } rest)
Clone this wiki locally