Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 614 lines (510 sloc) 17.651 kb
c2e0d3a @chobie for now, adding base render.
authored
1 /*
798c4cf @chobie change license to PHP License from MIT.
authored
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2011 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Shuhei Tanuma <chobieee@gmail.com> |
16 +----------------------------------------------------------------------+
c2e0d3a @chobie for now, adding base render.
authored
17 */
18
19 #include "php_sundown.h"
20
4b10a7e @chobie add Sundown\Buffer class.
authored
21 extern zend_class_entry *sundown_render_base_class_entry;
c2e0d3a @chobie for now, adding base render.
authored
22
4b10a7e @chobie add Sundown\Buffer class.
authored
23 zend_class_entry *sundown_markdown_class_entry;
24
add5c2b @chobie adjust function signature
authored
25 static void rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
26 {
ce930ea @chobie for now, fix getting render flags issue.
authored
27 BLOCK_CALLBACK_EX(ob,"blockCode", 2, buf2str(text), buf2str(lang));
4b10a7e @chobie add Sundown\Buffer class.
authored
28 }
29
add5c2b @chobie adjust function signature
authored
30 static void rndr_blockquote(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
31 {
ce930ea @chobie for now, fix getting render flags issue.
authored
32 BLOCK_CALLBACK_EX(ob,"blockQuote", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
33 }
34
add5c2b @chobie adjust function signature
authored
35 static void rndr_raw_block(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
36 {
ce930ea @chobie for now, fix getting render flags issue.
authored
37 BLOCK_CALLBACK_EX(ob,"blockHtml", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
38 }
39
add5c2b @chobie adjust function signature
authored
40 static void rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
41 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
42 BLOCK_CALLBACK_EX(ob,"header", 2, buf2str(text), buf2long(level));
4b10a7e @chobie add Sundown\Buffer class.
authored
43 }
44
45 static void rndr_hrule(struct buf *ob, void *opaque)
46 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
47 BLOCK_CALLBACK_EX(ob,"hrule", 0);
4b10a7e @chobie add Sundown\Buffer class.
authored
48 }
49
add5c2b @chobie adjust function signature
authored
50 static void rndr_list(struct buf *ob, const struct buf *text, int flags, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
51 {
2f88fca @chobie fix something. add Markdown test case. we've just passed MarkdownTest_1....
authored
52 zval *flag;
53 MAKE_STD_ZVAL(flag);
54 ZVAL_LONG(flag, flags);
ce930ea @chobie for now, fix getting render flags issue.
authored
55 BLOCK_CALLBACK_EX(ob,"listBox", 2,buf2str(text),flag);
71ba79b @chobie update sundown and support Sondown\Render\HTML
authored
56
4b10a7e @chobie add Sundown\Buffer class.
authored
57 }
58
add5c2b @chobie adjust function signature
authored
59 static void rndr_listitem(struct buf *ob, const struct buf *text, int flags, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
60 {
2f88fca @chobie fix something. add Markdown test case. we've just passed MarkdownTest_1....
authored
61 zval *flag;
62 MAKE_STD_ZVAL(flag);
63 ZVAL_LONG(flag, flags);
ce930ea @chobie for now, fix getting render flags issue.
authored
64 BLOCK_CALLBACK_EX(ob,"listItem", 2, buf2str(text),flag);
4b10a7e @chobie add Sundown\Buffer class.
authored
65 }
66
add5c2b @chobie adjust function signature
authored
67 static void rndr_paragraph(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
68 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
69 BLOCK_CALLBACK_EX(ob,"paragraph", 1,buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
70 }
71
add5c2b @chobie adjust function signature
authored
72 static void rndr_table(struct buf *ob, const struct buf *header, const struct buf *body, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
73 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
74 BLOCK_CALLBACK_EX(ob,"table", 2, buf2str(header), buf2str(body));
4b10a7e @chobie add Sundown\Buffer class.
authored
75 }
76
add5c2b @chobie adjust function signature
authored
77 static void rndr_tablerow(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
78 {
ce930ea @chobie for now, fix getting render flags issue.
authored
79 BLOCK_CALLBACK_EX(ob,"tableRow", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
80 }
81
add5c2b @chobie adjust function signature
authored
82 static void rndr_tablecell(struct buf *ob, const struct buf *text, int align, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
83 {
84 zval php_align;
85
86 switch (align) {
87 case MKD_TABLE_ALIGN_L:
88 ZVAL_STRING(&php_align, "left", 1);
89 break;
90
91 case MKD_TABLE_ALIGN_R:
92 ZVAL_STRING(&php_align, "right", 1);
93 break;
94
95 case MKD_TABLE_ALIGN_CENTER:
96 ZVAL_STRING(&php_align, "center", 1);
97 break;
98
99 default:
100 ZVAL_NULL(&php_align);
101 break;
102 }
103
ce930ea @chobie for now, fix getting render flags issue.
authored
104 BLOCK_CALLBACK_EX(ob,"tableCell", 2,buf2str(text), &php_align);
4b10a7e @chobie add Sundown\Buffer class.
authored
105 }
106
107 /***
108 * SPAN LEVEL
109 */
add5c2b @chobie adjust function signature
authored
110 static int rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
111 {
9cf6e7b @chobie fix memory leak
authored
112 zval *m_type;
9273baa @chobie following K&R coding style and fix misunderstood zend_parameter_parse va...
authored
113
9cf6e7b @chobie fix memory leak
authored
114 MAKE_STD_ZVAL(m_type);
115 if (type == MKDA_NORMAL) {
116 ZVAL_STRING(m_type, "url",1);
117 } else {
118 ZVAL_STRING(m_type, "email",1);
119 }
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
120 SPAN_CALLBACK_EX(ob,"autolink", 2,buf2str(link),m_type);
4b10a7e @chobie add Sundown\Buffer class.
authored
121 }
122
add5c2b @chobie adjust function signature
authored
123 static int rndr_codespan(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
124 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
125 SPAN_CALLBACK_EX(ob,"codespan", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
126 }
127
add5c2b @chobie adjust function signature
authored
128 static int rndr_double_emphasis(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
129 {
ce930ea @chobie for now, fix getting render flags issue.
authored
130 SPAN_CALLBACK_EX(ob,"doubleEmphasis", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
131 }
132
add5c2b @chobie adjust function signature
authored
133 static int rndr_emphasis(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
134 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
135 SPAN_CALLBACK_EX(ob,"emphasis", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
136 }
137
add5c2b @chobie adjust function signature
authored
138 static int rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
139 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
140 SPAN_CALLBACK_EX(ob,"image", 3, buf2str(link), buf2str(title), buf2str(alt));
4b10a7e @chobie add Sundown\Buffer class.
authored
141 }
142
143 static int rndr_linebreak(struct buf *ob, void *opaque)
144 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
145 SPAN_CALLBACK_EX(ob,"linebreak", 0);
4b10a7e @chobie add Sundown\Buffer class.
authored
146 }
147
add5c2b @chobie adjust function signature
authored
148 static int rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
149 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
150 SPAN_CALLBACK_EX(ob,"link", 3, buf2str(link), buf2str(title), buf2str(content));
4b10a7e @chobie add Sundown\Buffer class.
authored
151 }
152
add5c2b @chobie adjust function signature
authored
153 static int rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
154 {
ce930ea @chobie for now, fix getting render flags issue.
authored
155 SPAN_CALLBACK_EX(ob, "rawHtml", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
156 }
157
add5c2b @chobie adjust function signature
authored
158 static int rndr_triple_emphasis(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
159 {
ce930ea @chobie for now, fix getting render flags issue.
authored
160 SPAN_CALLBACK_EX(ob, "tripleEmphasis", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
161 }
162
add5c2b @chobie adjust function signature
authored
163 static int rndr_strikethrough(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
164 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
165 SPAN_CALLBACK_EX(ob, "strikethrough", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
166 }
167
add5c2b @chobie adjust function signature
authored
168 static int rndr_superscript(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
169 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
170 SPAN_CALLBACK_EX(ob, "superscript", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
171 }
172
173 /**
174 * direct writes
175 */
add5c2b @chobie adjust function signature
authored
176 static void rndr_entity(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
177 {
206b2ba @chobie improve Sundown\Render\Base method signature.
authored
178 BLOCK_CALLBACK_EX(ob, "entity", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
179 }
180
add5c2b @chobie adjust function signature
authored
181 static void rndr_normal_text(struct buf *ob, const struct buf *text, void *opaque)
4b10a7e @chobie add Sundown\Buffer class.
authored
182 {
ce930ea @chobie for now, fix getting render flags issue.
authored
183 BLOCK_CALLBACK_EX(ob, "normalText", 1, buf2str(text));
4b10a7e @chobie add Sundown\Buffer class.
authored
184 }
185
186 static void rndr_doc_header(struct buf *ob, void *opaque)
187 {
ce930ea @chobie for now, fix getting render flags issue.
authored
188 BLOCK_CALLBACK_EX(ob, "docHeader", 0);
4b10a7e @chobie add Sundown\Buffer class.
authored
189 }
190
191 static void rndr_doc_footer(struct buf *ob, void *opaque)
192 {
ce930ea @chobie for now, fix getting render flags issue.
authored
193 BLOCK_CALLBACK_EX(ob, "docFooter", 0);
4b10a7e @chobie add Sundown\Buffer class.
authored
194 }
195
196
197 static struct sd_callbacks php_sundown_callbacks = {
198 rndr_blockcode,
199 rndr_blockquote,
200 rndr_raw_block,
201 rndr_header,
202 rndr_hrule,
203 rndr_list,
204 rndr_listitem,
205 rndr_paragraph,
206 rndr_table,
207 rndr_tablerow,
208 rndr_tablecell,
209
210 rndr_autolink,
211 rndr_codespan,
212 rndr_double_emphasis,
213 rndr_emphasis,
214 rndr_image,
215 rndr_linebreak,
216 rndr_link,
217 rndr_raw_html,
218 rndr_triple_emphasis,
219 rndr_strikethrough,
220 rndr_superscript,
221
222 rndr_entity,
223 rndr_normal_text,
224
225 rndr_doc_header,
226 rndr_doc_footer,
227 };
228
229 static const char *php_sundown_method_names[] = {
c9eca45 @chobie fix #13 fix overriding callback methods
authored
230 "blockcode",
231 "blockquote",
232 "blockhtml",
4b10a7e @chobie add Sundown\Buffer class.
authored
233 "header",
234 "hrule",
c9eca45 @chobie fix #13 fix overriding callback methods
authored
235 "listbox",
236 "listitem",
4b10a7e @chobie add Sundown\Buffer class.
authored
237 "paragraph",
238 "table",
c9eca45 @chobie fix #13 fix overriding callback methods
authored
239 "tablerow",
240 "tablecell",
4b10a7e @chobie add Sundown\Buffer class.
authored
241
242 "autolink",
243 "codespan",
c9eca45 @chobie fix #13 fix overriding callback methods
authored
244 "doubleemphasis",
4b10a7e @chobie add Sundown\Buffer class.
authored
245 "emphasis",
246 "image",
247 "linebreak",
248 "link",
c9eca45 @chobie fix #13 fix overriding callback methods
authored
249 "rawhtml",
250 "tripleemphasis",
4b10a7e @chobie add Sundown\Buffer class.
authored
251 "strikethrough",
252 "superscript",
253
254 "entity",
c9eca45 @chobie fix #13 fix overriding callback methods
authored
255 "normaltext",
4b10a7e @chobie add Sundown\Buffer class.
authored
256
c9eca45 @chobie fix #13 fix overriding callback methods
authored
257 "docheader",
258 "docfooter"
4b10a7e @chobie add Sundown\Buffer class.
authored
259 };
260
261 static const size_t php_sundown_method_count = sizeof(php_sundown_method_names)/sizeof(char *);
c2e0d3a @chobie for now, adding base render.
authored
262
263 ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_markdown__construct, 0, 0, 2)
264 ZEND_ARG_INFO(0, render)
265 ZEND_ARG_INFO(0, options)
266 ZEND_END_ARG_INFO()
267
268 ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_markdown_render, 0, 0, 1)
269 ZEND_ARG_INFO(0, body)
270 ZEND_END_ARG_INFO()
271
862657d @chobie add getExtensions and setExtensions method for Sundown\Markdown
authored
272 ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_markdown_set_extensions, 0, 0, 1)
273 ZEND_ARG_INFO(0, extension)
274 ZEND_END_ARG_INFO()
275
bc50651 @chobie fixed #9 : check enabled extensions or render flags correctly.
authored
276 ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_markdown_has_extension, 0, 0, 1)
277 ZEND_ARG_INFO(0, name)
278 ZEND_END_ARG_INFO()
279
e4f9933 @chobie add hasRenderFlag method
authored
280 ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_markdown_has_render_flag, 0, 0, 1)
281 ZEND_ARG_INFO(0, name)
282 ZEND_END_ARG_INFO()
283
c2e0d3a @chobie for now, adding base render.
authored
284 static void php_sundown_markdown_free_storage(php_sundown_markdown_t *obj TSRMLS_DC)
285 {
286 zend_object_std_dtor(&obj->zo TSRMLS_CC);
287 if (obj->render != NULL) {
288 zval_ptr_dtor(&obj->render);
289 }
290 efree(obj);
291 }
292
293 zend_object_value php_sundown_markdown_new(zend_class_entry *ce TSRMLS_DC)
294 {
295 zend_object_value retval;
296 php_sundown_markdown_t *obj;
297 zval *tmp;
298
299 obj = ecalloc(1, sizeof(*obj));
300 zend_object_std_init( &obj->zo, ce TSRMLS_CC );
4482819 @chobie PHP5.4 compatibility
authored
301 #if ZEND_MODULE_API_NO >= 20100525
302 object_properties_init(&(obj->zo), ce);
303 #else
c2e0d3a @chobie for now, adding base render.
authored
304 zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
4482819 @chobie PHP5.4 compatibility
authored
305 #endif
c2e0d3a @chobie for now, adding base render.
authored
306 retval.handle = zend_objects_store_put(obj,
307 (zend_objects_store_dtor_t)zend_objects_destroy_object,
308 (zend_objects_free_object_storage_t)php_sundown_markdown_free_storage,
309 NULL TSRMLS_CC);
310 retval.handlers = zend_get_std_object_handlers();
311 return retval;
312 }
313
314
77af627 @chobie modified method comments
authored
315 /* {{{ proto string Sundown\Markdown::__construct(Sundown\Render\Base $render [, array $extensions])
c2e0d3a @chobie for now, adding base render.
authored
316 */
317 PHP_METHOD(sundown_markdown, __construct)
318 {
319 zval *render;
df81b01 @chobie forget to init NULL
authored
320 zval *extensions = NULL, *c_extensions = NULL;
2f88fca @chobie fix something. add Markdown test case. we've just passed MarkdownTest_1....
authored
321 zend_class_entry **ce;
c2e0d3a @chobie for now, adding base render.
authored
322 php_sundown_markdown_t *object = (php_sundown_markdown_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
323
8d05840 @chobie adjust coding styles.
authored
324 if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
325 "z|a", &render, &extensions) == FAILURE) {
77af627 @chobie modified method comments
authored
326 zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC," Sundown\\Markdown::__construct() expects parameter 2 to be array");
c2e0d3a @chobie for now, adding base render.
authored
327 return;
328 }
329
330 if (Z_TYPE_P(render) == IS_STRING) {
9273baa @chobie following K&R coding style and fix misunderstood zend_parameter_parse va...
authored
331 if (zend_lookup_class(Z_STRVAL_P(render), strlen(Z_STRVAL_P(render)), &ce TSRMLS_CC) == FAILURE) {
45522f7 @chobie add exception and fix segv
authored
332 zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"class %s does not find.", Z_STRVAL_P(render));
2f88fca @chobie fix something. add Markdown test case. we've just passed MarkdownTest_1....
authored
333 return;
334 } else {
335 zval *func,*ret, *obj;
336
337 MAKE_STD_ZVAL(func);
338 MAKE_STD_ZVAL(ret);
339 MAKE_STD_ZVAL(obj);
340 ZVAL_STRING(func,"__construct",1);
341 object_init_ex(obj, *ce);
342 call_user_function(NULL, &obj,func,ret,0,NULL TSRMLS_CC);
343 zval_ptr_dtor(&func);
344 zval_ptr_dtor(&ret);
345 render = obj;
346 }
ecca581 @chobie fixed segv when make a render instance and passed it directly to Sundown...
authored
347 } else {
348 Z_ADDREF_P(render);
c2e0d3a @chobie for now, adding base render.
authored
349 }
4b10a7e @chobie add Sundown\Buffer class.
authored
350
54c122d @chobie false does not define almost environment
authored
351 if (!instanceof_function_ex(Z_OBJCE_P(render), sundown_render_base_class_entry, 0 TSRMLS_CC)) {
45522f7 @chobie add exception and fix segv
authored
352 zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"Render class must extend Sundown\\Render\\Base");
4b10a7e @chobie add Sundown\Buffer class.
authored
353 return;
354 }
c2e0d3a @chobie for now, adding base render.
authored
355 object->render = render;
356
498992e @chobie divided render_flags and extensions.
authored
357 if (extensions == NULL) {
27706d0 @chobie fixed segv when extensions or render flags ommited
authored
358 MAKE_STD_ZVAL(c_extensions);
359 array_init(c_extensions);
8a608a8 @chobie fixed segv when using Sundown\Markdown and adjust travis setting
authored
360 } else {
46a92dc @chobie use ZVAL_ZVAL instead of retaining render_flags and extensions.
authored
361 ALLOC_INIT_ZVAL(c_extensions);
362 ZVAL_ZVAL(c_extensions,extensions,1,0);
363 }
364 add_property_zval_ex(getThis(),"extensions",sizeof("extensions"),c_extensions TSRMLS_CC);
c2e0d3a @chobie for now, adding base render.
authored
365 }
366 /* }}} */
367
368
77af627 @chobie modified method comments
authored
369 /* {{{ proto void Sundown\Markdown::__destruct()
c2e0d3a @chobie for now, adding base render.
authored
370 cleanup variables */
371 PHP_METHOD(sundown_markdown, __destruct)
372 {
373 zval *extensions;
374
375 extensions = zend_read_property(sundown_markdown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC);
46a92dc @chobie use ZVAL_ZVAL instead of retaining render_flags and extensions.
authored
376 zval_ptr_dtor(&extensions);
c2e0d3a @chobie for now, adding base render.
authored
377 }
378 /* }}} */
379
380
381
77af627 @chobie modified method comments
authored
382 /* {{{ proto string Sundown\Markdown::render(string $body)
c2e0d3a @chobie for now, adding base render.
authored
383 */
384 PHP_METHOD(sundown_markdown, render)
385 {
386 php_sundown_markdown_t *object = (php_sundown_markdown_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
4b10a7e @chobie add Sundown\Buffer class.
authored
387 php_sundown_buffer_t *buffer_object_t;
ce930ea @chobie for now, fix getting render flags issue.
authored
388 php_sundown_render_base_t *render_base;
f6a5640 @chobie improve Sundown\Markdown:
authored
389 zval *buffer_object, preprocess, postprocess, *params[1], *ret, *render, *m_retval;
c2e0d3a @chobie for now, adding base render.
authored
390 struct buf input_buf, *output_buf;
391 struct sd_callbacks sundown_render;
4b10a7e @chobie add Sundown\Buffer class.
authored
392 struct php_sundown_renderopt_ex opt;
71ba79b @chobie update sundown and support Sondown\Render\HTML
authored
393 struct sd_markdown *markdown;
c2e0d3a @chobie for now, adding base render.
authored
394 unsigned int enabled_extensions = 0, render_flags = 0;
395 char *buffer;
396 int buffer_len = 0;
397 zend_class_entry *ce;
398 HashTable *table;
77af627 @chobie modified method comments
authored
399 void **source, **dest;
400 size_t i;
401
c2e0d3a @chobie for now, adding base render.
authored
402
8d05840 @chobie adjust coding styles.
authored
403 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
404 "s", &buffer, &buffer_len) == FAILURE) {
c2e0d3a @chobie for now, adding base render.
authored
405 return;
406 }
665039a @chobie now, preprocess and postprocess methods are able to use.
authored
407
c2e0d3a @chobie for now, adding base render.
authored
408 output_buf = bufnew(128);
8d05840 @chobie adjust coding styles.
authored
409 bufgrow(output_buf, buffer_len * 1.2f);
f6a5640 @chobie improve Sundown\Markdown:
authored
410
411 if (zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), NULL, "getrender", &render) == FAILURE) {
412 return;
413 }
498992e @chobie divided render_flags and extensions.
authored
414
f6a5640 @chobie improve Sundown\Markdown:
authored
415 if (zend_call_method_with_0_params(&render, Z_OBJCE_P(render), NULL, "getrenderflags", &m_retval)) {
416 table = Z_ARRVAL_P(m_retval);
498992e @chobie divided render_flags and extensions.
authored
417 php_sundown__get_render_flags(table, &render_flags);
418 table = NULL;
f6a5640 @chobie improve Sundown\Markdown:
authored
419 zval_ptr_dtor(&m_retval);
498992e @chobie divided render_flags and extensions.
authored
420 }
f6a5640 @chobie improve Sundown\Markdown:
authored
421
422 if (zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), NULL, "getextensions", &m_retval)) {
423 table = Z_ARRVAL_P(m_retval);
498992e @chobie divided render_flags and extensions.
authored
424 php_sundown__get_extensions(table, &enabled_extensions);
425 table = NULL;
f6a5640 @chobie improve Sundown\Markdown:
authored
426 zval_ptr_dtor(&m_retval);
c2e0d3a @chobie for now, adding base render.
authored
427 }
f6a5640 @chobie improve Sundown\Markdown:
authored
428
8d05840 @chobie adjust coding styles.
authored
429 /* @todo: setup render */
c2e0d3a @chobie for now, adding base render.
authored
430 switch (SUNDOWN_RENDER_HTML) {
431 case SUNDOWN_RENDER_HTML:
432 sdhtml_renderer(&sundown_render, &opt.html, render_flags);
433 break;
434 case SUNDOWN_RENDER_TOC:
435 sdhtml_toc_renderer(&sundown_render,&opt.html);
436 break;
437 default:
438 RETURN_FALSE;
439 }
440
f6a5640 @chobie improve Sundown\Markdown:
authored
441 render_base = (php_sundown_render_base_t *) zend_object_store_get_object(render TSRMLS_CC);
ce930ea @chobie for now, fix getting render flags issue.
authored
442 render_base->html = opt.html;
443
f6a5640 @chobie improve Sundown\Markdown:
authored
444 ce = Z_OBJCE_P(render);
445 opt.self = render;
4b10a7e @chobie add Sundown\Buffer class.
authored
446
77af627 @chobie modified method comments
authored
447 source = (void **)&php_sundown_callbacks;
448 dest = (void **)&sundown_render;
c2e0d3a @chobie for now, adding base render.
authored
449 for (i = 0; i < php_sundown_method_count; ++i) {
450 if (zend_hash_exists(&ce->function_table, php_sundown_method_names[i], strlen(php_sundown_method_names[i])+1)) {
451 dest[i] = source[i];
452 }
453 }
454
8d05840 @chobie adjust coding styles.
authored
455 /* preprocess */
665039a @chobie now, preprocess and postprocess methods are able to use.
authored
456 MAKE_STD_ZVAL(ret);
457 MAKE_STD_ZVAL(params[0]);
458 ZVAL_STRINGL(params[0], buffer,strlen(buffer), 1);
459 ZVAL_STRING(&preprocess,"preprocess",1);
f6a5640 @chobie improve Sundown\Markdown:
authored
460 if (call_user_function(NULL, &render, &preprocess, ret, 1, params TSRMLS_CC) == FAILURE) {
665039a @chobie now, preprocess and postprocess methods are able to use.
authored
461 }
462
463 memset(&input_buf, 0x0, sizeof(struct buf));
464 if (ret != NULL && Z_TYPE_P(ret) == IS_STRING) {
465 input_buf.data = Z_STRVAL_P(ret);
466 input_buf.size = Z_STRLEN_P(ret);
467 } else {
468 input_buf.data = buffer;
469 input_buf.size = strlen(buffer);
470 }
471 zval_ptr_dtor(&params[0]);
472
77af627 @chobie modified method comments
authored
473 /* proceess markdown */
b2dd5e7 @chobie fixed #5 render extension does not work correctly
authored
474 markdown = sd_markdown_new(enabled_extensions, 16, &sundown_render, &opt);
71ba79b @chobie update sundown and support Sondown\Render\HTML
authored
475 sd_markdown_render(output_buf, input_buf.data, input_buf.size, markdown);
476 sd_markdown_free(markdown);
665039a @chobie now, preprocess and postprocess methods are able to use.
authored
477
478 zval_ptr_dtor(&ret);
77af627 @chobie modified method comments
authored
479 /* postprocess */
665039a @chobie now, preprocess and postprocess methods are able to use.
authored
480 MAKE_STD_ZVAL(ret);
481 MAKE_STD_ZVAL(params[0]);
482 ZVAL_STRINGL(params[0], output_buf->data,output_buf->size, 1);
483 ZVAL_STRING(&postprocess,"postprocess",1);
f6a5640 @chobie improve Sundown\Markdown:
authored
484 if (call_user_function(NULL, &render, &postprocess, ret, 1, params TSRMLS_CC) == FAILURE) {
665039a @chobie now, preprocess and postprocess methods are able to use.
authored
485 }
486
487 if (ret != NULL && Z_TYPE_P(ret) == IS_STRING) {
488 RETVAL_STRINGL(Z_STRVAL_P(ret), Z_STRLEN_P(ret),1);
ba83764 @chobie now SmartyPants ready to use via Sundown\Markdown
authored
489 } else {
665039a @chobie now, preprocess and postprocess methods are able to use.
authored
490 RETVAL_STRINGL(output_buf->data,output_buf->size,1);
ba83764 @chobie now SmartyPants ready to use via Sundown\Markdown
authored
491 }
665039a @chobie now, preprocess and postprocess methods are able to use.
authored
492 zval_ptr_dtor(&ret);
493 zval_ptr_dtor(&params[0]);
494 zval_dtor(&postprocess);
495 zval_dtor(&preprocess);
f6a5640 @chobie improve Sundown\Markdown:
authored
496 zval_ptr_dtor(&render);
c2e0d3a @chobie for now, adding base render.
authored
497 }
913f423 @chobie fix unclosed marker
authored
498 /* }}} */
c2e0d3a @chobie for now, adding base render.
authored
499
500
bc50651 @chobie fixed #9 : check enabled extensions or render flags correctly.
authored
501 /* {{{ proto string Sundown\Markdown::hasExtension(string $ext_name)
502 */
503 PHP_METHOD(sundown_markdown, hasExtension)
504 {
505 char *name;
506 int name_len = 0;
507 HashTable *table;
508
509
510 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
511 "s", &name, &name_len) == FAILURE) {
512 return;
513 }
514
515 if (Z_TYPE_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC)) != IS_NULL) {
516 table = Z_ARRVAL_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC));
517 RETVAL_BOOL(php_sundown_has_ext(table, name));
518 }
519 }
913f423 @chobie fix unclosed marker
authored
520 /* }}} */
bc50651 @chobie fixed #9 : check enabled extensions or render flags correctly.
authored
521
e4f9933 @chobie add hasRenderFlag method
authored
522 /* {{{ proto string Sundown\Markdown::hasRenderFlag(string $ext_name)
523 */
524 PHP_METHOD(sundown_markdown, hasRenderFlag)
525 {
526 char *name;
527 int name_len = 0;
528 HashTable *table;
f6a5640 @chobie improve Sundown\Markdown:
authored
529 zval *render_flags,*render = NULL;
e4f9933 @chobie add hasRenderFlag method
authored
530 php_sundown_markdown_t *object = (php_sundown_markdown_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
531
532 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
533 "s", &name, &name_len) == FAILURE) {
534 return;
535 }
536
f6a5640 @chobie improve Sundown\Markdown:
authored
537 if (zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), NULL, "getrender", &render) == FAILURE) {
538 return;
e4f9933 @chobie add hasRenderFlag method
authored
539 }
f6a5640 @chobie improve Sundown\Markdown:
authored
540
541 if (zend_call_method_with_0_params(&render, Z_OBJCE_P(render), NULL, "getrenderflags", &render_flags) == FAILURE) {
542 return;
543 }
544
545 table = Z_ARRVAL_P(render_flags);
546 RETVAL_BOOL(php_sundown_has_ext(table, name));
547 zval_ptr_dtor(&render);
548 zval_ptr_dtor(&render_flags);
e4f9933 @chobie add hasRenderFlag method
authored
549 }
913f423 @chobie fix unclosed marker
authored
550 /* }}} */
e4f9933 @chobie add hasRenderFlag method
authored
551
665039a @chobie now, preprocess and postprocess methods are able to use.
authored
552
862657d @chobie add getExtensions and setExtensions method for Sundown\Markdown
authored
553 /* {{{ proto void string Sundown\Markdown::setExtension(array $extensions)
554 */
555 PHP_METHOD(sundown_markdown, setExtensions)
556 {
683b1d3 @chobie fix memory leaks
authored
557 zval *tmp, *extensions = NULL;
862657d @chobie add getExtensions and setExtensions method for Sundown\Markdown
authored
558
559 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
560 "a", &extensions) == FAILURE) {
561 return;
562 }
563
683b1d3 @chobie fix memory leaks
authored
564 tmp = zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC);
565 zval_ptr_dtor(&tmp);
566
862657d @chobie add getExtensions and setExtensions method for Sundown\Markdown
authored
567 add_property_zval_ex(getThis(),"extensions",sizeof("extensions"),extensions TSRMLS_CC);
568 }
913f423 @chobie fix unclosed marker
authored
569 /* }}} */
862657d @chobie add getExtensions and setExtensions method for Sundown\Markdown
authored
570
571 /* {{{ proto array Sundown\Markdown::getExtensions()
572 */
573 PHP_METHOD(sundown_markdown, getExtensions)
574 {
575 if (Z_TYPE_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC)) != IS_NULL) {
576 zval *result;
577
578 result = zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC);
1261851 @chobie render cause segv when call it three time. #12
authored
579 RETVAL_ZVAL(result, 1, 0);
862657d @chobie add getExtensions and setExtensions method for Sundown\Markdown
authored
580 }
581 }
913f423 @chobie fix unclosed marker
authored
582 /* }}} */
862657d @chobie add getExtensions and setExtensions method for Sundown\Markdown
authored
583
e87c889 @chobie add Sundown\Render\Base::getRenderFlags setRenderFlags and Sundown\Markd...
authored
584 /* {{{ proto Sundown\Render\Base Sundown\Markdown::getRender()
585 */
586 PHP_METHOD(sundown_markdown, getRender)
587 {
588 php_sundown_markdown_t *object = (php_sundown_markdown_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
589 RETVAL_ZVAL(object->render, 1, 0);
590 }
591 /* }}} */
862657d @chobie add getExtensions and setExtensions method for Sundown\Markdown
authored
592
c2e0d3a @chobie for now, adding base render.
authored
593 static zend_function_entry php_sundown_markdown_methods[] = {
594 PHP_ME(sundown_markdown, __construct, arginfo_sundown_markdown__construct, ZEND_ACC_PUBLIC)
595 PHP_ME(sundown_markdown, __destruct, NULL, ZEND_ACC_PUBLIC)
596 PHP_ME(sundown_markdown, render, arginfo_sundown_markdown_render, ZEND_ACC_PUBLIC)
e87c889 @chobie add Sundown\Render\Base::getRenderFlags setRenderFlags and Sundown\Markd...
authored
597 PHP_ME(sundown_markdown, getRender, NULL, ZEND_ACC_PUBLIC)
862657d @chobie add getExtensions and setExtensions method for Sundown\Markdown
authored
598 PHP_ME(sundown_markdown, getExtensions, NULL, ZEND_ACC_PUBLIC)
599 PHP_ME(sundown_markdown, setExtensions, arginfo_sundown_markdown_set_extensions, ZEND_ACC_PUBLIC)
bc50651 @chobie fixed #9 : check enabled extensions or render flags correctly.
authored
600 PHP_ME(sundown_markdown, hasExtension, arginfo_sundown_markdown_has_extension, ZEND_ACC_PUBLIC)
e4f9933 @chobie add hasRenderFlag method
authored
601 PHP_ME(sundown_markdown, hasRenderFlag, arginfo_sundown_markdown_has_render_flag, ZEND_ACC_PUBLIC)
c2e0d3a @chobie for now, adding base render.
authored
602 {NULL,NULL,NULL}
603 };
604
605 void php_sundown_markdown_init(TSRMLS_D)
606 {
607 zend_class_entry ce;
77af627 @chobie modified method comments
authored
608
c2e0d3a @chobie for now, adding base render.
authored
609 INIT_NS_CLASS_ENTRY(ce, "Sundown","Markdown", php_sundown_markdown_methods);
610 sundown_markdown_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
4b10a7e @chobie add Sundown\Buffer class.
authored
611 sundown_markdown_class_entry->create_object = php_sundown_markdown_new;
c2e0d3a @chobie for now, adding base render.
authored
612 zend_declare_property_null(sundown_markdown_class_entry, "extensions", sizeof("extensions")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
613 }
Something went wrong with that request. Please try again.