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-ts

v1.0.5

Published

![Support Node of LTS](https://img.shields.io/badge/node-LTS-brightgreen.svg?style=plastic) ![npm version](https://img.shields.io/badge/npm-7.16.0-brightgreen.svg?style=plastic) ![Build passing](https://img.shields.io/badge/build-passing%20Typescript-brig

Downloads

371

Readme

pandoc-ts

Support Node of LTS npm version Build passing Support dependencies pandoc License mit


Description

pandoc-ts is a pure typescript wrapper for nodejs of pandoc. Main purpose of this library is to provide synchronous and asynchronous methods to convert documents in all formats supported by pandoc.

How to use

Install dependencies:

You need to install pandoc and add it to the system path to use this library.
To install pandoc follow the official procedure at https://pandoc.org/installing.html

Import in node js

After pandoc is installed, simple run:

npm install --save pandoc-ts

or

yarn add pandoc-ts

Use in your project

Typescript

import { Pandoc, PandocOutFormat, PandocData } from "pandoc-ts";

Javascript

const pandoc = require("pandoc-ts");
const Pandoc = pandoc.Pandoc;
const PandocOutFormat = pandoc.PandocOutFormat;
const PandocData = pandoc.PandocData;

Configuration

To use corverter you have to configure the output format you need and create an instance of converter.

Typescript

const outFormats: PandocOutFormat[] = [
  {
    name: String,
    format: String,
    fname: String,
    outBin: Boolean,
    enc: String,
  },
  ...
];
const pandocInstance = new Pandoc('format', outFormats);
const outFormats = [
  {
    name: String,
    format: String,
    fname: String,
    outBin: Boolean,
    enc: String,
  },
  ...
];
const pandocInstance = new Pandoc('format', outFormats);

Where:

  • name: friendly name for the output
  • format: Pandoc format name for input or output see here for more details
  • fname: define the output file name for current format
  • outBin: if true the current format output will be returned in raw buffer format
  • enc: if outBin is false and fname is not defined set the output content encoding. For more information see here

outFormats: could also be single object rather than an array

Convert

Now you can call conversion function in the instance you created.

Typescript

pandocInstance.convert("text", callback);
pandocInstance.convertFile("file-name", callback);

// or async

const result: PandocData = await pandocInstance.convertAsync("text");
const result: PandocData = await pandocInstance.convertFileAsync("file-name");

Javascript

pandocInstance.convert("text", callback);
pandocInstance.convertFile("file-name", callback);

// or async

const result = await pandocInstance.convertAsync("text");
const result = await pandocInstance.convertFileAsync("file-name");

Where:

  • text: string text to convert in the specific format
  • file-name: name of the file to convert
  • callback: function to call when the operation is completed

Callback signature: (data: PandocData, err: Error | null) => void
where data is a PandocData value and Error is Nodejs Error

PandocData is defined as { [format: string]: string | Buffer } | null.
A nullable key value-value pair where key is the name of the out format and value is the result of coversion.

Example

In this sample we convert a docx file (input.docx) in two format.

  • gfm (github markdown)
  • html

First one will be converted in utf-8 string (as default) and shown in console
The second saved in an output file "sample.html"

import { Pandoc, PandocOutFormat } from "pandoc-ts";

const outs: PandocOutFormat[] = [
  { name: "markdown", name: "gfm", outBin: false },
  { name: "markdownFile", name: "gfm", fname: "sample.md" },
  { name: "html", name: "html", fname: "sample.html" },
];

const pandocInstance = new Pandoc("docx", outs);

pandocInstance.convertFile("input.docx", (result, err) => {
  if (err) {
    console.error(err);
  }
  if (result) {
    console.log(result.markdown);
    console.log(result.markdownFile);
    console.log(result.html);
  }
});