Permalink
Browse files

now, preprocess and postprocess methods are able to use.

````
String Sundown\Render\Base::preprocess(string $text)
String Sundown\Render\Base::postprocess(string $text)
````

and SmartyPants disabled at this time. i'm working to move that feature to postprocess method.
  • Loading branch information...
chobie committed Jan 8, 2012
1 parent caea2a8 commit 665039a9efb6c4c03fcb6fce45e9555d5760bc47
Showing with 68 additions and 16 deletions.
  1. +1 −1 src/render_base.c
  2. +26 −1 src/render_html.c
  3. +41 −14 src/sundown_markdown.c
View
@@ -618,10 +618,10 @@ PHP_METHOD(sundown_render_base, __construct)
}
if (Z_TYPE_P(render_flags) == IS_ARRAY) {
+ ALLOC_INIT_ZVAL(c_flags);
ZVAL_ZVAL(c_flags, render_flags, 1, 1);
add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),c_flags TSRMLS_CC);
}
- RETURN_FALSE;
}
/* }}} */
View
@@ -859,19 +859,43 @@ PHP_METHOD(sundown_render_html, postprocess)
}
/* }}} */
-/* {{{ proto void __construct($options)
+/* {{{ proto void __construct($render_flags)
*/
PHP_METHOD(sundown_render_html, __construct)
{
php_sundown_render_html_t *object;
struct php_sundown_renderopt_ex opt;
+ zval *render_flags, *c_flags;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ "z", &render_flags) == FAILURE){
+ return;
+ }
+
+ if (Z_TYPE_P(render_flags) == IS_ARRAY) {
+ ALLOC_INIT_ZVAL(c_flags);
+ ZVAL_ZVAL(c_flags, render_flags, 1, 1);
+ add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),c_flags TSRMLS_CC);
+ }
object = (php_sundown_render_html_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
sdhtml_renderer(&object->cb, &opt.html, 0);
opt.self = getThis();
}
/* }}} */
+/* {{{ proto __destruct()
+*/
+PHP_METHOD(sundown_render_html, __destruct)
+{
+ zval *render_flags;
+ render_flags = zend_read_property(sundown_render_base_class_entry, getThis(),"render_flags",sizeof("render_flags")-1, 0 TSRMLS_CC);
+ if(Z_TYPE_P(render_flags) == IS_ARRAY) {
+ zval_ptr_dtor(&render_flags);
+ }
+}
+
+
static zend_function_entry php_sundown_render_html_methods[] = {
PHP_ME(sundown_render_html, __construct, arginfo_sundown_render_html___construct, ZEND_ACC_PUBLIC)
PHP_ME(sundown_render_html, enable_pants, arginfo_sundown_render_html_enable_pants, ZEND_ACC_PUBLIC)
@@ -903,6 +927,7 @@ static zend_function_entry php_sundown_render_html_methods[] = {
PHP_ME(sundown_render_html, doc_footer, arginfo_sundown_render_html_doc_footer, ZEND_ACC_PUBLIC)
PHP_ME(sundown_render_html, preprocess, arginfo_sundown_render_html_preprocess, ZEND_ACC_PUBLIC)
PHP_ME(sundown_render_html, postprocess, arginfo_sundown_render_html_postprocess, ZEND_ACC_PUBLIC)
+ PHP_ME(sundown_render_html, __destruct, NULL, ZEND_ACC_PUBLIC)
{NULL,NULL,NULL}
};
View
@@ -314,8 +314,9 @@ PHP_METHOD(sundown_markdown, __construct)
zend_class_entry **ce;
php_sundown_markdown_t *object = (php_sundown_markdown_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
- if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ if(zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
"z|a", &render, &extensions) == FAILURE){
+ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC," Sundown\Markdown::__construct() expects parameter 2 to be array");
return;
}
@@ -377,7 +378,7 @@ PHP_METHOD(sundown_markdown, render)
{
php_sundown_markdown_t *object = (php_sundown_markdown_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
php_sundown_buffer_t *buffer_object_t;
- zval *buffer_object;
+ zval *buffer_object, preprocess, postprocess, *params[1], *ret;
struct buf input_buf, *output_buf;
struct sd_callbacks sundown_render;
struct php_sundown_renderopt_ex opt;
@@ -392,11 +393,7 @@ PHP_METHOD(sundown_markdown, render)
"s", &buffer, &buffer_len) == FAILURE){
return;
}
-
- memset(&input_buf, 0x0, sizeof(struct buf));
- input_buf.data = buffer;
- input_buf.size = strlen(buffer);
-
+
output_buf = bufnew(128);
bufgrow(output_buf, strlen(buffer) * 1.2f);
@@ -437,21 +434,51 @@ PHP_METHOD(sundown_markdown, render)
}
}
+ // preprocess
+ MAKE_STD_ZVAL(ret);
+ MAKE_STD_ZVAL(params[0]);
+ ZVAL_STRINGL(params[0], buffer,strlen(buffer), 1);
+ ZVAL_STRING(&preprocess,"preprocess",1);
+ if (call_user_function(NULL, &object->render, &preprocess, ret, 1, params TSRMLS_CC) == FAILURE) {
+ }
+
+ memset(&input_buf, 0x0, sizeof(struct buf));
+ if (ret != NULL && Z_TYPE_P(ret) == IS_STRING) {
+ input_buf.data = Z_STRVAL_P(ret);
+ input_buf.size = Z_STRLEN_P(ret);
+ } else {
+ input_buf.data = buffer;
+ input_buf.size = strlen(buffer);
+ }
+ zval_ptr_dtor(&params[0]);
+
+ // proceess markdown
markdown = sd_markdown_new(enabled_extensions, 16, &sundown_render, &opt);
sd_markdown_render(output_buf, input_buf.data, input_buf.size, markdown);
sd_markdown_free(markdown);
-
- if (Z_BVAL_P(zend_read_property(ce, object->render,"enable_pants",sizeof("enable_pants")-1, 1 TSRMLS_CC))) {
- struct buf *smart_buf = bufnew(128);
- sdhtml_smartypants(smart_buf, output_buf->data,output_buf->size);
- RETVAL_STRINGL(smart_buf->data, smart_buf->size,1);
- bufrelease(smart_buf);
+
+ zval_ptr_dtor(&ret);
+ // postprocess
+ MAKE_STD_ZVAL(ret);
+ MAKE_STD_ZVAL(params[0]);
+ ZVAL_STRINGL(params[0], output_buf->data,output_buf->size, 1);
+ ZVAL_STRING(&postprocess,"postprocess",1);
+ if (call_user_function(NULL, &object->render, &postprocess, ret, 1, params TSRMLS_CC) == FAILURE) {
+ }
+
+ if (ret != NULL && Z_TYPE_P(ret) == IS_STRING) {
+ RETVAL_STRINGL(Z_STRVAL_P(ret), Z_STRLEN_P(ret),1);
} else {
- RETVAL_STRINGL(output_buf->data, output_buf->size,1);
+ RETVAL_STRINGL(output_buf->data,output_buf->size,1);
}
+ zval_ptr_dtor(&ret);
+ zval_ptr_dtor(&params[0]);
+ zval_dtor(&postprocess);
+ zval_dtor(&preprocess);
}
+
static zend_function_entry php_sundown_markdown_methods[] = {
PHP_ME(sundown_markdown, __construct, arginfo_sundown_markdown__construct, ZEND_ACC_PUBLIC)
PHP_ME(sundown_markdown, __destruct, NULL, ZEND_ACC_PUBLIC)

0 comments on commit 665039a

Please sign in to comment.