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

JS helper libraries / functions #86

Open
ivandov opened this issue Dec 8, 2021 · 2 comments
Open

JS helper libraries / functions #86

ivandov opened this issue Dec 8, 2021 · 2 comments

Comments

@ivandov
Copy link

ivandov commented Dec 8, 2021

Are there any JS client libraries or helper functions available for generation of the json objects that are needed to be created to inject into the array supplied to the json2md function?

I'm looking to create some helper functions like

  • getHeader(level, text)
  • getParagraph(text)
  • getCodeBlock(code, language, content)

I'd imagine some of these types of functions were already implemented elsewhere by the projects that consume this library.

Are there patterns for these helper type functions being established somewhere or tracked alongside this repo?

@IonicaBizau
Copy link
Owner

That's a great idea! It could be done, of course.

Something like this would work:

const h1 = h1 => ({ h1 })
const code = (language, content) => ({ code: { language, content } })
console.log(json2md([
    h1("JSON To Markdown")
  , code("js", `function sum (a, b) {
       return a + b;
    }`)
]))

@ivandov
Copy link
Author

ivandov commented Dec 9, 2021

Going further, I have various parts of my code that generate document sections.

So the functions you're defining like h1 and code would actually be used to generate that doc section and I'd append to the json2md array as needed.

I just wanted to mention that in case it was thought that I'd be calling these helper functions instead of passing the required objects into the array.

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

No branches or pull requests

2 participants