From 6b9fe9b6d0fd6417656cc13e7b676c696f010ab9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 4 May 2012 17:43:12 +0900 Subject: [PATCH 1/5] add Sundown\Render\HTML_TOC render. --- config.m4 | 1 + php_sundown.c | 3 +- php_sundown.h | 6 + render_html_toc.c | 608 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 617 insertions(+), 1 deletion(-) create mode 100644 render_html_toc.c diff --git a/config.m4 b/config.m4 index b38ed91..9d1e99e 100644 --- a/config.m4 +++ b/config.m4 @@ -8,6 +8,7 @@ if test $PHP_SUNDOWN != "no"; then render_base.c \ render_html.c \ render_xhtml.c \ + render_html_toc.c \ buffer.c \ markdown.c \ html.c \ diff --git a/php_sundown.c b/php_sundown.c index 65df44f..ad70a62 100644 --- a/php_sundown.c +++ b/php_sundown.c @@ -20,9 +20,9 @@ #include "php_sundown.h" extern void php_sundown_render_html_init(TSRMLS_D); +extern void php_sundown_render_html_toc_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); zend_class_entry *sundown_class_entry; @@ -217,6 +217,7 @@ PHP_MINIT_FUNCTION(sundown) { php_sundown_render_base_init(TSRMLS_C); php_sundown_render_html_init(TSRMLS_C); php_sundown_render_xhtml_init(TSRMLS_C); + php_sundown_render_html_toc_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); diff --git a/php_sundown.h b/php_sundown.h index f204870..8689583 100644 --- a/php_sundown.h +++ b/php_sundown.h @@ -56,6 +56,12 @@ typedef struct{ struct sd_callbacks cb; } php_sundown_render_html_t; +typedef struct{ + zend_object zo; + struct html_renderopt html; + struct sd_callbacks cb; +} php_sundown_render_html_toc_t; + typedef struct{ zend_object zo; struct html_renderopt html; diff --git a/render_html_toc.c b/render_html_toc.c new file mode 100644 index 0000000..3b325f7 --- /dev/null +++ b/render_html_toc.c @@ -0,0 +1,608 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Shuhei Tanuma | + +----------------------------------------------------------------------+ + */ + + +#include "php_sundown.h" +#include "html.h" + +static void php_sundown_render_html_toc_free_storage(php_sundown_render_html_toc_t *obj TSRMLS_DC) +{ + zend_object_std_dtor(&obj->zo TSRMLS_CC); + efree(obj); +} + +zend_object_value php_sundown_render_html_toc_new(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value retval; + php_sundown_render_html_toc_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_html_toc_free_storage, + NULL TSRMLS_CC); + retval.handlers = zend_get_std_object_handlers(); + return retval; +} + +zend_class_entry *sundown_render_html_toc_class_entry; +extern zend_class_entry *sundown_render_base_class_entry; + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc___construct, 0, 0, 1) + ZEND_ARG_INFO(0, render_flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_block_code, 0, 0, 2) + ZEND_ARG_INFO(0, language) + ZEND_ARG_INFO(0, code) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_block_quote, 0, 0, 1) + ZEND_ARG_INFO(0, quote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_block_html, 0, 0, 1) + ZEND_ARG_INFO(0, raw_html) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_header, 0, 0, 2) + ZEND_ARG_INFO(0, htext) + ZEND_ARG_INFO(0, header_level) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_hrule, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_list_box, 0, 0, 2) + ZEND_ARG_INFO(0, contents) + ZEND_ARG_INFO(0, list_type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_list_item, 0, 0, 2) + ZEND_ARG_INFO(0, text) + ZEND_ARG_INFO(0, list_type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_paragraph, 0, 0, 1) + ZEND_ARG_INFO(0, text) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_table, 0, 0, 2) + ZEND_ARG_INFO(0, header) + ZEND_ARG_INFO(0, body) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_table_row, 0, 0, 1) + ZEND_ARG_INFO(0, content) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_table_cell, 0, 0, 2) + ZEND_ARG_INFO(0, content) + ZEND_ARG_INFO(0, alignment) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_autolink, 0, 0, 2) + ZEND_ARG_INFO(0, link) + ZEND_ARG_INFO(0, link_type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_codespan, 0, 0, 1) + ZEND_ARG_INFO(0, code) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_double_emphasis, 0, 0, 1) + ZEND_ARG_INFO(0, text) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_emphasis, 0, 0, 1) + ZEND_ARG_INFO(0, text) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_image, 0, 0, 3) + ZEND_ARG_INFO(0, link) + ZEND_ARG_INFO(0, title) + ZEND_ARG_INFO(0, alt_text) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_linebreak, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_link, 0, 0, 3) + ZEND_ARG_INFO(0, link) + ZEND_ARG_INFO(0, title) + ZEND_ARG_INFO(0, content) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_raw_html, 0, 0, 1) + ZEND_ARG_INFO(0, raw_html) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_triple_emphasis, 0, 0, 1) + ZEND_ARG_INFO(0, text) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_strikethrough, 0, 0, 1) + ZEND_ARG_INFO(0, text) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_superscript, 0, 0, 1) + ZEND_ARG_INFO(0, text) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_entity, 0, 0, 1) + ZEND_ARG_INFO(0, text) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_normal_text, 0, 0, 1) + ZEND_ARG_INFO(0, text) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_doc_header, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_doc_footer, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_html_toc_postprocess, 0, 0, 1) + ZEND_ARG_INFO(0, text) +ZEND_END_ARG_INFO() + +/* {{{ proto stirng Sundown\Render\HTML_TOC::blockCode($language, $code) +*/ +PHP_METHOD(sundown_render_html_toc, blockCode) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::blockQuote($quote) +*/ +PHP_METHOD(sundown_render_html_toc, blockQuote) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::blockHtml() +*/ +PHP_METHOD(sundown_render_html_toc, blockHtml) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::header($htext,$header_level) +*/ +PHP_METHOD(sundown_render_html_toc, header) +{ + char *htext; + int htext_len; + long header_level; + struct buf *input, *output; + php_sundown_buffer_t *object; + php_sundown_render_html_toc_t *html; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sl",&htext, &htext_len, &header_level) == FAILURE) { + return; + } + + html = (php_sundown_render_html_toc_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + php_sundown_render_base_t *base = (php_sundown_render_base_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + input = str2buf(htext, htext_len); + output = bufnew(128); + html->cb.header(output,input,header_level, &base->html); + bufrelease(input); + RETVAL_STRINGL(output->data, output->size,1); + bufrelease(output); +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::hrule() +*/ +PHP_METHOD(sundown_render_html_toc, hrule) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::listBox($contents, $list_type) +*/ +PHP_METHOD(sundown_render_html_toc, listBox) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::listItem($text, $list_type) +*/ +PHP_METHOD(sundown_render_html_toc, listItem) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::paragraph($text) +*/ +PHP_METHOD(sundown_render_html_toc, paragraph) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::table($header, $body) +*/ +PHP_METHOD(sundown_render_html_toc, table) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::tableRow($content) +*/ +PHP_METHOD(sundown_render_html_toc, tableRow) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::tableCell($content, $alignment) +*/ +PHP_METHOD(sundown_render_html_toc, tableCell) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::autolink($link, $link_type) +*/ +PHP_METHOD(sundown_render_html_toc, autolink) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::codespan($code) +*/ +PHP_METHOD(sundown_render_html_toc, codespan) +{ + char *code; + int code_len; + struct buf *input, *output; + php_sundown_buffer_t *object; + php_sundown_render_html_toc_t *html; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &code, &code_len) == FAILURE) { + return; + } + + input = str2buf(code, code_len); + output = bufnew(128); + html = (php_sundown_render_html_toc_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + html->cb.codespan(output,input, &html->html); + bufrelease(input); + RETVAL_STRINGL(output->data, output->size,1); + bufrelease(output); +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::doubleEmphasis($text) +*/ +PHP_METHOD(sundown_render_html_toc, doubleEmphasis) +{ + char *text; + int text_len; + struct buf *input, *output; + php_sundown_buffer_t *object; + php_sundown_render_html_toc_t *html; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s",&text, &text_len) == FAILURE) { + return; + } + + html = (php_sundown_render_html_toc_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + php_sundown_render_base_t *base = (php_sundown_render_base_t *) zend_object_store_get_object(getThis() TSRMLS_CC);\ + input = str2buf(text, text_len); + output = bufnew(128); + html->cb.double_emphasis(output,input, &base->html); + bufrelease(input); + RETVAL_STRINGL(output->data, output->size,1); + bufrelease(output); +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::emphasis($text) +*/ +PHP_METHOD(sundown_render_html_toc, emphasis) +{ + char *text; + int text_len; + struct buf *input, *output; + php_sundown_buffer_t *object; + php_sundown_render_html_toc_t *html; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &text, &text_len) == FAILURE) { + return; + } + + html = (php_sundown_render_html_toc_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + php_sundown_render_base_t *base = (php_sundown_render_base_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + input = str2buf(text, text_len); + output = bufnew(128); + html->cb.emphasis(output,input, &base->html); + bufrelease(input); + RETVAL_STRINGL(output->data, output->size,1); + bufrelease(output); +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::image($link, $title, $alt_text) +*/ +PHP_METHOD(sundown_render_html_toc, image) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::linebreak() +*/ +PHP_METHOD(sundown_render_html_toc, linebreak) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::link($link,$title,$content) +*/ +PHP_METHOD(sundown_render_html_toc, link) +{ + char *link, *title, *content; + int link_len, title_len, content_len; + struct buf *m_link, *m_title, *m_content, *output; + php_sundown_buffer_t *object; + php_sundown_render_html_toc_t *html; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sss",&link, &link_len, &title, &title_len, &content, &content_len) == FAILURE) { + return; + } + + html = (php_sundown_render_html_toc_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + m_link = str2buf(link, link_len); + m_title = str2buf(title, title_len); + m_content = str2buf(content, content_len); + output = bufnew(128); + html->cb.link(output,m_link, m_title, m_content, &html->html); + bufrelease(m_link); + bufrelease(m_title); + bufrelease(m_content); + RETVAL_STRINGL(output->data, output->size,1); + bufrelease(output); +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::rawHtml($raw_html) +*/ +PHP_METHOD(sundown_render_html_toc, rawHtml) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::tripleEmphasis($text) +*/ +PHP_METHOD(sundown_render_html_toc, tripleEmphasis) +{ + char *text; + int text_len; + struct buf *input, *output; + php_sundown_buffer_t *object; + php_sundown_render_html_toc_t *html; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &text, &text_len) == FAILURE) { + return; + } + + html = (php_sundown_render_html_toc_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + input = str2buf(text, text_len); + output = bufnew(128); + html->cb.triple_emphasis(output,input, &html->html); + bufrelease(input); + RETVAL_STRINGL(output->data, output->size,1); + bufrelease(output); +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::strikethrough($text) +*/ +PHP_METHOD(sundown_render_html_toc, strikethrough) +{ + char *text; + int text_len; + struct buf *input, *output; + php_sundown_render_html_toc_t *html; + php_sundown_buffer_t *object; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &text, &text_len) == FAILURE) { + return; + } + + html = (php_sundown_render_html_toc_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + input = str2buf(text, text_len); + output = bufnew(128); + html->cb.strikethrough(output,input, &html->html); + bufrelease(input); + RETVAL_STRINGL(output->data, output->size,1); + bufrelease(output); +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::superscript($text) +*/ +PHP_METHOD(sundown_render_html_toc, superscript) +{ + char *text; + int text_len; + struct buf *input, *output; + php_sundown_buffer_t *object; + php_sundown_render_html_toc_t *html; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s",&text, &text_len) == FAILURE) { + return; + } + + html = (php_sundown_render_html_toc_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + input = str2buf(text, text_len); + output = bufnew(128); + html->cb.superscript(output,input, &html->html); + bufrelease(input); + RETVAL_STRINGL(output->data, output->size,1); + bufrelease(output); +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::entity($text) +*/ +PHP_METHOD(sundown_render_html_toc, entity) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::normalText($text) +*/ +PHP_METHOD(sundown_render_html_toc, normalText) +{ + char *text; + int text_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s",&text, &text_len) == FAILURE) { + return; + } + + RETVAL_STRINGL(text,text_len,1); +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::docHeader() +*/ +PHP_METHOD(sundown_render_html_toc, docHeader) +{ + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::docFooter() +*/ +PHP_METHOD(sundown_render_html_toc, docFooter) +{ + struct buf *output; + php_sundown_buffer_t *object; + php_sundown_render_html_toc_t *html; + + html = (php_sundown_render_html_toc_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + output = bufnew(128); + html->cb.doc_footer(output,&html->html); + RETVAL_STRINGL(output->data, output->size,1); + bufrelease(output); +} +/* }}} */ + +/* {{{ proto string Sundown\Render\HTML_TOC::__construct($render_flags) +*/ +PHP_METHOD(sundown_render_html_toc, __construct) +{ + php_sundown_render_html_toc_t *object; + struct php_sundown_renderopt_ex opt; + zval *render_flags = NULL, *c_flags = NULL; + + 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, 0); + } else { + MAKE_STD_ZVAL(c_flags); + array_init(c_flags); + } + add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),c_flags TSRMLS_CC); + + object = (php_sundown_render_html_toc_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + sdhtml_toc_renderer(&object->cb, &opt.html); + opt.self = getThis(); +} +/* }}} */ + +static zend_function_entry php_sundown_render_html_toc_methods[] = { + PHP_ME(sundown_render_html_toc, __construct, arginfo_sundown_render_html_toc___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_ME(sundown_render_html_toc, blockCode, arginfo_sundown_render_html_toc_block_code, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, blockQuote, arginfo_sundown_render_html_toc_block_quote, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, blockHtml, arginfo_sundown_render_html_toc_block_html, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, header, arginfo_sundown_render_html_toc_header, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, hrule, arginfo_sundown_render_html_toc_hrule, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, listBox, arginfo_sundown_render_html_toc_list_box, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, listItem, arginfo_sundown_render_html_toc_list_item, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, paragraph, arginfo_sundown_render_html_toc_paragraph, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, table, arginfo_sundown_render_html_toc_table, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, tableRow, arginfo_sundown_render_html_toc_table_row, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, tableCell, arginfo_sundown_render_html_toc_table_cell, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, autolink, arginfo_sundown_render_html_toc_autolink, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, codespan, arginfo_sundown_render_html_toc_codespan, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, doubleEmphasis, arginfo_sundown_render_html_toc_double_emphasis, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, emphasis, arginfo_sundown_render_html_toc_emphasis, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, image, arginfo_sundown_render_html_toc_image, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, linebreak, arginfo_sundown_render_html_toc_linebreak, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, link, arginfo_sundown_render_html_toc_link, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, rawHtml, arginfo_sundown_render_html_toc_raw_html, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, tripleEmphasis, arginfo_sundown_render_html_toc_triple_emphasis, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, strikethrough, arginfo_sundown_render_html_toc_strikethrough, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, superscript, arginfo_sundown_render_html_toc_superscript, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, entity, arginfo_sundown_render_html_toc_entity, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, normalText, arginfo_sundown_render_html_toc_normal_text, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, docHeader, arginfo_sundown_render_html_toc_doc_header, ZEND_ACC_PUBLIC) + PHP_ME(sundown_render_html_toc, docFooter, arginfo_sundown_render_html_toc_doc_footer, ZEND_ACC_PUBLIC) + {NULL,NULL,NULL} +}; + +void php_sundown_render_html_toc_init(TSRMLS_D) +{ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, ZEND_NS_NAME("Sundown","Render"),"HTML_TOC", php_sundown_render_html_toc_methods); + sundown_render_html_toc_class_entry = zend_register_internal_class_ex(&ce, sundown_render_base_class_entry, NULL TSRMLS_CC); + sundown_render_html_toc_class_entry->create_object = php_sundown_render_html_toc_new; + zend_declare_property_null(sundown_render_html_toc_class_entry, "render_flags", sizeof("render_flags")-1, ZEND_ACC_PUBLIC TSRMLS_CC); +} From 1e3bf31119880fe4816463699fb919b5dcceb39d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 4 May 2012 18:06:11 +0900 Subject: [PATCH 2/5] add Sundown\Markdown::setRender(Sundown\Render\Base $render); --- sundown_markdown.c | 29 +++++++++++++++ tests/003-advanced-set-render.phpt | 58 ++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100755 tests/003-advanced-set-render.phpt diff --git a/sundown_markdown.c b/sundown_markdown.c index 446acaf..79ed0d9 100644 --- a/sundown_markdown.c +++ b/sundown_markdown.c @@ -269,6 +269,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_markdown_render, 0, 0, 1) ZEND_ARG_INFO(0, body) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_markdown_set_render, 0, 0, 1) + ZEND_ARG_INFO(0, render) +ZEND_END_ARG_INFO() + + ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_markdown_set_extensions, 0, 0, 1) ZEND_ARG_INFO(0, extension) ZEND_END_ARG_INFO() @@ -590,11 +595,35 @@ PHP_METHOD(sundown_markdown, getRender) } /* }}} */ +/* {{{ proto void string Sundown\Markdown::setRender(Sundown\Render\Base $render) +*/ +PHP_METHOD(sundown_markdown, setRender) +{ + zval *render = NULL; + 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", &render) == FAILURE) { + return; + } + + if (!instanceof_function_ex(Z_OBJCE_P(render), sundown_render_base_class_entry, 0 TSRMLS_CC)) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"Render class must extend Sundown\\Render\\Base"); + return; + } + zval_ptr_dtor(&object->render); + object->render = render; + Z_ADDREF_P(render); +} +/* }}} */ + + 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) PHP_ME(sundown_markdown, render, arginfo_sundown_markdown_render, ZEND_ACC_PUBLIC) PHP_ME(sundown_markdown, getRender, NULL, ZEND_ACC_PUBLIC) + PHP_ME(sundown_markdown, setRender, arginfo_sundown_markdown_set_render, ZEND_ACC_PUBLIC) PHP_ME(sundown_markdown, getExtensions, NULL, ZEND_ACC_PUBLIC) PHP_ME(sundown_markdown, setExtensions, arginfo_sundown_markdown_set_extensions, ZEND_ACC_PUBLIC) PHP_ME(sundown_markdown, hasExtension, arginfo_sundown_markdown_has_extension, ZEND_ACC_PUBLIC) diff --git a/tests/003-advanced-set-render.phpt b/tests/003-advanced-set-render.phpt new file mode 100755 index 0000000..3021d79 --- /dev/null +++ b/tests/003-advanced-set-render.phpt @@ -0,0 +1,58 @@ +--TEST-- +Check for Sundown\Markdown::setRender +--SKIPIF-- + +--FILE-- +render($data); +echo "DATA\n"; +$md->setRender(new Sundown\Render\HTML(array("with_toc_data"=>true))); +echo $md->render($data); +$render = new Sundown\Render\HTML(array("with_toc_data"=>true)); +$md->setRender($render); +echo $md->render($data); +$md->setRender(new Sundown\Render\HTML(array("with_toc_data"=>true))); +echo "#check render was not destroyed\n"; +if($render instanceof Sundown\Render\HTML) { +echo "OK"; +} else { +echo "FAILURE"; +} + +--EXPECT-- +TOC_DATA + +DATA +

