mrb_value mrb_discount_md2html(mrb_state *mrb, mrb_value self) { mrb_md_context *md_ctx = mrb_md_get_context(mrb, self, "mrb_md_context"); MMIOT *md; mrb_value md_obj; int size; char *html, *title; mrb_value header, footer, data; mrb_get_args(mrb, "o", &md_obj); md = mkd_string(RSTRING_PTR(md_obj), strlen(RSTRING_PTR(md_obj)), 0); mkd_compile(md, MKD_TOC|MKD_AUTOLINK); title = mkd_doc_title(md); if (title) { md_ctx->title = title; } if ((size = mkd_document(md, &html)) == EOF) { mrb_raise(mrb, E_RUNTIME_ERROR, "mkd_document() failed"); } header = mrb_discount_header(mrb, self); footer = mrb_discount_footer(mrb, self); data = mrb_str_plus(mrb, header, mrb_str_new(mrb, html, strlen(html))); data = mrb_str_plus(mrb, data, footer); mkd_cleanup(md); return data; }
/* * GC Free function */ static void bluecloth_gc_free( MMIOT *document ) { if ( document ) { mkd_cleanup( document ); document = NULL; } }
static VALUE rb_rdiscount_toc_content(int argc, VALUE *argv, VALUE self) { char *res; int szres; int flags = rb_rdiscount__get_flags(self); /* grab char pointer to markdown input text */ VALUE text = rb_funcall(self, rb_intern("text"), 0); Check_Type(text, T_STRING); /* allocate a ruby string buffer and wrap it in a stream */ VALUE buf = rb_str_buf_new(4096); MMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags); if ( mkd_compile(doc, flags) ) { szres = mkd_toc(doc, &res); if ( szres != EOF ) { rb_str_cat(buf, res, szres); rb_str_cat(buf, "\n", 1); } } mkd_cleanup(doc); return buf; }
static VALUE rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self) { /* grab char pointer to markdown input text */ char *res; int szres; VALUE encoding; VALUE text = rb_funcall(self, rb_intern("text"), 0); VALUE buf = rb_str_buf_new(1024); Check_Type(text, T_STRING); int flags = rb_rdiscount__get_flags(self); MMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags); if ( mkd_compile(doc, flags) ) { szres = mkd_document(doc, &res); if ( szres != EOF ) { rb_str_cat(buf, res, szres); rb_str_cat(buf, "\n", 1); } } mkd_cleanup(doc); /* force the input encoding */ if ( rb_respond_to(text, rb_intern("encoding")) ) { encoding = rb_funcall(text, rb_intern("encoding"), 0); rb_funcall(buf, rb_intern("force_encoding"), 1, encoding); } return buf; }
/* Convert a given markdown file into a HTML file. */ int convert_file(const char *path_in, const char *path_out) { FILE *fin = fopen(path_in, "r"); if (!fin) { printf("Error opening file <%s>\n%s\n", path_in, strerror(errno)); return 1; } FILE *fout = fopen(path_out, "aw"); if (!fout) { printf("Error opening file <%s>\n%s\n", path_out, strerror(errno)); return 1; } Document *doc = mkd_in(fin, 0); if (!doc) { printf("Unknown libmarkdown error calling mkd_in()."); return 1; } int res = 0; if (markdown(doc, fout, 0)) { printf("Unknown libmarkdown error calling markdown()."); res = 1; } fclose(fin); fclose(fout); mkd_cleanup(doc); return res; }
int markdown(Document *document, FILE *out, int flags) { if ( mkd_compile(document, flags) ) { mkd_generatehtml(document, out); mkd_cleanup(document); return 0; } return -1; }
void Markdown(sLONG_PTR *pResult, PackagePtr pParams) { C_TEXT Param1; C_TEXT Param2; C_LONGINT Param3; C_LONGINT Param4; C_LONGINT returnValue; Param1.fromParamAtIndex(pParams, 1); Param3.fromParamAtIndex(pParams, 3); Param4.fromParamAtIndex(pParams, 4); CUTF8String src; Param1.copyUTF8String(&src); mkd_flag_t flags; flags = (mkd_flag_t)Param3.getIntValue(); if(MKD_WITH_HTML5_TAGS && Param4.getIntValue()) mkd_with_html5_tags(); Document *doc; if(MKD_GITHUB_FLAVOURED && Param4.getIntValue()) { doc = gfm_string((const char *)src.c_str(), src.length(), flags); }else{ doc = mkd_string((const char *)src.c_str(), src.length(), flags); } if(doc) { if(mkd_compile(doc, flags)) { std::ostringstream outstream; mkd_generatecss(doc, outstream); mkd_generatetoc(doc, outstream); mkd_generatehtml(doc, outstream); std::string dst = outstream.str(); Param2.setUTF8String((const uint8_t *)dst.c_str(), dst.length()); }else{returnValue.setIntValue(errno);} mkd_cleanup(doc); }else{returnValue.setIntValue(errno);} mkd_deallocate_tags(); Param2.toParamAtIndex(pParams, 2); returnValue.setReturn(pResult); }
void markdown_output(MMIOT *doc, request_rec *r) { char *title; int ret; int size; char *p; markdown_conf *conf; list_t *css; conf = (markdown_conf *) ap_get_module_config(r->per_dir_config, &markdown_module); ret = mkd_compile(doc, MKD_TOC|MKD_AUTOLINK); ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", r); ap_rputs("<!DOCTYPE html PUBLIC \n" " \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n" " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n", r); ap_rputs("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n", r); ap_rputs("<head>\n", r); if (conf->css) { ap_rputs("<meta http-equiv=\"Content-Type\"" " content=\"text/html; charset=UTF-8\" />\n", r); ap_rputs("<meta http-equiv=\"Content-Style-Type\"" " content=\"text/css\" />\n", r); css = conf->css; do{ ap_rprintf(r, "<link rel=\"stylesheet\" href=\"%s\"" " type=\"text/css\" />\n", (char *)css->data); css = (list_t *)css->next; }while(css); } title = mkd_doc_title(doc); if (title) { ap_rprintf(r, "<title>%s</title>\n", title); } ap_rputs("</head>\n", r); ap_rputs("<body>\n", r); if (title) { ap_rprintf(r, "<h1 class=\"title\">%s</h1>\n", title); } if ((size = mkd_document(doc, &p)) != EOF) { ap_rwrite(p, size, r); } ap_rputc('\n', r); ap_rputs("</body>\n", r); ap_rputs("</html>\n", r); mkd_cleanup(doc); }
std::string markdown(std::string src) { auto flags = MKD_AUTOLINK; auto doc = mkd_string(src.c_str(), src.length(), flags); if(mkd_compile(doc, flags)) { char * buf; mkd_document(doc, &buf); std::string result(buf); mkd_cleanup(doc); return result; } else { throw "Conversion Failed"; } }
struct page * parse_page(FILE *f, char *file_path) { char c; int parsed_header = 0; struct ut_str buffer; /* markdown vars */ struct page *p = malloc(sizeof(struct page)); parse_filepath(file_path, p); p->inherits = NULL; p->attr_top = NULL; str_init(&buffer); while ((c = fgetc(f)) != EOF) { if (!parsed_header && '-' == c && flook_ahead(f, "--", 2)) { parse_header(f, p); parsed_header = 1; } else { str_append(&buffer, c); } } while (c != EOF); p->code = malloc(sizeof(char) * buffer.size + 1); memset(p->code, '\0', buffer.size + 1); if (MARKDOWN == p->page_type) { Document *doc = mkd_string(buffer.s, buffer.size + 1, 0); if (NULL != doc && mkd_compile(doc, 0) ) { char *html = NULL; int szdoc = mkd_document(doc, &html); strncpy(p->code, html, szdoc); mkd_cleanup(doc); } } else { strncpy(p->code, buffer.s, buffer.size); } str_free(&buffer); return p; }
mrb_value mrb_discount_to_html(mrb_state *mrb, mrb_value self) { MMIOT *md; int size; char *html; md = mkd_string(RSTRING_PTR(self), strlen(RSTRING_PTR(self)), 0); mkd_compile(md, MKD_TOC|MKD_AUTOLINK); if ((size = mkd_document(md, &html)) == EOF) { mrb_raise(mrb, E_RUNTIME_ERROR, "mkd_document() failed"); } mkd_cleanup(md); return mrb_str_new(mrb, html, strlen(html)); }
static VALUE rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self) { /* grab char pointer to markdown input text */ char *res; int szres; VALUE encoding; VALUE text = rb_funcall(self, rb_intern("text"), 0); VALUE buf = rb_str_buf_new(1024); Check_Type(text, T_STRING); int flags = rb_rdiscount__get_flags(self); /* * Force Discount to use ASCII character encoding for isalnum(), isalpha(), * and similar functions. * * Ruby tends to use UTF-8 encoding, which is ill-defined for these * functions since they expect 8-bit codepoints (and UTF-8 has codepoints * of at least 21 bits). */ char *old_locale = strdup(setlocale(LC_CTYPE, NULL)); setlocale(LC_CTYPE, "C"); // ASCII (and passthru characters > 127) MMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags); if ( mkd_compile(doc, flags) ) { szres = mkd_document(doc, &res); if ( szres != EOF ) { rb_str_cat(buf, res, szres); rb_str_cat(buf, "\n", 1); } } mkd_cleanup(doc); setlocale(LC_CTYPE, old_locale); free(old_locale); /* force the input encoding */ if ( rb_respond_to(text, rb_intern("encoding")) ) { encoding = rb_funcall(text, rb_intern("encoding"), 0); rb_funcall(buf, rb_intern("force_encoding"), 1, encoding); } return buf; }
NEOERR* mkd_esc_str(const char *in, char **out) { if (!in || !out) return STATUS_OK; int len = 0; *out = NULL; char *s = NULL; MMIOT *m = mkd_string((char*)in, strlen(in), 0); if (m) { if (mkd_compile(m, 0)) { len = mkd_document(m, &s); if (s && len > 0) { *(s+len) = '\0'; *out = strdup(s); } mkd_cleanup(m); } return STATUS_OK; } return nerr_raise(NERR_SYSTEM, "mkd_string() error %s", in); }
int main(int argc, char *argv[]) { char *h; char *source = 0, *dest = 0; MMIOT *mmiot; int i; FILE *input, *output; STRING(char*) css, headers, footers; CREATE(css); CREATE(headers); CREATE(footers); pgm = basename(argv[0]); while ( argc > 2 ) { if ( strcmp(argv[1], "-css") == 0 ) { EXPAND(css) = argv[2]; argc -= 2; argv += 2; } else if ( strcmp(argv[1], "-header") == 0 ) { EXPAND(headers) = argv[2]; argc -= 2; argv += 2; } else if ( strcmp(argv[1], "-footer") == 0 ) { EXPAND(footers) = argv[2]; argc -= 2; argv += 2; } } if ( argc > 1 ) { char *p, *dot; source = malloc(strlen(argv[1]) + 6); dest = malloc(strlen(argv[1]) + 6); if ( !(source && dest) ) fail("out of memory allocating name buffers"); strcpy(source, argv[1]); if (( p = strrchr(source, '/') )) p = source; else ++p; if ( (input = fopen(source, "r")) == 0 ) { strcat(source, ".text"); if ( (input = fopen(source, "r")) == 0 ) fail("can't open either %s or %s", argv[1], source); } strcpy(dest, source); if (( dot = strrchr(dest, '.') )) *dot = 0; strcat(dest, ".html"); if ( (output = fopen(dest, "w")) == 0 ) fail("can't write to %s", dest); } else { input = stdin; output = stdout; } if ( (mmiot = mkd_in(input, 0)) == 0 ) fail("can't read %s", source ? source : "stdin"); if ( !mkd_compile(mmiot, 0) ) fail("couldn't compile input"); h = mkd_doc_title(mmiot); /* print a header */ fprintf(output, "<!doctype html public \"-//W3C//DTD HTML 4.0 Transitional //EN\">\n" "<html>\n" "<head>\n" " <meta name=\"GENERATOR\" content=\"mkd2html %s\">\n", markdown_version); fprintf(output," <meta http-equiv=\"Content-Type\"\n" " content=\"text/html; charset-us-ascii\">"); for ( i=0; i < S(css); i++ ) fprintf(output, " <link rel=\"stylesheet\"\n" " type=\"text/css\"\n" " href=\"%s\" />\n", T(css)[i]); if ( h ) { fprintf(output," <title>"); mkd_generateline(h, strlen(h), output, 0); fprintf(output, "</title>\n"); } for ( i=0; i < S(headers); i++ ) fprintf(output, " %s\n", T(headers)[i]); fprintf(output, "</head>\n" "<body>\n"); /* print the compiled body */ mkd_generatehtml(mmiot, output); for ( i=0; i < S(footers); i++ ) fprintf(output, "%s\n", T(footers)[i]); fprintf(output, "</body>\n" "</html>\n"); mkd_cleanup(mmiot); exit(0); }
float main(int argc, char **argv) { int opt; int rc; int flags = 0; int debug = 0; int toc = 0; int with_html5 = 0; int use_mkd_line = 0; char *urlflags = 0; char *text = 0; char *ofile = 0; char *urlbase = 0; char *q; MMIOT *doc; if ( q = getenv("MARKDOWN_FLAGS") ) flags = strtol(q, 0, 0); pgm = basename(argv[0]); opterr = 1; while ( (opt=getopt(argc, argv, "5b:df:E:F:o:s:t:TV")) != EOF ) { switch (opt) { case '5': with_html5 = 1; break; case 'b': urlbase = optarg; break; case 'd': debug = 1; break; case 'V': printf("%s: discount %s%s\n", pgm, markdown_version, with_html5 ? " +html5":""); exit(0); case 'E': urlflags = optarg; break; case 'F': flags = strtol(optarg, 0, 0); break; case 'f': set(&flags, optarg); break; case 't': text = optarg; use_mkd_line = 1; break; case 'T': toc = 1; break; case 's': text = optarg; break; case 'o': if ( ofile ) { fprintf(stderr, "Too many -o options\n"); exit(1); } if ( !freopen(ofile = optarg, "w", stdout) ) { perror(ofile); exit(1); } break; default: fprintf(stderr, "usage: %s [-dTV] [-b url-base]" " [-F bitmap] [-f {+-}flags]" " [-o ofile] [-s text]" " [-t text] [file]\n", pgm); exit(1); } } argc -= optind; argv += optind; if ( with_html5 ) mkd_with_html5_tags(); if ( use_mkd_line ) rc = mkd_generateline( text, strlen(text), stdout, flags); else { if ( text ) { if ( (doc = mkd_string(text, strlen(text), flags)) == 0 ) { perror(text); exit(1); } } else { if ( argc && !freopen(argv[0], "r", stdin) ) { perror(argv[0]); exit(1); } if ( (doc = mkd_in(stdin,flags)) == 0 ) { perror(argc ? argv[0] : "stdin"); exit(1); } } if ( urlbase ) mkd_basename(doc, urlbase); if ( urlflags ) { mkd_e_data(doc, urlflags); mkd_e_flags(doc, e_flags); } if ( debug ) rc = mkd_dump(doc, stdout, 0, argc ? basename(argv[0]) : "stdin"); else { rc = 1; if ( mkd_compile(doc, flags) ) { rc = 0; if ( toc ) mkd_generatetoc(doc, stdout); mkd_generatehtml(doc, stdout); mkd_cleanup(doc); } } } adump(); exit( (rc == 0) ? 0 : errno ); }
/* The wiki handler */ static int wiki_handler(request_rec *r) { wiki_conf *conf; git_repository *repo; const git_oid *tree_oid; char *path; const git_oid *oid; char hash[41]; hash[40] = '\0'; int ret; int type; MMIOT *doc; if (strcmp(r->handler, "wiki")) { return DECLINED; } if (r->header_only) { return OK; } conf = (wiki_conf *) ap_get_module_config(r->per_dir_config, &wiki_module); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "filename=%s", r->filename); if (conf->basepath) { path = ltrim(conf->basepath, r->parsed_uri.path); } else { path = r->parsed_uri.path + 1; } ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "path=%s", path); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "r->content_type=%s", r->content_type); if (conf->repo == NULL) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "WikiRepository is not set."); return HTTP_INTERNAL_SERVER_ERROR; } ret = git_repository_open(&repo, conf->repo); if (ret) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Cannot open git repository.(%s)", conf->repo); return HTTP_INTERNAL_SERVER_ERROR; } tree_oid = lookup_master_tree(repo); if (tree_oid == NULL) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Not found master tree."); git_repository_free(repo); } type = lookup_object_oid(r, repo, tree_oid, path, &oid); if (type == WIKI_NOTFOUND) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Object is not found."); git_repository_free(repo); return HTTP_NOT_FOUND; } else if(type == WIKI_DIR) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Directory listing is not implement yet."); git_repository_free(repo); return HTTP_FORBIDDEN; } else if(type == WIKI_ERROR) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Error at lookup."); git_repository_free(repo); return HTTP_NOT_FOUND; } git_oid_fmt(hash, oid); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "object hash=%s", hash); const char *data; size_t size; git_odb *odb; ret = git_repository_odb(&odb, repo); git_odb_object *odb_object; ret = git_odb_read(&odb_object, odb, oid); data = git_odb_object_data(odb_object); size = git_odb_object_size(odb_object); git_odb_object_free(odb_object); // is this safe? if (type == WIKI_FOUND) { ap_rwrite(data, size, r); } else if(type == WIKI_MARKDOWN) { r->content_type = "text/html"; doc = mkd_string(data, size, 0); if (doc == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "mkd_string() returned NULL\n"); git_repository_free(repo); return HTTP_INTERNAL_SERVER_ERROR; } wiki_output(doc, r); mkd_cleanup(doc); } else { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Unknown Error.\n"); git_repository_free(repo); return HTTP_INTERNAL_SERVER_ERROR; } git_repository_free(repo); return OK; }
QString QGitHubReleaseAPIPrivate::body(int idx) const { #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) || defined(QJSON_FOUND)) if(dataAvailable()) { if(entries() > idx) { #ifdef HAVE_MKDIO_H const QString bMD(m_vdata[idx].toMap()["body"].toString()); #if QT_VERSION >= QT_VERSION_CHECK(4, 5, 0) const mkd_flag_t f = MKD_TOC|MKD_AUTOLINK|MKD_NOEXT|MKD_NOHEADER; #else const mkd_flag_t f = MKD_TOC|MKD_AUTOLINK|MKD_NOEXT|MKD_NOHEADER|MKD_NOIMAGE; #endif #endif switch(m_type) { #ifdef HAVE_MKDIO_H case QGitHubReleaseAPI::RAW: { MMIOT *doc = 0L; char *html = 0L; int dlen = EOF; if((doc = mkd_string(bMD.toStdString().c_str(), bMD.length(), f)) && mkd_compile(doc, f) != EOF && (dlen = mkd_document(doc, &html)) != EOF) { QString b(QString::fromUtf8((QByteArray(html, dlen).append('\0')).constData())); mkd_cleanup(doc); return embedImages(b); } else { emit error(tr("libmarkdown: parsing failed")); } } break; #else case QGitHubReleaseAPI::RAW: #endif case QGitHubReleaseAPI::HTML: { QString b(m_vdata[idx].toMap()["body_html"].toString()); return embedImages(b); } break; default: return m_vdata[idx].toMap()["body_text"].toString(). append(QString::fromUtf8("\n\n--\nRelease information provided by " \ "QGitHubReleaseAPI " PROJECTVERSION " \u00a9 2015 Heiko Sch\u00e4fer <*****@*****.**>")); } } else { emit error(QString(m_outOfBoundsError).arg(entries()).arg(idx)); } } else { emit error(m_noDataAvailableError); } #else emit error(tr("No libmarkdown installed, body not available")); #endif return QString::null; }
~DiscountMarkdownDocument() { mkd_cleanup(discountDocument); }
int main(int argc, char **argv) { int opt; int rc; mkd_flag_t flags = 0; int debug = 0; int toc = 0; int content = 1; int version = 0; int with_html5 = 0; int styles = 0; int use_mkd_line = 0; int github_flavoured = 0; char *extra_footnote_prefix = 0; char *urlflags = 0; char *text = 0; char *ofile = 0; char *urlbase = 0; char *q; MMIOT *doc; if ( q = getenv("MARKDOWN_FLAGS") ) flags = strtol(q, 0, 0); pgm = basename(argv[0]); opterr = 1; while ( (opt=getopt(argc, argv, "5b:C:df:E:F:Gno:s:St:TV")) != EOF ) { switch (opt) { case '5': with_html5 = 1; break; case 'b': urlbase = optarg; break; case 'd': debug = 1; break; case 'V': version++; break; case 'E': urlflags = optarg; break; case 'F': if ( strcmp(optarg, "?") == 0 ) { show_flags(0); exit(0); } else flags = strtol(optarg, 0, 0); break; case 'f': if ( strcmp(optarg, "?") == 0 ) { show_flags(1); exit(0); } else if ( !set_flag(&flags, optarg) ) complain("unknown option <%s>", optarg); break; case 'G': github_flavoured = 1; break; case 'n': content = 0; break; case 's': text = optarg; break; case 'S': styles = 1; break; case 't': text = optarg; use_mkd_line = 1; break; case 'T': toc = 1; break; case 'C': extra_footnote_prefix = optarg; break; case 'o': if ( ofile ) { complain("Too many -o options"); exit(1); } if ( !freopen(ofile = optarg, "w", stdout) ) { perror(ofile); exit(1); } break; default: fprintf(stderr, "usage: %s [-dTV] [-b url-base]" " [-F bitmap] [-f {+-}flags]" " [-o ofile] [-s text]" " [-t text] [file]\n", pgm); exit(1); } } if ( version ) { printf("%s: discount %s%s", pgm, markdown_version, with_html5 ? " +html5":""); if ( version > 1 ) mkd_flags_are(stdout, flags, 0); putchar('\n'); exit(0); } argc -= optind; argv += optind; if ( with_html5 ) mkd_with_html5_tags(); if ( use_mkd_line ) rc = mkd_generateline( text, strlen(text), stdout, flags); else { if ( text ) { doc = github_flavoured ? gfm_string(text, strlen(text), flags) : mkd_string(text, strlen(text), flags) ; if ( !doc ) { perror(text); exit(1); } } else { if ( argc && !freopen(argv[0], "r", stdin) ) { perror(argv[0]); exit(1); } doc = github_flavoured ? gfm_in(stdin,flags) : mkd_in(stdin,flags); if ( !doc ) { perror(argc ? argv[0] : "stdin"); exit(1); } } if ( urlbase ) mkd_basename(doc, urlbase); if ( urlflags ) { mkd_e_data(doc, urlflags); mkd_e_flags(doc, e_flags); } if ( extra_footnote_prefix ) mkd_ref_prefix(doc, extra_footnote_prefix); if ( debug ) rc = mkd_dump(doc, stdout, 0, argc ? basename(argv[0]) : "stdin"); else { rc = 1; if ( mkd_compile(doc, flags) ) { rc = 0; if ( styles ) mkd_generatecss(doc, stdout); if ( toc ) mkd_generatetoc(doc, stdout); if ( content ) mkd_generatehtml(doc, stdout); } } mkd_cleanup(doc); } mkd_deallocate_tags(); adump(); exit( (rc == 0) ? 0 : errno ); }
static int diary_handle_entry(request_rec *r, diary_conf *conf, const char *filename) { FILE *fp; CSPARSE *cs; NEOERR *cs_err; HDF *hdf; MMIOT *doc; char *title; char *author; char *date; int size; char *p; int flag = 0; int github_flavoured = conf->github_flavoured; calendar_info cal; char *theme_path; char *theme_file; theme_path = apr_pstrcat(r->pool, conf->path, "/themes/", conf->theme, NULL); theme_file = apr_pstrcat(r->pool, theme_path, "/index.cst", NULL); fp = fopen(filename, "r"); if(fp == NULL){ switch (errno) { case ENOENT: return HTTP_NOT_FOUND; case EACCES: return HTTP_FORBIDDEN; default: ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "diary_parse_entry error: errno=%d\n", errno); return HTTP_INTERNAL_SERVER_ERROR; } } doc = github_flavoured ? gfm_in(fp, 0) : mkd_in(fp, 0); fclose(fp); if (doc == NULL) { return HTTP_INTERNAL_SERVER_ERROR; } title = mkd_doc_title(doc); if(title == NULL){ title = "notitle"; } date = mkd_doc_date(doc); author = mkd_doc_author(doc); if(conf->autolink){ flag = MKD_AUTOLINK; } mkd_compile(doc, flag); if ((size = mkd_document(doc, &p)) == EOF) { return HTTP_INTERNAL_SERVER_ERROR; } hdf_init(&hdf); hdf_set_value(hdf, "hdf.loadpaths.1", conf->path); hdf_set_value(hdf, "hdf.loadpaths.2", theme_path); cs_err = hdf_read_file(hdf, INDEX_HDF); if(cs_err){ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "cannot read index.hdf."); // TODO: no need to free cs_err and cs_err_str? hdf_destroy(&hdf); return HTTP_INTERNAL_SERVER_ERROR; } hdf_set_value(hdf, "diary.title", conf->title); hdf_set_value(hdf, "diary.uri", conf->uri); hdf_set_value(hdf, "diary.theme", conf->theme); hdf_set_value(hdf, "entry.uri", r->uri); hdf_set_value(hdf, "entry.title", title); hdf_set_value(hdf, "entry.author", author); hdf_set_value(hdf, "entry.date", date); hdf_set_value(hdf, "entry.desc", p); //hdf_dump(hdf, NULL); if (conf->calendar) { diary_set_calendar_info(&cal, r->args); hdf_set_int_value(hdf, "cal.year", cal.year); hdf_set_value(hdf, "cal.month", cal.month); hdf_set_value(hdf, "cal.day", cal.day); hdf_set_value(hdf, "cal.today", cal.today); hdf_set_int_value(hdf, "cal.lastdayofmonth", cal.lastdayofmonth); hdf_set_int_value(hdf, "cal.dayofweek_1stdayofmonth", cal.dayofweek_1stdayofmonth); } cs_err = cs_init(&cs, hdf); if(cs_err){ return HTTP_INTERNAL_SERVER_ERROR; } cgi_register_strfuncs(cs); mkd_cleanup(doc); cs_parse_file(cs, theme_file); r->content_type = "text/html"; cs_render(cs, r, diary_cs_render_cb); hdf_destroy(&hdf); cs_destroy(&cs); return 0; }