Skip to content
Browse files

added XHTML render class template

  • Loading branch information...
1 parent 5d448ba commit 0db201003c9d393ffab16fec217a20583944569f @chobie committed Jan 9, 2012
Showing with 102 additions and 0 deletions.
  1. +1 −0 src/config.m4
  2. +2 −0 src/php_sundown.c
  3. +6 −0 src/php_sundown.h
  4. +93 −0 src/render_xhtml.c
View
1 src/config.m4
@@ -8,6 +8,7 @@ if test $PHP_SUNDOWN != "no"; then
sundown_buffer.c \
render_base.c \
render_html.c \
+ render_xhtml.c \
buffer.c \
markdown.c \
html.c \
View
2 src/php_sundown.c
@@ -25,6 +25,7 @@
#include "php_sundown.h"
extern void php_sundown_render_html_init(TSRMLS_D);
+extern void php_sundown_render_xhtml_init(TSRMLS_D);
extern void php_sundown_markdown_init(TSRMLS_D);
extern void php_sundown_markdown_init(TSRMLS_D);
extern void php_sundown_buffer_init(TSRMLS_D);
@@ -359,6 +360,7 @@ PHP_MINIT_FUNCTION(sundown) {
php_sundown_buffer_init(TSRMLS_C);
php_sundown_render_base_init(TSRMLS_C);
php_sundown_render_html_init(TSRMLS_C);
+ php_sundown_render_xhtml_init(TSRMLS_C);
php_sundown_markdown_init(TSRMLS_C);
REGISTER_NS_STRING_CONSTANT(ZEND_NS_NAME("Sundown","Render"), "HTML", "Sundown\\Render\\HTML", CONST_CS | CONST_PERSISTENT);
View
6 src/php_sundown.h
@@ -65,6 +65,12 @@ typedef struct{
typedef struct{
zend_object zo;
struct html_renderopt html;
+ struct sd_callbacks cb;
+} php_sundown_render_xhtml_t;
+
+typedef struct{
+ zend_object zo;
+ struct html_renderopt html;
} php_sundown_render_base_t;
#define SPAN_CALLBACK_EX(buffer,method_name, ...) {\
View
93 src/render_xhtml.c
@@ -0,0 +1,93 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 Shuhei Tanuma
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "php_sundown.h"
+extern zend_class_entry *sundown_render_html_class_entry;
+zend_class_entry *sundown_render_xhtml_class_entry;
+
+static void php_sundown_render_xhtml_free_storage(php_sundown_render_xhtml_t *obj TSRMLS_DC)
+{
+ zend_object_std_dtor(&obj->zo TSRMLS_CC);
+ efree(obj);
+}
+
+zend_object_value php_sundown_render_xhtml_new(zend_class_entry *ce TSRMLS_DC)
+{
+ zend_object_value retval;
+ php_sundown_render_xhtml_t *obj;
+ zval *tmp;
+
+ obj = ecalloc(1, sizeof(*obj));
+ zend_object_std_init( &obj->zo, ce TSRMLS_CC);
+#if ZEND_MODULE_API_NO >= 20100525
+ object_properties_init(&(obj->zo), ce);
+#else
+ zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+#endif
+
+ retval.handle = zend_objects_store_put(obj,
+ (zend_objects_store_dtor_t)zend_objects_destroy_object,
+ (zend_objects_free_object_storage_t)php_sundown_render_xhtml_free_storage,
+ NULL TSRMLS_CC);
+ retval.handlers = zend_get_std_object_handlers();
+ return retval;
+}
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render___construct,0,0,1)
+ ZEND_ARG_INFO(0, render_flags)
+ZEND_END_ARG_INFO()
+
+/* {{{ proto __construct([array render_flags])
+*/
+PHP_METHOD(sundown_render_xhtml, __construct)
+{
+ zval *render_flags, *c_flags;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ "|z", &render_flags) == FAILURE){
+ return;
+ }
+
+ if (render_flags != NULL && 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);
+ }
+}
+/* }}} */
+
+
+static zend_function_entry php_sundown_render_xhtml_methods[] = {
+ PHP_ME(sundown_render_xhtml, __construct, arginfo_sundown_render___construct, ZEND_ACC_PUBLIC)
+ {NULL,NULL,NULL}
+};
+
+void php_sundown_render_xhtml_init(TSRMLS_D)
+{
+ zend_class_entry ce;
+ INIT_NS_CLASS_ENTRY(ce, ZEND_NS_NAME("Sundown","Render"),"XHTML", php_sundown_render_xhtml_methods);
+ sundown_render_xhtml_class_entry = zend_register_internal_class_ex(&ce, sundown_render_html_class_entry, NULL TSRMLS_CC);
+ sundown_render_xhtml_class_entry->create_object = php_sundown_render_xhtml_new;
+ zend_declare_property_null(sundown_render_xhtml_class_entry, "render_flags", sizeof("render_flags")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
+}

0 comments on commit 0db2010

Please sign in to comment.
Something went wrong with that request. Please try again.