Git Product home page Git Product logo

pandoc-server's Introduction

pandoc-server

Note: This project is obsolete. Starting with version 2.19.2, pandoc itself can be run as a full-featured server. See the pandoc documentation for details.


A small example of a servant-based server for doing pandoc conversions. Customize to fit your needs!

Installation

You will need stack or cabal. With stack:

% stack install

The executable will be put in ~/.local/bin, so make sure this is in your path.

Running the server

% pandoc-server

This makes the server available at localhost port 8080.

Using the server

There are two endpoints.

/convert expects a POST request with a JSON body containing the following fields:

  • text (text to convert)
  • from (defaults to "markdown")
  • to (defaults to "html")
  • wrapText ("WrapAuto" (default), "WrapNone", or "WrapPreserve")
  • columns (integer, defaults to 72)
  • standalone (boolean, defaults to false)
  • template (defaults to the default template for the output format)

Example of use (with httpie):

% http POST http://localhost:8080/convert text=:+1: from=markdown+emoji to=mediawiki Accept:text/plain
HTTP/1.1 200 OK
Content-Type: text/plain;charset=utf-8
Date: Wed, 30 Jun 2021 15:51:15 GMT
Server: Warp/3.3.16
Transfer-Encoding: chunked

<span class="emoji" data-emoji="+1">๐Ÿ‘</span>

/convert-batch expects a POST request with a JSON body containing a list of JSON objects of the sort provided to /convert. (This can be used to save on network overhead.)

It returns a JSON list of the converted results.

Example of use (with curl):

% cat d.json
[
  {
    "from": "markdown",
    "to": "latex",
    "text": "*Hello* world."
  },
  {
    "from": "markdown",
    "to": "html",
    "text": "*Hello* world."
  }
]
% curl -d @d.json -H Content-Type:application/json -H Accept:application/json http://127.0.0.1:8080/convert-batch
["\\emph{Hello} world.","<p><em>Hello</em> world.</p>"]%

Performance

Measured with ab on a 2.3 GHz i9 MacBook Pro:

  • For 10,000 sequential conversions of a very short text from markdown to latex, 2852 requests per second.

  • With 10 parallel threads making requests, 4081 requests per second.

Better performance can be achieved by using /convert-batch.

pandoc-server's People

Contributors

jgm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.