IonicaBizau/json2md

Json to front matter markdown

cedricdelpoux opened this issue · 3 comments

Hello, Thank you for your amazing lib.

Like you saw by yourself, I used your lib to create markdown content for my Gatsby-source-google-docs plugin.

But what about supporting full markdown features like front metadata?

For now I do a simple conversion but I'm not very happy with this because it could be more complicated, for exemple if I have some nested arrays in front matter.

Do you plan to support this ?

You could use an optional second argument:

json2md([{ h1: "JSON To Markdown" }], {
  tags: ["tag1", "tag2"], 
  authors: [
    {name: "author1", email: "author1@"}, 
    {name: "author2", email: "author2@"}
  ]
})

should transform to

--- 
tags:
  - tag1
  - tag2
authors:
  - name: author1
    email: author1@
  - name: author2
    email: author2@
--- 
# JSON To Markdown

Thank you very much

I just understood frontmatter was yaml do I found a better way to build my file using yamljs:

const json2md = require("json2md")
const YAML = require("yamljs")
... 
const markdown = `---
${YAML.stringify(metadata)}
---
${json2md(content)}`

But I still need to be carefull about the indent. Do you have any tips to handle this?

It's better if we keep the yamljs as separate functionality, not part of this library. YAML should support indent.

Ki-er commented

I know this issue is closed and 3 years old but if someone ever stumbles across it again, this package does frontmatter

https://github.com/easybird/json-to-frontmatter-markdown