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

Programmatic API #25

Closed
simonhaenisch opened this issue Jan 1, 2019 · 3 comments
Closed

Programmatic API #25

simonhaenisch opened this issue Jan 1, 2019 · 3 comments

Comments

@simonhaenisch
Copy link
Owner

To make the package easier to use as a dependency of other packages, a programmatic API would probably be helpful for some people. Should be a pretty straight-forward refactoring task.

@ceddybi
Copy link

ceddybi commented Jan 18, 2019

@simonhaenisch Can we use this in a node app?

simonhaenisch added a commit that referenced this issue Jan 20, 2019
This refactors the main convertToPdf function and exposes it from `util/md-to-pdf.js`, so it can be shared between the new programmatic API and the CLI. The CLI has been moved to `cli.js` and `index.js` exposes a wrapper around `mdToPdf` instead.

Closes #25
@simonhaenisch
Copy link
Owner Author

simonhaenisch commented Jan 20, 2019

@ceddybi I just worked on this and got something ready, however it'll be a very simplistic API for now (basically it'll expose a function mdToPdf() that accepts a path to a markdown file and a config object).

Here's an example of how to use it:

const mdToPdf = require('md-to-pdf');
 
(async () => {
    const pdf = await mdToPdf('readme.md', { dest: 'readme.pdf' }).catch(console.error);
 
    if (pdf) {
        console.log(pdf.filename);
    }
})();

I'm planning on changing the API to accept a list of files and to allow for concurrent conversions, however that'll require a couple more changes and one breaking change.

I'll make this available in the next release. Just need to update the readme.

@simonhaenisch
Copy link
Owner Author

@ceddybi this is now released in v2.5.0 (:

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