Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

divided render_flags and extensions.

Sundown\Markdown mixed render_flags and extensions. it's not straight forward method signature.
now it divided as following method signatures.

````
Sundown\Render\Base::__construct(array $render_flags)
Sundown\Markdown::__construct($render, array $extensions)
````

Available extensions
--------------------

$extensions = array(
	"no_intra_emphasis"=>true,
	"tables"=>true,
	"fenced_code_blocks"=>true,
	"autolink"=>true,
	"strikethrough"=>true,
	"lax_html_blocks"=>true,
	"space_after_headers"=>true,
	"superscript"=>true,
);

Available render flags
----------------------

$render_flags = array(
	"escape_html" => true,
	"filter_html" => true,
	"no_images" => true,
	"no_links" => true,
	"no_styles" => true,
	"safe_links_only" => true,
	"with_toc_data" => true,
	"hard_wrap" => true,
	"xhtml" => true,
);
  • Loading branch information...
commit 498992e7ed5903beb0c3d6c51574b691602a4137 1 parent 3132564
@chobie authored
Showing with 75 additions and 12 deletions.
  1. +21 −2 src/php_sundown.c
  2. +37 −1 src/render_base.c
  3. +17 −9 src/sundown_markdown.c
View
23 src/php_sundown.c
@@ -127,11 +127,10 @@ int call_user_function_v(HashTable *function_table, zval **object_pp, zval *func
#define SUNDOWN_HAS_EXTENSION(name) (table != NULL && zend_hash_exists(table, name,strlen(name)+1) == 1)
-void php_sundown__get_flags(HashTable *table, unsigned int *enabled_extensions_p, unsigned int *render_flags_p)
+void php_sundown__get_render_flags(HashTable *table, unsigned int *render_flags_p)
{
TSRMLS_FETCH();
unsigned int render_flags = HTML_EXPAND_TABS;
- unsigned int extensions = 0;
/* filter_html */
if (SUNDOWN_HAS_EXTENSION("filter_html")) {
@@ -170,6 +169,14 @@ void php_sundown__get_flags(HashTable *table, unsigned int *enabled_extensions_p
render_flags |= HTML_USE_XHTML;
}
+ *render_flags_p = render_flags;
+}
+
+void php_sundown__get_extensions(HashTable *table, unsigned int *enabled_extensions_p)
+{
+ TSRMLS_FETCH();
+ unsigned int extensions = 0;
+
/**
* Markdown extensions -- all disabled by default
*/
@@ -206,6 +213,18 @@ void php_sundown__get_flags(HashTable *table, unsigned int *enabled_extensions_p
}
*enabled_extensions_p = extensions;
+}
+
+void php_sundown__get_flags(HashTable *table, unsigned int *enabled_extensions_p, unsigned int *render_flags_p)
+{
+ TSRMLS_FETCH();
+ unsigned int extensions = 0;
+ unsigned int render_flags = HTML_EXPAND_TABS;
+
+ php_sundown__get_extensions(table, &extensions);
+ php_sundown__get_render_flags(table, &render_flags);
+
+ *enabled_extensions_p = extensions;
*render_flags_p = render_flags;
}
View
38 src/render_base.c
@@ -54,6 +54,10 @@ zend_object_value php_sundown_render_base_new(zend_class_entry *ce TSRMLS_DC)
return retval;
}
+ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render___construct,0,0,1)
+ ZEND_ARG_INFO(0, render_flags)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_base_enable_pants, 0, 0, 0)
ZEND_END_ARG_INFO()
@@ -599,7 +603,38 @@ PHP_METHOD(sundown_render_base, postprocess)
}
/* }}} */
+/* {{{ proto __construct([array render_flags])
+*/
+PHP_METHOD(sundown_render_base, __construct)
+{
+ 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) {
+ ZVAL_ZVAL(c_flags, render_flags, 1, 1);
+ add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),c_flags TSRMLS_CC);
+ }
+ RETURN_FALSE;
+}
+/* }}} */
+
+/* {{{ proto __destruct()
+*/
+PHP_METHOD(sundown_render_base, __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_base_methods[] = {
+ PHP_ME(sundown_render_base, __construct, arginfo_sundown_render___construct, ZEND_ACC_PUBLIC)
PHP_ME(sundown_render_base, enable_pants, arginfo_sundown_render_base_enable_pants, ZEND_ACC_PUBLIC)
PHP_ME(sundown_render_base, block_code, arginfo_sundown_render_base_block_code, ZEND_ACC_PUBLIC)
PHP_ME(sundown_render_base, block_quote, arginfo_sundown_render_base_block_quote, ZEND_ACC_PUBLIC)
@@ -629,6 +664,7 @@ static zend_function_entry php_sundown_render_base_methods[] = {
PHP_ME(sundown_render_base, doc_footer, arginfo_sundown_render_base_doc_footer, ZEND_ACC_PUBLIC)
PHP_ME(sundown_render_base, preprocess, arginfo_sundown_render_base_preprocess, ZEND_ACC_PUBLIC)
PHP_ME(sundown_render_base, postprocess, arginfo_sundown_render_base_postprocess, ZEND_ACC_PUBLIC)
+ PHP_ME(sundown_render_base, __destruct, NULL, ZEND_ACC_PUBLIC)
{NULL,NULL,NULL}
};
@@ -638,5 +674,5 @@ void php_sundown_render_base_init(TSRMLS_D)
INIT_NS_CLASS_ENTRY(ce, ZEND_NS_NAME("Sundown","Render"),"Base", php_sundown_render_base_methods);
sundown_render_base_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
sundown_render_base_class_entry->create_object = php_sundown_render_base_new;
-
+ zend_declare_property_null(sundown_render_base_class_entry, "render_flags", sizeof("render_flags")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
}
View
26 src/sundown_markdown.c
@@ -305,17 +305,17 @@ zend_object_value php_sundown_markdown_new(zend_class_entry *ce TSRMLS_DC)
}
-/* {{{ proto string __construct($render [, $options])
+/* {{{ proto string __construct($render [, $extensions])
*/
PHP_METHOD(sundown_markdown, __construct)
{
zval *render;
- zval *options = NULL;
+ zval *extensions = NULL;
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,
- "z|a", &render, &options) == FAILURE){
+ "z|a", &render, &extensions) == FAILURE){
return;
}
@@ -346,13 +346,13 @@ PHP_METHOD(sundown_markdown, __construct)
}
object->render = render;
- if (options == NULL) {
- MAKE_STD_ZVAL(options);
- array_init(options);
+ if (extensions == NULL) {
+ MAKE_STD_ZVAL(extensions);
+ array_init(extensions);
} else {
- Z_ADDREF_P(options);
+ Z_ADDREF_P(extensions);
}
- add_property_zval_ex(getThis(),"extensions",sizeof("extensions"),options TSRMLS_CC);
+ add_property_zval_ex(getThis(),"extensions",sizeof("extensions"),extensions TSRMLS_CC);
}
/* }}} */
@@ -400,11 +400,19 @@ PHP_METHOD(sundown_markdown, render)
output_buf = bufnew(128);
bufgrow(output_buf, strlen(buffer) * 1.2f);
+
+
+ if(Z_TYPE_P(zend_read_property(Z_OBJCE_P(object->render), object->render,"render_flags",sizeof("render_flags")-1, 0 TSRMLS_CC)) != IS_NULL) {
+ table = Z_ARRVAL_P(zend_read_property(Z_OBJCE_P(object->render), object->render,"render_flags",sizeof("render_flags")-1, 0 TSRMLS_CC));
+ php_sundown__get_render_flags(table, &render_flags);
+ table = NULL;
+ }
if(Z_TYPE_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC)) != IS_NULL) {
table = Z_ARRVAL_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC));
+ php_sundown__get_extensions(table, &enabled_extensions);
+ table = NULL;
}
- php_sundown__get_flags(table, &enabled_extensions, &render_flags);
// setup render
switch (SUNDOWN_RENDER_HTML) {
Please sign in to comment.
Something went wrong with that request. Please try again.