Skip to content

Commit

Permalink
use Cython>=0.28 and hoedown3.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Oct 11, 2018
1 parent ec917bd commit 4f093c2
Show file tree
Hide file tree
Showing 5 changed files with 3,477 additions and 587 deletions.
72 changes: 59 additions & 13 deletions hoedownpy/_hoedown/src/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static size_t char_autolink_url(hoedown_buffer *ob, hoedown_document *doc, uint8
static size_t char_autolink_email(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
static size_t char_autolink_www(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
static size_t char_link(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
static size_t char_image(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
static size_t char_superscript(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
static size_t char_math(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);

Expand All @@ -86,6 +87,7 @@ enum markdown_char_t {
MD_CHAR_CODESPAN,
MD_CHAR_LINEBREAK,
MD_CHAR_LINK,
MD_CHAR_IMAGE,
MD_CHAR_LANGLE,
MD_CHAR_ESCAPE,
MD_CHAR_ENTITY,
Expand All @@ -103,6 +105,7 @@ static char_trigger markdown_char_ptrs[] = {
&char_codespan,
&char_linebreak,
&char_link,
&char_image,
&char_langle_tag,
&char_escape,
&char_entity,
Expand Down Expand Up @@ -402,9 +405,23 @@ tag_length(uint8_t *data, size_t size, hoedown_autolink_type *autolink)
/* a valid tag can't be shorter than 3 chars */
if (size < 3) return 0;

/* begins with a '<' optionally followed by '/', followed by letter or number */
if (data[0] != '<') return 0;
i = (data[1] == '/') ? 2 : 1;

/* HTML comment, laxist form */
if (size > 5 && data[1] == '!' && data[2] == '-' && data[3] == '-') {
i = 5;

while (i < size && !(data[i - 2] == '-' && data[i - 1] == '-' && data[i] == '>'))
i++;

i++;

if (i <= size)
return i;
}

/* begins with a '<' optionally followed by '/', followed by letter or number */
i = (data[1] == '/') ? 2 : 1;

if (!isalnum(data[i]))
return 0;
Expand Down Expand Up @@ -549,7 +566,7 @@ find_emph_char(uint8_t *data, size_t size, uint8_t c)
}

/* not a well-formed codespan; use found matching emph char */
if (i >= size) return tmp_i;
if (bt < span_nb && i >= size) return tmp_i;
}
/* skipping a link */
else if (data[i] == '[') {
Expand Down Expand Up @@ -928,7 +945,12 @@ char_escape(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t off
}
else hoedown_buffer_putc(ob, data[1]);
} else if (size == 1) {
hoedown_buffer_putc(ob, data[0]);
if (doc->md.normal_text) {
work.data = data;
work.size = 1;
doc->md.normal_text(ob, &work, &doc->data);
}
else hoedown_buffer_putc(ob, data[0]);
}

return 2;
Expand Down Expand Up @@ -1008,7 +1030,11 @@ char_autolink_www(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size
HOEDOWN_BUFPUTSL(link_url, "http://");
hoedown_buffer_put(link_url, link->data, link->size);

ob->size -= rewind;
if (ob->size > rewind)
ob->size -= rewind;
else
ob->size = 0;

if (doc->md.normal_text) {
link_text = newbuf(doc, BUFFER_SPAN);
doc->md.normal_text(link_text, link, &doc->data);
Expand Down Expand Up @@ -1036,7 +1062,11 @@ char_autolink_email(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, si
link = newbuf(doc, BUFFER_SPAN);

if ((link_len = hoedown_autolink__email(&rewind, link, data, offset, size, 0)) > 0) {
ob->size -= rewind;
if (ob->size > rewind)
ob->size -= rewind;
else
ob->size = 0;

doc->md.autolink(ob, link, HOEDOWN_AUTOLINK_EMAIL, &doc->data);
}

Expand All @@ -1056,14 +1086,29 @@ char_autolink_url(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size
link = newbuf(doc, BUFFER_SPAN);

if ((link_len = hoedown_autolink__url(&rewind, link, data, offset, size, 0)) > 0) {
ob->size -= rewind;
if (ob->size > rewind)
ob->size -= rewind;
else
ob->size = 0;

doc->md.autolink(ob, link, HOEDOWN_AUTOLINK_NORMAL, &doc->data);
}

popbuf(doc, BUFFER_SPAN);
return link_len;
}

static size_t
char_image(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size) {
size_t ret;

if (size < 2 || data[1] != '[') return 0;

ret = char_link(ob, doc, data + 1, offset + 1, size - 1);
if (!ret) return 0;
return ret + 1;
}

/* char_link • '[': parsing a link, a footnote or an image */
static size_t
char_link(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
Expand Down Expand Up @@ -1187,8 +1232,10 @@ char_link(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offse
link_e--;

/* remove optional angle brackets around the link */
if (data[link_b] == '<') link_b++;
if (data[link_e - 1] == '>') link_e--;
if (data[link_b] == '<' && data[link_e - 1] == '>') {
link_b++;
link_e--;
}

/* building escaped link and title */
if (link_e > link_b) {
Expand Down Expand Up @@ -1274,9 +1321,6 @@ char_link(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offse

/* calling the relevant rendering function */
if (is_img) {
if (ob->size && ob->data[ob->size - 1] == '!')
ob->size -= 1;

ret = doc->md.image(ob, u_link, title, content, &doc->data);
} else {
ret = doc->md.link(ob, content, u_link, title, &doc->data);
Expand Down Expand Up @@ -2779,8 +2823,10 @@ hoedown_document_new(
if (doc->md.linebreak)
doc->active_char['\n'] = MD_CHAR_LINEBREAK;

if (doc->md.image || doc->md.link || doc->md.footnotes || doc->md.footnote_ref)
if (doc->md.image || doc->md.link || doc->md.footnotes || doc->md.footnote_ref) {
doc->active_char['['] = MD_CHAR_LINK;
doc->active_char['!'] = MD_CHAR_IMAGE;
}

doc->active_char['<'] = MD_CHAR_LANGLE;
doc->active_char['\\'] = MD_CHAR_ESCAPE;
Expand Down
2 changes: 1 addition & 1 deletion hoedownpy/_hoedown/src/html_smartypants.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ smartypants_cb__ltag(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t
size_t tag, i = 0;

/* This is a comment. Copy everything verbatim until --> or EOF is seen. */
if (i + 4 < size && memcmp(text, "<!--", 4) == 0) {
if (i + 4 < size && memcmp(text + i, "<!--", 4) == 0) {
i += 4;
while (i + 3 < size && memcmp(text + i, "-->", 3) != 0)
i++;
Expand Down
4 changes: 2 additions & 2 deletions hoedownpy/_hoedown/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ extern "C" {
* CONSTANTS *
*************/

#define HOEDOWN_VERSION "3.0.3"
#define HOEDOWN_VERSION "3.0.7"
#define HOEDOWN_VERSION_MAJOR 3
#define HOEDOWN_VERSION_MINOR 0
#define HOEDOWN_VERSION_REVISION 3
#define HOEDOWN_VERSION_REVISION 7


/*************
Expand Down

0 comments on commit 4f093c2

Please sign in to comment.