snoyberg / markdown

Convert Markdown to HTML, with XSS protection
BSD 3-Clause "New" or "Revised" License
69 stars 401 forks source link

YAML front matter #12

Closed gregwebs closed 10 years ago

gregwebs commented 11 years ago

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)
snoyberg commented 11 years ago

I'm on the fence about this one... but I think for now it makes more sense as a separate package.

gregwebs commented 11 years ago

what about adding a simple frontmatter parser to the existing package? I have only seen frontmatter used for key: string where string does not have to be quoted when it has spaces, so the common case seems to be both simple and not actually YAML.

snoyberg commented 11 years ago

I have no objection to that.

gregwebs commented 11 years ago

The code above works ok for me now. This issue can serve to document a workaround and a feature request.

snoyberg commented 10 years ago

I've moved the content to the Wiki: https://github.com/snoyberg/markdown/wiki/YAML-front-matter