Closed Phyks closed 7 years ago
The buf
sent to writer()
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's a len
argument.
Try fwrite(buf, 1, len, stdout);
instead of printf
and see if you get the correct output. In case pandoc()
doesn't add a newline at the end of output (never tested this, so not sure), you may want to add a printf("\n");
right after your pandoc()
call.
So something like this:
#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();
}
Thanks for the explanations!
Hi,
I have a minimal C file using
libpandoc
like this:I would expect the output to be
as given by Pandoc.
However the output ends with a lot of empty newlines, I am not sure why:
Thanks!
P.S.: It would be really useful to have an example code making use of
libpandoc
in the repo. I can submit a PR addressing this, if you want.