Created
November 16, 2012 18:17
-
-
Save bdolman/4089583 to your computer and use it in GitHub Desktop.
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
NSString *plaintext = @"**text to render**"; | |
struct sd_markdown *markdown; | |
struct html_renderopt html_options; | |
unsigned int render_flags = HTML_HARD_WRAP; | |
unsigned int extensions = MKDEXT_NO_INTRA_EMPHASIS | | |
MKDEXT_TABLES | | |
MKDEXT_FENCED_CODE | | |
MKDEXT_AUTOLINK | | |
MKDEXT_STRIKETHROUGH | | |
MKDEXT_SPACE_HEADERS | | |
MKDEXT_SUPERSCRIPT | | |
MKDEXT_LAX_SPACING | | |
MKDEXT_FOOTNOTES; | |
struct sd_callbacks callbacks; | |
sdhtml_renderer(&callbacks, &html_options, render_flags); | |
markdown = sd_markdown_new(extensions, 16, &callbacks, &html_options); | |
const char *text = [plaintext UTF8String]; | |
struct buf *ib = bufnew(64); | |
bufputs(ib, text); | |
struct buf *ob = bufnew(64); | |
sd_markdown_render(ob, ib->data, ib->size, markdown); | |
bufrelease(ib); | |
struct buf *sb = bufnew(64); | |
sdhtml_smartypants(sb, ob->data, ob->size); | |
bufrelease(ob); | |
ob = sb; | |
NSString *result = [NSString stringWithUTF8String:bufcstr(ob)]; | |
bufrelease(ob); | |
sd_markdown_free(markdown); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment