Added Smartypants render flag.

This commit is contained in:
Frank
2011-05-10 19:58:41 +02:00
parent 27d43c462f
commit ab5d00cb9f
4 changed files with 22 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ News/Changelog
0.2.0 (2011-05-??)
------------------
* Added Smartypants render flag.
* Added a ``toc`` function that outputs a table of contents.
* Renamed ``markdown`` function to ``html``.
* Updated Upskirt files;

View File

@@ -82,3 +82,4 @@ Render flags:
HTML_SKIP_IMAGES
HTML_EXPAND_TABS
HTML_USE_XHTML
HTML_SMARTYPANTS

View File

@@ -5,6 +5,10 @@
#include "upskirt/html.h"
/* An extra flag to enabled Smartypants */
unsigned int HTML_SMARTYPANTS = (1 << 12);
/* The module doc strings */
PyDoc_STRVAR(pantyshot_module__doc__, "Pantyshot is a Python binding for Upskirt!");
PyDoc_STRVAR(pantyshot_markdown__doc__, "Render Markdown text into HTML.");
@@ -36,6 +40,15 @@ pantyshot_render(const char *text, unsigned int extensions,
ups_markdown(ob, ib, &renderer, extensions);
upshtml_free_renderer(&renderer);
/* Smartypants actions */
if (render_flags & HTML_SMARTYPANTS)
{
struct buf *sb = bufnew(1);
upshtml_smartypants(sb, ob);
ob = bufdup(sb, sb->size); /* Duplicate Smartypants buffer to output buffer */
bufrelease(sb); /* Cleanup Smartypants buffer */
}
/* Append a null terminator to the output buffer and make a Python string */
bufnullterm(ob);
PyObject *html = Py_BuildValue("s", ob->data);
@@ -116,4 +129,5 @@ initpantyshot(void)
PyModule_AddIntConstant(module, "HTML_HARD_WRAP", HTML_HARD_WRAP);
PyModule_AddIntConstant(module, "HTML_GITHUB_BLOCKCODE", HTML_GITHUB_BLOCKCODE);
PyModule_AddIntConstant(module, "HTML_USE_XHTML", HTML_USE_XHTML);
PyModule_AddIntConstant(module, "HTML_SMARTYPANTS", HTML_SMARTYPANTS);
}

View File

@@ -8,7 +8,10 @@ text = '''
# Markdown extensions
Here are some demonstrations of Markdown extensions.
Here are some demonstrations of Markdown "extensions".
Test Smartypants: <3/4ths> -- Test test
## MKDEXT_NO_INTRA_EMPHASIS
@@ -61,7 +64,7 @@ Nullam tincidunt dui ~vitae~ nulla ~~tristique~~ ultricies.
result = p.html(
text,
p.EXT_TABLES | p.EXT_STRIKETHROUGH | p.EXT_LAX_HTML_BLOCKS,
p.HTML_SKIP_HTML | p.HTML_EXPAND_TABS | p.HTML_SKIP_LINKS | p.HTML_TOC
p.HTML_SKIP_HTML | p.HTML_EXPAND_TABS | p.HTML_SKIP_LINKS | p.HTML_TOC | p.HTML_SMARTYPANTS
)
result = p.toc(text)
#result = p.toc(text)
print result