Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 517619a00676434cccab567b9d4ca5f0124e7b37 1 parent 625d52c
@chobie authored
View
4 docs/Render.md
@@ -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 added a note

isn't it Sundown\Render::MKDA_EMAIL ?

@chobie Owner
chobie added a note

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

@stof
stof added a note

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 Owner
chobie added a note

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 :sleepy:

@stof
stof added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
### SundownRenderBase::codespan(string $code)
View
2  php_sundown.c
@@ -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
7 render_base.c
@@ -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
13 render_html.c
@@ -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
10 sundown_markdown.c
@@ -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)
View
28 tests/999-regression-no19.phpt
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.