Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML front matter #12

Closed
gregwebs opened this issue Jun 23, 2013 · 5 comments
Closed

YAML front matter #12

gregwebs opened this issue Jun 23, 2013 · 5 comments

Comments

@gregwebs
Copy link

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
Copy link
Owner

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

@gregwebs
Copy link
Author

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
Copy link
Owner

I have no objection to that.

@gregwebs
Copy link
Author

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

@snoyberg
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants