All Projects → ShabbyX → Libpandoc

ShabbyX / Libpandoc

C bindings to Pandoc, a markup converter library written in Haskell.

Programming Languages

haskell
3896 projects

Labels

Projects that are alternatives of or similar to Libpandoc

Pandoc Starter
📄 My pandoc markdown templates and makefiles
Stars: ✭ 443 (+532.86%)
Mutual labels:  pandoc
Pandoc Latex Tip
A pandoc filter for adding tip in LaTeX
Stars: ✭ 7 (-90%)
Mutual labels:  pandoc
Go Pandoc
Run pandoc as a service
Stars: ✭ 30 (-57.14%)
Mutual labels:  pandoc
Pandoc Crossref
Pandoc filter for cross-references
Stars: ✭ 528 (+654.29%)
Mutual labels:  pandoc
Marker
🖊 A gtk3 markdown editor
Stars: ✭ 644 (+820%)
Mutual labels:  pandoc
Phd thesis markdown
Template for writing a PhD thesis in Markdown
Stars: ✭ 898 (+1182.86%)
Mutual labels:  pandoc
Letter Boilerplate
Finest letter typesetting from the command line
Stars: ✭ 374 (+434.29%)
Mutual labels:  pandoc
Pandoc Plantuml Filter
Pandoc filter for PlantUML code blocks
Stars: ✭ 51 (-27.14%)
Mutual labels:  pandoc
Vim Pandoc
pandoc integration and utilities for vim
Stars: ✭ 734 (+948.57%)
Mutual labels:  pandoc
Mdviewer
Minimalistic Markdown viewer/converter with built-in Css stylesheets support.
Stars: ✭ 26 (-62.86%)
Mutual labels:  pandoc
Zettlr
A Markdown Editor for the 21st century.
Stars: ✭ 6,099 (+8612.86%)
Mutual labels:  pandoc
Invoice Boilerplate
Simple automated LaTeX invoicing system
Stars: ✭ 604 (+762.86%)
Mutual labels:  pandoc
Easy Pandoc Templates
A collection of portable pandoc templates with no dependencies
Stars: ✭ 23 (-67.14%)
Mutual labels:  pandoc
Asynctasks.vim
🚀 Modern Task System for Project Building, Testing and Deploying !!
Stars: ✭ 495 (+607.14%)
Mutual labels:  pandoc
Cv Boilerplate
Programmatic generation of high-quality CVs
Stars: ✭ 967 (+1281.43%)
Mutual labels:  pandoc
Summarytools
R Package to Quickly and Neatly Summarize Data
Stars: ✭ 390 (+457.14%)
Mutual labels:  pandoc
Crisscross
A Markdown-centric template engine for batch offline document generation.
Stars: ✭ 18 (-74.29%)
Mutual labels:  pandoc
Markdeck
presentations as code - author cool slide decks, text-only, offline-ready, collaborative
Stars: ✭ 1,159 (+1555.71%)
Mutual labels:  pandoc
Thiefmd
The markdown editor worth stealing. Inspired by Ulysses, based on code from Quilter
Stars: ✭ 48 (-31.43%)
Mutual labels:  pandoc
Readteractive
Tool for writing and generating interactive books.
Stars: ✭ 23 (-67.14%)
Mutual labels:  pandoc

libpandoc

The purpose of libpandoc is to make the Haskell library Pandoc available for use from C and other non-Haskell environments that support C FFI. Pandoc and libpandoc support text conversion between HTML, Markdown, LaTeX, OpenDocument and other formats.

Obtaining

The latest version is available at GitHub. libpandoc is licensed under GPL version 2 or later, which is also Pandoc's license.

Installation

Building

Building follows standard Haskell conventions and requires the Haskell Platform:

$ cabal configure [--global]
$ cabal install --only-dependencies
$ cabal build

Or simply:

$ make

A successful build creates the shared library file in ./dist/build/libpandoc.so/libpandoc.so. Installation and use of the library is platform-dependent.

