/* * call-seq: * bluecloth.header -> hash * * Return the hash of * {Pandoc-style headers}[http://johnmacfarlane.net/pandoc/README.html#title-blocks] * from the parsed document. If there were no headers, or the BlueCloth object was not * constructed with the :pandoc_headers option enabled, an empty Hash is returned. * * markdown = "%title My Essay\n%author Me\n%date Today\n\nSome stuff..." * bc = BlueCloth.new( markdown, :pandoc_headers => true ) * # => * bc.header * # => */ static VALUE bluecloth_header( VALUE self ) { MMIOT *document = bluecloth_get_ptr( self ); char *field; VALUE fieldstring, headers = rb_hash_new(); bluecloth_debug( "Fetching pandoc headers for document %p", document ); if ( (field = mkd_doc_title(document)) ) { fieldstring = rb_str_new2( field ); OBJ_INFECT( fieldstring, self ); rb_hash_aset( headers, ID2SYM(rb_intern("title")), fieldstring ); } if ( (field = mkd_doc_author(document)) ) { fieldstring = rb_str_new2( field ); OBJ_INFECT( fieldstring, self ); rb_hash_aset( headers, ID2SYM(rb_intern("author")), fieldstring ); } if ( (field = mkd_doc_date(document)) ) { fieldstring = rb_str_new2( field ); OBJ_INFECT( fieldstring, self ); rb_hash_aset( headers, ID2SYM(rb_intern("date")), fieldstring ); } return headers; }
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; }