Permalink
Browse files

change exntension object to hash.

now, we can use array instead of object to choose upskirt extension.

$upskirt = new Upskirt($string, array("extension_name"=>true));

still i don't check the extension array value. for now, key is important.
  • Loading branch information...
1 parent 0c98340 commit eb977d47e281809182837be1bad960649f0dd16f @chobie committed Jun 7, 2011
Showing with 42 additions and 11 deletions.
  1. +42 −11 phpskirt.c
View
53 phpskirt.c
@@ -10,9 +10,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phpskirt__construct, 0, 0, 1)
ZEND_END_ARG_INFO()
-#define PHPSKIRT_HAS_EXTENSION(name) Z_BVAL_P(zend_read_property(phpskirt_class_entry,php_obj,name,sizeof(name), 1 TSRMLS_CC))
+#define PHPSKIRT_HAS_EXTENSION(name) (zend_hash_exists( Z_ARRVAL_P(php_obj), name,strlen(name)) == SUCCESS)
- static void php_phpskirt__get_flags(zval *php_obj, unsigned int *enabled_extensions_p, unsigned int *render_flags_p)
+static void php_phpskirt__get_flags(zval *php_obj, unsigned int *enabled_extensions_p, unsigned int *render_flags_p)
{
TSRMLS_FETCH();
unsigned int render_flags = HTML_EXPAND_TABS;
@@ -37,17 +37,48 @@ ZEND_END_ARG_INFO()
render_flags |= HTML_SKIP_LINKS;
/* filter_style */
- if (PHPSKIRT_HAS_EXTENSION("filter_style"))
+ if (PHPSKIRT_HAS_EXTENSION("filter_styles"))
render_flags |= HTML_SKIP_STYLE;
- /* autolink */
- if (PHPSKIRT_HAS_EXTENSION("auto_link"))
- render_flags |= MKDEXT_AUTOLINK;
-
/* safelink */
if (PHPSKIRT_HAS_EXTENSION("safelink"))
render_flags |= HTML_SAFELINK;
+ if (PHPSKIRT_HAS_EXTENSION("generate_toc"))
+ render_flags |= HTML_TOC;
+
+ if (PHPSKIRT_HAS_EXTENSION("hard_wrap"))
+ render_flags |= HTML_HARD_WRAP;
+
+ if (PHPSKIRT_HAS_EXTENSION("gh_blockcode"))
+ render_flags |= HTML_GITHUB_BLOCKCODE;
+
+ if (PHPSKIRT_HAS_EXTENSION("xhtml"))
+ render_flags |= HTML_USE_XHTML;
+
+ /**
+ * Markdown extensions -- all disabled by default
+ */
+ if (PHPSKIRT_HAS_EXTENSION("auto_link"))
+ extensions |= MKDEXT_AUTOLINK;
+
+ if (PHPSKIRT_HAS_EXTENSION("no_intraemphasis"))
+ extensions |= MKDEXT_NO_INTRA_EMPHASIS;
+
+ if (PHPSKIRT_HAS_EXTENSION("tables"))
+ extensions |= MKDEXT_TABLES;
+
+ if (PHPSKIRT_HAS_EXTENSION("fenced_code"))
+ extensions |= MKDEXT_FENCED_CODE;
+
+ if (PHPSKIRT_HAS_EXTENSION("strikethrough"))
+ extensions |= MKDEXT_STRIKETHROUGH;
+
+ if (PHPSKIRT_HAS_EXTENSION("lax_htmlblock"))
+ extensions |= MKDEXT_LAX_HTML_BLOCKS;
+
+ if (PHPSKIRT_HAS_EXTENSION("space_header"))
+ extensions |= MKDEXT_SPACE_HEADERS;
*enabled_extensions_p = extensions;
*render_flags_p = render_flags;
@@ -64,7 +95,7 @@ PHP_METHOD(phpskirt, __construct)
}
add_property_stringl_ex(getThis(),"data",sizeof("data"),buffer,buffer_len,1 TSRMLS_CC);
- if(!extensions){
+ if(extensions){
add_property_zval_ex(getThis(),"extensions",sizeof("extensions"),extensions TSRMLS_CC);
}
}
@@ -73,16 +104,15 @@ PHP_METHOD(phpskirt, to_html)
{
struct buf input_buf, *output_buf;
struct mkd_renderer phpskirt_render;
- unsigned int enabled_extensions, render_flags;
+ unsigned int enabled_extensions = 0, render_flags = 0;
memset(&input_buf, 0x0, sizeof(struct buf));
char *buffer = Z_STRVAL_P(zend_read_property(phpskirt_class_entry,getThis(),"data",sizeof("data")-1,1 TSRMLS_CC));
input_buf.data = buffer;
input_buf.size = strlen(buffer);
output_buf = bufnew(128);
-
- php_phpskirt__get_flags(getThis(), &enabled_extensions, &render_flags);
+ 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);
ups_markdown(output_buf, &input_buf, &phpskirt_render, enabled_extensions);
@@ -133,6 +163,7 @@ void php_phpskirt_init(TSRMLS_D)
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "Upskirt", php_phpskirt_methods);
phpskirt_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ zend_declare_property_null(phpskirt_class_entry, "extensions", sizeof("extensions"), ZEND_ACC_PUBLIC TSRMLS_CC);
}

0 comments on commit eb977d4

Please sign in to comment.