/* {{{ proto string MarkdownDocument::transformFragment(string $markdown_fragment [, int $flags = 0 ]) */ PHP_METHOD(markdowndoc, transformFragment) { char *markdown; int markdown_len; long flags = 0; char *out = NULL; int out_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &markdown, &markdown_len, &flags) == FAILURE) { RETURN_FALSE; } if (markdown_len == 0) { RETURN_EMPTY_STRING(); } out_len = mkd_line(markdown, markdown_len, &out, (mkd_flag_t) flags); if (out_len < 0) { zend_throw_exception(spl_ce_RuntimeException, "Error parsing the fragment", 0 TSRMLS_CC); RETVAL_FALSE; } else { RETVAL_STRINGL(out, out_len, 0); } if (Z_TYPE_P(return_value) == IS_BOOL && out != NULL) { efree(out); } }
/* write out a Cstring, mangled into a form suitable for `<a href=` or `<a id=` */ void mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar, void *out, int labelformat) { unsigned char c; int i, size; char *line; size = mkd_line(s, len, &line, IS_LABEL); if ( labelformat && (size>0) && !isalpha(line[0]) ) (*outchar)('L',out); for ( i=0; i < size ; i++ ) { c = line[i]; if ( labelformat ) { if ( isalnum(c) || (c == '_') || (c == ':') || (c == '-') || (c == '.' ) ) (*outchar)(c, out); else (*outchar)('.', out); } else (*outchar)(c,out); } if (line) free(line); }