Note: On Windows, you should edit the libpandoc.cabal file to rename the extension of the shared object to dll.

UNIX Installation

The accompanying Makefile contains install and uninstall targets that take care of installing the header and library in /usr.

Windows Installation

For your convenience, an ./install.bat is provided that installs the shared library under %windir%\System32.

Using

C Interface

The C interface is defined in src/pandoc.h. Synopsis:

#include <pandoc.h>

pandoc_init();
char* error = pandoc(1024       /* buffer size */,
                     "markdown" /* input format */,
                     "html"     /* output format */,
                     NULL       /* JSON settings */,
                     reader     /* the reader function */,
                     writer     /* the writer function */,
                     user_data  /* private user data */);
pandoc_exit();

Compile as:

gcc [my-file.c] -lpandoc

Haskell runtime has to be started and stopped explicitly via the init/exit functions. Note that you don't need to restart the Haskell runtime on every call to pandoc. As a matter of fact, you may not even be able to initialize the Haskell runtime after stopping it, e.g. due to this bug of GHC.

The reader function is in the following form:

int reader(char *buf, void *user_data);

Where buf is the buffer to be filled. The size of this buffer is the same as provided as the first argument to the pandoc function. user_data is the same pointer passed as the last argument of the pandoc function. The reader function must fill the buffer with the input to be converted by Pandoc. The return value is the number of characters read. The reader is no longer called when this value is zero.

The writer function is in the following form:

void writer(const char *buf, int len, void *user_data);

Where buf is the buffer to be written, len is the number of elements in the buffer and user_data is the last argument of the pandoc function, similar to user_data of the reader. The writer function must write the contents of the buffer as the output of the conversion by Pandoc. buf is not necessarily NUL-terminated. In fact, most of the time it isn't because the output could be given to writer() in chunks. That's also why there is a len argument.

Input and Output Formats

Input and output formats depend on Pandoc version the library is built against. They are passed as strings. Reader and writer names are the same as understood by Pandoc, for example "html" or "markdown".

JSON Settings

The settings parameter allows to customize the text transformation by passing Pandoc settings as an JSON-encoded string. The JSON format is derived automatically from Pandoc data type declarations by generic programming.

The file defaults.json is a printout of the default settings. NOTE: it may be outdated with respect to the current library version. The custom settings passed by the user are merged with the default settings, so only the fields that have non-default values have to be provided.

C example code

#include <stdlib.h>
#include <string.h>

#include <pandoc.h>

int done = 0;
const char test[] = "$\\textit{K}$ -trivial, $\\textit{K}$ -low and ${{\\mathrm{\\textit{MLR}}}}$ -low Sequences: A Tutorial";
const int BUFFER_LENGTH = 1024;

int reader(char *buf, void *user_data) {
    if (done) {
        return 0;
    }
    strncpy(buf, test, BUFFER_LENGTH);
    done = 1;
    return strlen(test);
}

void writer(const char *buf, int len, void *user_data) {
    fwrite(buf, 1, len, stdout);
}

int main() {
    pandoc_init();
    pandoc(BUFFER_LENGTH, "markdown", "plain", NULL, &reader, &writer, NULL);
    printf("\n");      /* if desired */
    pandoc_exit();
}

Other Interfaces

Changelog

  • 0.8
    • Switched to JSON format for settings instead of XML
    • Completed support for all Pandoc readers and writers
    • Updated to Pandoc version 1.16 and higher
  • 0.7 - Updated to Pandoc version 1.13 and higher
  • 0.6 - Updated to Pandoc version 1.10 and higher
  • 0.5 - Implemented XML generics to support all config settings.

Authors

Original author is Anton Tayanovskyy [email protected].

Shahbaz Youssefi [email protected] is the current maintainer. Bug reports and feature requests are welcome.

Additional Contributers:

  • Katherine Whitlock
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].