Permalink
Browse files

added Upskirt::to_toc().

  • Loading branch information...
1 parent d126293 commit 174598e7d840fe0aad75c02b2073d30b6a57d449 @chobie committed Jun 7, 2011
Showing with 50 additions and 21 deletions.
  1. +2 −1 README.md
  2. +48 −20 src/phpskirt.c
View
@@ -32,5 +32,6 @@ Install
Example
-------
- $markdown = new Upskirt(string $text[, StdClass $extensions]);
+ $markdown = new Upskirt(string $text[, array $extensions]);
echo $markdown->to_html();
+ echo $markdown->to_toc();
View
@@ -26,6 +26,12 @@
PHPAPI zend_class_entry *phpskirt_class_entry;
+typedef enum
+{
+ PHPSKIRT_RENDER_HTML,
+ PHPSKIRT_RENDER_TOC
+} PHPSkirtRendererType;
+
void php_phpskirt_init(TSRMLS_D);
ZEND_BEGIN_ARG_INFO_EX(arginfo_phpskirt__construct, 0, 0, 1)
@@ -42,7 +48,7 @@ static void php_phpskirt__get_flags(zval *php_obj, unsigned int *enabled_extensi
unsigned int render_flags = HTML_EXPAND_TABS;
unsigned int extensions = 0;
- /* filter_html */
+ /* filter_html */
if (PHPSKIRT_HAS_EXTENSION("filter_html"))
render_flags |= HTML_SKIP_HTML;
@@ -102,23 +108,7 @@ static void php_phpskirt__get_flags(zval *php_obj, unsigned int *enabled_extensi
*render_flags_p = render_flags;
}
-PHP_METHOD(phpskirt, __construct)
-{
- char *buffer;
- int buffer_len = 0;
- zval *extensions;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s|z",&buffer,&buffer_len,&extensions) == FAILURE) {
- return;
- }
- add_property_stringl_ex(getThis(),"data",sizeof("data"),buffer,buffer_len,1 TSRMLS_CC);
-
- if(extensions){
- add_property_zval_ex(getThis(),"extensions",sizeof("extensions"),extensions TSRMLS_CC);
- }
-}
-
-PHP_METHOD(phpskirt, to_html)
+static void phpskirt__render(PHPSkirtRendererType render_type, INTERNAL_FUNCTION_PARAMETERS)
{
struct buf input_buf, *output_buf;
struct mkd_renderer phpskirt_render;
@@ -133,20 +123,58 @@ PHP_METHOD(phpskirt, to_html)
bufgrow(output_buf, strlen(buffer) * 1.2f);
php_phpskirt__get_flags(zend_read_property(phpskirt_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC), &enabled_extensions, &render_flags);
- upshtml_renderer(&phpskirt_render, render_flags);
+
+ switch (render_type) {
+ case PHPSKIRT_RENDER_HTML:
+ upshtml_renderer(&phpskirt_render, render_flags);
+ break;
+
+ case PHPSKIRT_RENDER_TOC:
+ upshtml_toc_renderer(&phpskirt_render);
+ break;
+
+ default:
+ RETURN_FALSE;
+ }
ups_markdown(output_buf, &input_buf, &phpskirt_render, enabled_extensions);
-
RETVAL_STRINGL(output_buf->data, output_buf->size,1);
bufrelease(output_buf);
upshtml_free_renderer(&phpskirt_render);
}
+PHP_METHOD(phpskirt, __construct)
+{
+ char *buffer;
+ int buffer_len = 0;
+ zval *extensions;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s|z",&buffer,&buffer_len,&extensions) == FAILURE) {
+ return;
+ }
+ add_property_stringl_ex(getThis(),"data",sizeof("data"),buffer,buffer_len,1 TSRMLS_CC);
+
+ if(extensions){
+ add_property_zval_ex(getThis(),"extensions",sizeof("extensions"),extensions TSRMLS_CC);
+ }
+}
+
+PHP_METHOD(phpskirt, to_html)
+{
+ phpskirt__render(PHPSKIRT_RENDER_HTML,INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+
+PHP_METHOD(phpskirt, to_toc)
+{
+ phpskirt__render(PHPSKIRT_RENDER_TOC,INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+
PHPAPI function_entry php_phpskirt_methods[] = {
PHP_ME(phpskirt, __construct, arginfo_phpskirt__construct, ZEND_ACC_PUBLIC)
PHP_ME(phpskirt, to_html, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(phpskirt, to_toc, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};

0 comments on commit 174598e

Please sign in to comment.