Exemplo n.º 1
0
PyMODINIT_FUNC initsnudown(void)
{
	PyObject *module;

	module = Py_InitModule3("snudown", snudown_methods, snudown_module__doc__);
	if (module == NULL)
		return;

	init_default_renderer(module);
	init_wiki_renderer(module);

	/* Version */
	PyModule_AddStringConstant(module, "__version__", SNUDOWN_VERSION);
}
Exemplo n.º 2
0
int main(int argc, const char * argv[])
{
	struct buf					ib, *ob;
	int							enable_toc = 0;
	struct snudown_renderer		renderer;
	int							nofollow = 0;
	char*						target = NULL;
	char*						domain = NULL;
	char*						toc_id_prefix = NULL;
	unsigned int				flags;
	FILE *						fp;
	
	init_default_renderer();

	memset(&ib, 0x0, sizeof(struct buf));
	
	nofollow = false;
	target = "_blank";
	domain = "lightnet.is";
	toc_id_prefix = "";
	enable_toc = false;
	
	renderer = sundown[RENDERER_USERTEXT];
	
	struct snudown_renderopt *options = &(renderer.state->options);
	options->nofollow = nofollow;
	options->target = target;
	options->domain = domain;
	
	/* Set the input buffer */
	ib.data = (unsigned char*)	"First line:\nSecond Line:\nThird Line\n\n"
								"[link away](http://google.com)\n[link here](http://lightnet.is/space/lightnet)\n\n"
								"![5-Cell aka Pentachoron](http://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Schlegel_wireframe_5-cell.png/250px-Schlegel_wireframe_5-cell.png)";
	ib.size = strlen((const char*) ib.data);
	
	/* Output buffer */
	ob = bufnew(128);
	
	flags = options->html.flags;
	
	if (enable_toc) {
		renderer.toc_state->options.html.toc_id_prefix = toc_id_prefix;
		sd_markdown_render(ob, ib.data, ib.size, renderer.toc_renderer);
		renderer.toc_state->options.html.toc_id_prefix = NULL;
		
		options->html.flags |= HTML_TOC;
	}
	
	options->html.toc_id_prefix = toc_id_prefix;
	
	/* do the magic */
	sd_markdown_render(ob, ib.data, ib.size, renderer.main_renderer);
	
	options->html.toc_id_prefix = NULL;
	options->html.flags = flags;
	
	fp = fopen( "markdown.html", "w+" );

	fprintf( fp, "<HTML>\n<BODY>\n");
	fprintf( fp, "%s", (const char*) ob->data);
	fprintf( fp, "\n<HTML>\n<BODY>\n");
	
	fclose( fp );
	
	printf( "%s", (const char*) ob->data );
	
	/* Cleanup */
	bufrelease(ob);

	return 0;
}