Hello World

+

lorem ipsum dolar sit amet

+

the World, What a beautiful it is.

+

lorem ipsum dolar sit amet

+

Hello World

+

lorem ipsum dolar sit amet

+

the World, What a beautiful it is.

+

lorem ipsum dolar sit amet

+#check render was not destroyed +OK \ No newline at end of file From b1e80f13ba3c859bffe179efe82f0966d1f4b8d3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 14 May 2012 22:54:07 +0900 Subject: [PATCH 3/5] improve build script. now, you don't need call `rake gather` task. just do following commands. git submodule init git submodule update phpize ./configure make --- .gitignore | 17 ----------------- Rakefile | 14 ++------------ config.m4 | 43 +++++++++++++++++++++++++++---------------- 3 files changed, 29 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index 10f8efb..c00b378 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,5 @@ *.o -# ignore sundown sources. -autolink.c -autolink.h -buffer.c -buffer.h -houdini.h -houdini_href_e.c -houdini_html_e.c -html.c -html.h -html_blocks.h -html_smartypants.c -stack.c -stack.h -markdown.c -markdown.h - # ignore phpized files Makefile.global acinclude.m4 diff --git a/Rakefile b/Rakefile index 3e99f16..dde5010 100644 --- a/Rakefile +++ b/Rakefile @@ -32,17 +32,8 @@ task "test:conformance" do end desc 'Gather required Sundown sources into extension directory' -task :gather => 'sundown/src/markdown.h' do |t| - files = - FileList[ - 'sundown/src/{markdown,buffer,stack,autolink,html_blocks}.h', - 'sundown/src/{markdown,buffer,stack,autolink}.c', - 'sundown/html/{html,html_smartypants,houdini_html_e,houdini_href_e}.c', - 'sundown/html/{html,houdini}.h', - ] - cp files, './', - :preserve => true, - :verbose => true +task :gather do + abort "gather task become deprecated. now you don't need call this task." end file 'sundown/src/markdown.h' do |t| @@ -52,5 +43,4 @@ end task :submodule do sh "git submodule init" sh "git submodule update" - Rake::Task['gather'].invoke end diff --git a/config.m4 b/config.m4 index 9d1e99e..ece07db 100644 --- a/config.m4 +++ b/config.m4 @@ -2,20 +2,31 @@ PHP_ARG_ENABLE(sundown,Whether to enable the "sundown" extension, [ --enable-sundown Enable "sundown" extension support]) if test $PHP_SUNDOWN != "no"; then - PHP_NEW_EXTENSION(sundown, - php_sundown.c \ - sundown_markdown.c \ - render_base.c \ - render_html.c \ - render_xhtml.c \ - render_html_toc.c \ - buffer.c \ - markdown.c \ - html.c \ - html_smartypants.c \ - autolink.c \ - stack.c \ - houdini_href_e.c \ - houdini_html_e.c \ - , $ext_shared) + SUNDOWN_SOURCES=" +php_sundown.c +sundown_markdown.c +render_base.c +render_html.c +render_xhtml.c +render_html_toc.c +sundown/src/buffer.c +sundown/src/markdown.c +sundown/src/autolink.c +sundown/src/stack.c +sundown/html/html.c +sundown/html/html_smartypants.c +sundown/html/houdini_href_e.c +sundown/html/houdini_html_e.c +" + + PHP_NEW_EXTENSION(sundown,$SUNDOWN_SOURCES, $ext_shared) + CFLAGS=" -Wunused-variable -Wpointer-sign -Wimplicit-function-declaration" + PHP_SUBST([CFLAGS]) + + PHP_ADD_BUILD_DIR([$ext_builddir/sundown/src]) + + PHP_ADD_INCLUDE([$ext_srcdir/sundown/src]) + PHP_ADD_INCLUDE([$ext_srcdir/sundown/html]) + PHP_ADD_INCLUDE([$ext_builddir/sundown/src]) + PHP_ADD_INCLUDE([$ext_builddir/sundown/html]) fi From 157e45efecc480b613e7d3f81d1957cb8856e32a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 14 May 2012 23:17:43 +0900 Subject: [PATCH 4/5] add Changelog, adjust package.xml --- Changelog | 61 +++++++++++++++++++++++++++ config.m4 | 1 + package.xml | 112 +++++++++++++++++++++++-------------------------- render_xhtml.c | 4 +- 4 files changed, 116 insertions(+), 62 deletions(-) create mode 100644 Changelog diff --git a/Changelog b/Changelog new file mode 100644 index 0000000..1260940 --- /dev/null +++ b/Changelog @@ -0,0 +1,61 @@ +2010-04-22 Shuhei Tanuma + + * bumped up 0.3.3: + + [summary] + * fix #16 missing space_after_headers extension + +2010-04-02 Shuhei Tanuma + + * bumped up 0.3.1: + + [summary] + * fixed overloading callback methods. + * fixed segfault when calling render method more than once. + * implement more test cases. + +2010-03-04 Shuhei Tanuma + + * bumped up 0.3.0: + + change callback method name for PECL standards. + php-sundown aims to implement more test cases until next minor version release. + + [summary] + * change callback method names for PECL standards + * fix segfault when using XHTML render + * fix getting render flags issue + * improve Sundown\Markdown + don'd read render / extensions property directly. + * fix memory leaks + * implement more test cases. + +2010-03-04 Shuhei Tanuma + + * bumped up 0.2.0: + + * checks extensions and render flags value. + + 0.1.0b release only checks specified key exist. Now, it also checks their value. + + * added useful methods. + + array Sundown\Render\Base::getRenderFlags() + void Sundown\Render\Base::setRenderFlags(array $render_flags) + + array Sundown\Markdown::getExtensions() + void Sundown\Markdown::setExtensions(array $extensions) + Sundown\Render\Base Sundown\Markdown::getRender() + + * update bundled Sundown library + + [summary] + * Fix segfault on empty link refs + * Escape html inside table of contents. + * hanging whitespace breaks tables + + +2010-02-05 Shuhei Tanuma + + * bumped up 0.2.0: + - Initial PECL Sundown release. diff --git a/config.m4 b/config.m4 index ece07db..2f1a4b1 100644 --- a/config.m4 +++ b/config.m4 @@ -24,6 +24,7 @@ sundown/html/houdini_html_e.c PHP_SUBST([CFLAGS]) PHP_ADD_BUILD_DIR([$ext_builddir/sundown/src]) + PHP_ADD_BUILD_DIR([$ext_builddir/sundown/html]) PHP_ADD_INCLUDE([$ext_srcdir/sundown/src]) PHP_ADD_INCLUDE([$ext_srcdir/sundown/html]) diff --git a/package.xml b/package.xml index 43db5be..3113819 100644 --- a/package.xml +++ b/package.xml @@ -38,23 +38,6 @@ bumped up 0.3.3 - - - - - - - - - - - - - - - - - @@ -62,25 +45,64 @@ bumped up 0.3.3 + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -187,36 +209,6 @@ Sundown\Render\Base Sundown\Markdown::getRender() * update bundled Sundown library -[summary] - * Fix segfault on empty link refs - * Escape html inside table of contents. - * hanging whitespace breaks tables - - - - - beta - beta - - - 0.2.0 - 0.2.0 - - 2012-02-21 - -* checks extensions and render flags value. - -0.1.0b release only checks specified key exist. Now, it also checks their value. - -* added useful methods. - -array Sundown\Render\Base::getRenderFlags() -void Sundown\Render\Base::setRenderFlags(array $render_flags) - -array Sundown\Markdown::getExtensions() -void Sundown\Markdown::setExtensions(array $extensions) -Sundown\Render\Base Sundown\Markdown::getRender() - [summary] * Fix segfault on empty link refs * Escape html inside table of contents. diff --git a/render_xhtml.c b/render_xhtml.c index be07079..19836b5 100644 --- a/render_xhtml.c +++ b/render_xhtml.c @@ -49,7 +49,7 @@ zend_object_value php_sundown_render_xhtml_new(zend_class_entry *ce TSRMLS_DC) return retval; } -ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render___construct,0,0,1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_xhtml__construct,0,0,1) ZEND_ARG_INFO(0, render_flags) ZEND_END_ARG_INFO() @@ -114,7 +114,7 @@ PHP_METHOD(sundown_render_xhtml, __construct) static zend_function_entry php_sundown_render_xhtml_methods[] = { - PHP_ME(sundown_render_xhtml, __construct, arginfo_sundown_render___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_ME(sundown_render_xhtml, __construct, arginfo_sundown_render_xhtml__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) {NULL,NULL,NULL} }; From 6fe73e873ef13a0ec068c56aa49b541333d4fbe9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 14 May 2012 23:27:52 +0900 Subject: [PATCH 5/5] bumped up 0.3.4 [summary] * add Sundown\Render\HTML_TOC render. * add Sundown\Markdown::setRender(Sundown\Render\Base $render); * improve build script. * add Changelog, adjust package.xml --- README.md | 30 +++++++++++++++++++++++++++--- package.xml | 31 +++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 96dc33c..ee88a1b 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,11 @@ Install for developpers git clone https://github.com/chobie/php-sundown.git php-sundown -b development cd php-sundown - # this command will fetch submodule and copy neccesally files to src dir. and compile it. - rake submodule compile - sudo rake install + git submodule init && git submodule update + phpze + ./configure + make + make install # please add following line to your php.ini # extension=sundown.so @@ -229,6 +231,28 @@ $md = new \Sundown\Markdown(\Sundown\Render\HTML,array("autolink"=>true)); $md->getRender()->setRenderFlags(array("filter_html"=>true)); ```` +### \Sundown\Markdown::setRender(Sundown\Render\Base $render) + +##### *Description* + +set render instance. + +##### *Parameters* + +*render*: render instance + +##### *Return Value* + +* void + +##### *Example* + +````php +true)); +$render2 = \Sundown\Render\HTML(); +$md->setRender($render2); +```` ### \Sundown\Render\Base diff --git a/package.xml b/package.xml index 3113819..4f4430b 100644 --- a/package.xml +++ b/package.xml @@ -15,10 +15,10 @@ PECL Sundown provides straight forward object oriented Markdown API and customiz chobieeee@php.net yes - 2012-04-22 + 2012-05-14 - 0.3.3 - 0.3.0 + 0.3.4 + 0.3.4 beta @@ -26,10 +26,13 @@ PECL Sundown provides straight forward object oriented Markdown API and customiz PHP -bumped up 0.3.3 +bumped up 0.3.4 [summary] - * fix #16 missing space_after_headers extension + * add Sundown\Render\HTML_TOC render. + * add Sundown\Markdown::setRender(Sundown\Render\Base $render); + * improve build script. + * add Changelog, adjust package.xml @@ -120,6 +123,23 @@ bumped up 0.3.3 sundown + + + beta + beta + + + 0.3.3 + 0.3.0 + + 2012-04-22 + +bumped up 0.3.3 + +[summary] + * fix #16 missing space_after_headers extension + + beta @@ -137,7 +157,6 @@ bumped up 0.3.2 * use no_intra_emphasis instead of no_intraemphasis - beta