Skip to content

HTTPS clone URL

Subversion checkout URL

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