pandoc-filter
Pandoc filtering for Node.js
Last updated a month ago by mvhenderson .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install pandoc-filter 
SYNC missed versions from official npm registry.

About

Node.js/TypeScript port of the Python pandocfilters for filtering with Pandoc

Install

npm install -g pandoc-filter

Example

#!/usr/bin/env node

// Pandoc filter to convert all text to uppercase

var pandoc = require("pandoc-filter");
var Str = pandoc.Str;

function action({ t: type, c: value }, format, meta) {
	if (type === "Str") return Str(value.toUpperCase());
}

pandoc.stdio(action);

Async using native promise

#!/usr/bin/env node
"use strict";

var pandoc = require("pandoc-filter");
var rp = require("request-promise-native");
var Str = pandoc.Str;

async function action({ t: type, c: value }, format, meta) {
	if (type === "Str") {
		const data = await rp({
			uri: value,
			json: true,
		});
		return Str(data.places[0]["post code"]);
	}
}

pandoc.stdio(action);

Using TypeScript:

import { stdio, Str } from "pandoc-filter";

stdio((ele) => {
	if (ele.t === "Str") {
		// c is typed as string
		return Str(ele.c.toUpperCase());
	}
	if (ele.t === "Image") {
		// ele.c is typed as a three-tuple
		const [attr, label, target] = ele.c;
		const [url, title] = target;
		return Str("url was " + url);
	}
});

Compatibility Notes

Required node >=v8 for async/await/promise support.

v0.1.6 is required for pandoc versions after 1.17.2 to support the new JSON format. See this issue for details.

Credits

Thanks to John MacFarlane for Pandoc.

License

MIT

Current Tags

  • 2.0.0                                ...           latest (a month ago)

9 Versions

  • 2.0.0                                ...           a month ago
  • 1.0.0                                ...           2 years ago
  • 0.1.8                                ...           3 years ago
  • 0.1.6                                ...           4 years ago
  • 0.1.5                                ...           4 years ago
  • 0.1.4                                ...           4 years ago
  • 0.1.3                                ...           4 years ago
  • 0.1.2                                ...           6 years ago
  • 0.1.0                                ...           6 years ago

Copyright 2014 - 2016 © taobao.org |