Last active
May 18, 2024 04:22
-
-
Save Orc/97b5711dd8c8a3b371928db756eba6e5 to your computer and use it in GitHub Desktop.
c++ header for discount -- trivially tested (the header compiles, a open/format test program works)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _MKDIO_CXX | |
#define _MKDIO_CXX | |
extern "C" { | |
#include <stdio.h> | |
#include <mkdio.h> | |
} | |
class MKIOT { | |
protected: | |
void *mmiot; | |
MKIOT() { mmiot=0;} /* dummy initializer */ | |
public: | |
MKIOT(FILE* in, mkd_flag_t flags) { mmiot = mkd_in(in,flags); } | |
MKIOT(const char *text, int size, mkd_flag_t flags) | |
{ mmiot = mkd_string(text, size, flags); } | |
~MKIOT() { mkd_cleanup(mmiot); } | |
void basename(char* name) { mkd_basename(mmiot,name); } | |
int compile(mkd_flag_t flags) { return mkd_compile(mmiot,flags); } | |
int dump(FILE *out, int flags, char *text) | |
{ return mkd_dump(mmiot,out,flags,text); } | |
int format(FILE *out, int flags) { return this->compile(flags) | |
&& this->generatehtml(out); } | |
int xhtmlpage(mkd_flag_t flags, FILE *out) | |
{ return mkd_xhtmlpage(mmiot,flags,out); } | |
char *doc_title() { return mkd_doc_title(mmiot); } | |
char *doc_author() { return mkd_doc_author(mmiot); } | |
char *doc_date() { return mkd_doc_date(mmiot); } | |
int document(char **buf_p) { return mkd_document(mmiot, buf_p); } | |
int toc(char **buf_p) { return mkd_toc(mmiot, buf_p); } | |
int css(char **buf_p) { return mkd_css(mmiot, buf_p); } | |
int generatehtml(FILE *out) { return mkd_generatehtml(mmiot, out); } | |
int generatetoc(FILE *out) { return mkd_generatetoc(mmiot, out); } | |
int generatecss(FILE *out) { return mkd_generatecss(mmiot, out); } | |
int style(FILE *out) { return this->generatecss(out); } | |
void e_url(mkd_callback_t f) { mkd_e_url(mmiot, f); } | |
void e_flags(mkd_callback_t f) { mkd_e_flags(mmiot, f); } | |
void e_free(mkd_free_t f) { mkd_e_free(mmiot, f); } | |
void e_data(void *ptr) { mkd_e_data(mmiot, ptr); } | |
char *version() { return markdown_version; } | |
void mmiot_flags(FILE *out, int html) | |
{ mkd_mmiot_flags(out,mmiot,html); } | |
void ref_prefix(char *pfx) { mkd_ref_prefix(mmiot, pfx); } | |
} ; | |
class GFIOT: MKIOT { | |
GFIOT(FILE *in, mkd_flag_t flags) { mmiot = gfm_in(in,flags); } | |
GFIOT(const char *text, int size, mkd_flag_t flags) | |
{ mmiot = gfm_string(text, size, flags); } | |
} ; | |
#endif/*_MKDIO_CXX*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* test program for the mkdio.h++ binding | |
* | |
* compiled (on macos) with the command line | |
* c++ -L/usr/local/lib -I/usr/local/include -o trivial trivial.cc -lmarkdown | |
*/ | |
#include <stdio.h> | |
#include "mkdio.h++" | |
int main(int argc, char **argv) | |
{ | |
if ( argc < 2 ) { | |
fprintf(stderr, "usage: %s file\n", argv[0]); | |
return 1; | |
} | |
FILE *foo = fopen(argv[1], "r"); | |
if ( !foo ) { | |
fprintf(stderr, "cannot open %s\n", argv[1]); | |
return 1; | |
} | |
MKIOT blob(foo, 0); | |
printf("<!-- discount %s -->\n", blob.version() ); | |
blob.format(stdout, 0); | |
blob.dump(stdout, 0, argv[1]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment