npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pandoc-wrapper

v0.3.1

Published

Simple Pandoc Wrapper for NodeJS

Downloads

37

Readme

pandoc-wrapper

MIT License NPM Registry Version

Pandoc Wrapper for NodeJS.

Requires the pandoc executable to be installed. Normally this is in /usr/bin/pandoc. It can be specified in the environmental variable PANDOC_BINARY_PATH if necesary.

sudo apt-get install pandoc   # Ubuntu (most versions of Debian)
apk add --no-cache pandoc     # Alpine v3.17+

# install the package
npm i pandoc-wrapper

# alternatively, install it directly from source
npm i git+https://github.com/valexandersaulys/pandoc-wrapper

Examples of Usage

It's suggested you look at tests/ for examples.

pandoc-wrapper can be used in both async and sync flavors. It defaults to sync if not specified.

Sync

const PandocJS = require("pandoc-wrapper");

// convert a file on disk already and write out
const pandoc = new PandocJS({ runAsAsync: false });
pandoc.convert("/tmp/input.md", "/tmp/output.html", "html");

Note: writing to the filestream is not practically possible in Synchronous execution. This is because of how child processes in node work. You can run it anyway even if async is enabled but a warning will be raised

const PandocJS = require("pandoc-wrapper");

(async () => {
  const pandoc = new PandocJS({ runAsAsync: false });
  await pandoc.sendRawStream(
      "# header",
      "/tmp/output.html",
      "html"
    )
  // WARNING: you have this marked to only run sync but pushing input is always ASYNC
  // $ cat /tmp/output.html 
  // <h1 id="header">header</h1>
})();

Async

const PandocJS = require("pandoc-wrapper");

const pandoc = new PandocJS({ runAsAsync: true });

// convert from file on-disk
pandoc
  .convert("/tmp/input.md", "/tmp/output.html", "bbbb")
  .then(() => {
    // do things with your file, there is no return value
  })
  .catch((err) => {
    // some helpful, build-in exceptions
    if(err.name == "EXECUTABLE_NOT_FOUND")
      console.log("Executable for pandoc not found");
    else if(err.name == "INPUT_FILE_NOT_FOUND")    
      console.log("Could not find input file specified");
    else if(err.name == "INVALID_FILE_FORMAT")
      console.log("File Format specified (e.g. 'html') was not correct");
    else if(err.name == "STDERR_EXCEPTION")
      console.log("All other exceptions generated");
  })    

Testing

npm run test
npm run test:one -- tests/name.of.test.js

You can optionally run the tests in Docker.

bash run-tests-docker.sh

This is particularly helpful if you plan to use this in a container context.

Caveats

No support for Windows either now or in the future. This is because I don't own a Windows machine. I'll accept relevant pull requests around it somebody else is interested in that.

License

MIT