Permalink
Browse files

fix #19 Autolink is broken for emails

[added constants]:
  Sundown\Render\MKDA_NORMAL
  Sundown\Render\MKDA_EMAIL

[changed signature]:
Sundown\Render\Base::autolink(string$link, int $type)

  type should be Sundown\Render\MKDA_NORMAL or Sundown\Render\MKDA_EMAIL
  • Loading branch information...
1 parent 625d52c commit 517619a00676434cccab567b9d4ca5f0124e7b37 @chobie committed May 16, 2012
Showing with 44 additions and 20 deletions.
  1. +3 −1 docs/Render.md
  2. +2 −0 php_sundown.c
  3. +4 −3 render_base.c
  4. +6 −7 render_html.c
  5. +1 −9 sundown_markdown.c
  6. +28 −0 tests/999-regression-no19.phpt
View
@@ -35,7 +35,9 @@ there are two render in php-sundown:
### SundownRenderBase::tableCell(string $content, string $alignment)
-### SundownRenderBase::autolink(string $link, string $link_type)
+### SundownRenderBase::autolink(string $link, long $link_type)
+
+link type should be Sundown\Render\MKDA_EMAIL or Sundown\Render\MKDA_NORMAL.
@stof

stof May 16, 2012

isn't it Sundown\Render::MKDA_EMAIL ?

@chobie

chobie May 16, 2012

Owner

no. there are constant of under Sundown\Render namespace.

@stof

stof May 16, 2012

why not using class constant (probably in the Base render) ? It would be cleaner IMO. I don't know any OOP code using such namespaced constants

@chobie

chobie May 16, 2012

Owner

You are right. namespaced constants seems useless in this case. I tested some codes and I felt its too much.
I'll change these constants in 0.4.0 release. for now, can you use these constants right now?
I'd like to improve another issues (compile warnings, method calling) at first.

well, I'll go to my bed today. good night 😪

@stof

stof May 16, 2012

for now, I don't need them as I don't overwrite the renderer :)

### SundownRenderBase::codespan(string $code)
View
@@ -222,6 +222,8 @@ PHP_MINIT_FUNCTION(sundown) {
REGISTER_NS_STRING_CONSTANT(ZEND_NS_NAME("Sundown","Render"), "HTML", "Sundown\\Render\\HTML", CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME("Sundown","Render"), "LIST_ORDERED", 1, CONST_CS | CONST_PERSISTENT);
+ REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME("Sundown","Render"), "MKDA_EMAIL", MKDA_EMAIL, CONST_CS | CONST_PERSISTENT);
+ REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME("Sundown","Render"), "MKDA_NORMAL", MKDA_NORMAL, CONST_CS | CONST_PERSISTENT);
return SUCCESS;
}
View
@@ -352,12 +352,13 @@ PHP_METHOD(sundown_render_base, tableCell)
*/
PHP_METHOD(sundown_render_base, autolink)
{
- char *link, *link_type;
- int link_len, link_type_len;
+ char *link;
+ int link_len;
+ long link_type;
php_sundown_buffer_t *object;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
- "ss",&link, &link_len, &link_type, &link_type_len) == FAILURE) {
+ "sl",&link, &link_len, &link_type) == FAILURE) {
return;
}
RETVAL_STRINGL(link,link_len,1);
View
@@ -458,23 +458,22 @@ PHP_METHOD(sundown_render_html, tableCell)
*/
PHP_METHOD(sundown_render_html, autolink)
{
- char *link, *link_type;
- int link_len, link_type_len;
+ char *link;
+ int link_len = 0;
+ long link_type;
struct buf *m_link, *output;
php_sundown_buffer_t *object;
- /* @Todo: map types. */
- enum mkd_autolink type = MKDA_NORMAL;
php_sundown_render_html_t *html;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
- "ss", &link, &link_len, &link_type, &link_type_len) == FAILURE) {
+ "sl", &link, &link_len, &link_type) == FAILURE) {
return;
}
-
+
m_link = str2buf(link, link_len);
output = bufnew(128);
html = (php_sundown_render_html_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
- html->cb.autolink(output,m_link,type, &html->html);
+ html->cb.autolink(output,m_link,link_type, &html->html);
bufrelease(m_link);
RETVAL_STRINGL(output->data, output->size,1);
bufrelease(output);
View
@@ -109,15 +109,7 @@ static void rndr_tablecell(struct buf *ob, const struct buf *text, int align, vo
*/
static int rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque)
{
- zval *m_type;
-
- MAKE_STD_ZVAL(m_type);
- if (type == MKDA_NORMAL) {
- ZVAL_STRING(m_type, "url",1);
- } else {
- ZVAL_STRING(m_type, "email",1);
- }
- SPAN_CALLBACK_EX(ob,"autolink", 2,buf2str(link),m_type);
+ SPAN_CALLBACK_EX(ob,"autolink", 2,buf2str(link),buf2long(type));
}
static int rndr_codespan(struct buf *ob, const struct buf *text, void *opaque)
@@ -0,0 +1,28 @@
+--TEST--
+Check for https://github.com/chobie/php-sundown/issues/19
+--SKIPIF--
+<?php if (!extension_loaded("sundown")) print "skip"; ?>
+--FILE--
+<?php
+//https://github.com/chobie/php-sundown/issues/19
+$sundown = new Sundown\Markdown(
+ new Sundown\Render\HTML(array('hard_wrap' => true)),
+ array(
+ 'no_intra_emphasis' =>true,
+ 'tables' => true,
+ 'fenced_code_blocks' => true,
+ 'autolink' => true,
+ 'strikethrough' => true,
+ 'lax_html_blocks' => true,
+ )
+);
+
+echo $sundown->render(
+ <<<MARKDOWN
+http://foo.bar/
+test@example.com
+MARKDOWN
+);
+--EXPECT--
+<p><a href="http://foo.bar/">http://foo.bar/</a><br>
+<a href="mailto:test@example.com">test@example.com</a></p>

0 comments on commit 517619a

Please sign in to comment.