Skip to content

Commit

Permalink
Updated Sundown files.
Browse files Browse the repository at this point in the history
  • Loading branch information
FSX committed Sep 7, 2011
1 parent 67142ea commit e97de7c
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 499 deletions.
2 changes: 0 additions & 2 deletions docs/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ The functionality of the following constants is explained at *Markdown Extension

The functionality of the following constants is explained at *Render Flags*.


HTML_GITHUB_BLOCKCODE
HTML_SKIP_HTML
HTML_SKIP_STYLE
HTML_HARD_WRAP
Expand Down
7 changes: 3 additions & 4 deletions src/misaka.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@


/* An extra flag to enabled Smartypants */
static const unsigned int HTML_SMARTYPANTS = (1 << 12);
static const unsigned int HTML_SMARTYPANTS = (1 << 9);

/* Only render a table of contents tree */
static const unsigned int HTML_TOC_TREE = (1 << 13);
static const unsigned int HTML_TOC_TREE = (1 << 10);


/* The module doc strings */
Expand Down Expand Up @@ -51,7 +51,7 @@ misaka_html(PyObject *self, PyObject *args, PyObject *kwargs)
}

markdown = sd_markdown_new(extensions, 16, &callbacks, &options);
sd_markdown_render(ob, &ib, markdown);
sd_markdown_render(ob, ib.data, ib.size, markdown);
sd_markdown_free(markdown);

/* Smartypants actions */
Expand Down Expand Up @@ -134,7 +134,6 @@ static PyMethodDef misaka_methods[] = {
PyModule_AddIntConstant(module, "HTML_SAFELINK", HTML_SAFELINK);
PyModule_AddIntConstant(module, "HTML_TOC", HTML_TOC);
PyModule_AddIntConstant(module, "HTML_HARD_WRAP", HTML_HARD_WRAP);
PyModule_AddIntConstant(module, "HTML_GITHUB_BLOCKCODE", HTML_GITHUB_BLOCKCODE);
PyModule_AddIntConstant(module, "HTML_USE_XHTML", HTML_USE_XHTML);

/* Extra HTML render flags - these are not from Sundown */
Expand Down
20 changes: 10 additions & 10 deletions src/sundown/autolink.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <ctype.h>

int
sd_autolink_issafe(const char *link, size_t link_len)
sd_autolink_issafe(const uint8_t *link, size_t link_len)
{
static const size_t valid_uris_count = 4;
static const char *valid_uris[] = {
Expand All @@ -35,7 +35,7 @@ sd_autolink_issafe(const char *link, size_t link_len)
size_t len = strlen(valid_uris[i]);

if (link_len > len &&
strncasecmp(link, valid_uris[i], len) == 0 &&
strncasecmp((char *)link, valid_uris[i], len) == 0 &&
isalnum(link[len]))
return 1;
}
Expand All @@ -44,9 +44,9 @@ sd_autolink_issafe(const char *link, size_t link_len)
}

static size_t
autolink_delim(char *data, size_t link_end, size_t offset, size_t size)
autolink_delim(uint8_t *data, size_t link_end, size_t offset, size_t size)
{
char cclose, copen = 0;
uint8_t cclose, copen = 0;
size_t i;

for (i = 0; i < link_end; ++i)
Expand Down Expand Up @@ -128,7 +128,7 @@ autolink_delim(char *data, size_t link_end, size_t offset, size_t size)
}

static size_t
check_domain(char *data, size_t size)
check_domain(uint8_t *data, size_t size)
{
size_t i, np = 0;

Expand All @@ -147,7 +147,7 @@ check_domain(char *data, size_t size)
}

size_t
sd_autolink__www(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size)
sd_autolink__www(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
{
size_t link_end;

Expand Down Expand Up @@ -177,13 +177,13 @@ sd_autolink__www(size_t *rewind_p, struct buf *link, char *data, size_t offset,
}

size_t
sd_autolink__email(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size)
sd_autolink__email(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
{
size_t link_end, rewind;
int nb = 0, np = 0;

for (rewind = 0; rewind < offset; ++rewind) {
char c = data[-rewind - 1];
uint8_t c = data[-rewind - 1];

if (isalnum(c))
continue;
Expand All @@ -198,7 +198,7 @@ sd_autolink__email(size_t *rewind_p, struct buf *link, char *data, size_t offset
return 0;

for (link_end = 0; link_end < size; ++link_end) {
char c = data[link_end];
uint8_t c = data[link_end];

if (isalnum(c))
continue;
Expand Down Expand Up @@ -226,7 +226,7 @@ sd_autolink__email(size_t *rewind_p, struct buf *link, char *data, size_t offset
}

size_t
sd_autolink__url(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size)
sd_autolink__url(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
{
size_t link_end, rewind = 0, domain_len;

Expand Down
8 changes: 4 additions & 4 deletions src/sundown/autolink.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
#include "buffer.h"

extern int
sd_autolink_issafe(const char *link, size_t link_len);
sd_autolink_issafe(const uint8_t *link, size_t link_len);

extern size_t
sd_autolink__www(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size);
sd_autolink__www(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size);

extern size_t
sd_autolink__email(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size);
sd_autolink__email(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size);

extern size_t
sd_autolink__url(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size);
sd_autolink__url(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size);

#endif

Expand Down
121 changes: 8 additions & 113 deletions src/sundown/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,58 +30,6 @@
# define _buf_vsnprintf vsnprintf
#endif

/* bufcmp: buffer comparison */
int
bufcmp(const struct buf *a, const struct buf *b)
{
size_t i = 0;
size_t cmplen;

if (a == b)
return 0;

if (!a)
return -1;

if (!b)
return 1;

cmplen = (a->size < b->size) ? a->size : b->size;

while (i < cmplen && a->data[i] == b->data[i])
++i;

if (i < a->size) {
if (i < b->size) return a->data[i] - b->data[i];
return 1;
} else {
if (i < b->size) return -1;
return 0;
}
}

/* bufcmps: comparison of a string to a buffer */
int
bufcmps(const struct buf *a, const char *b)
{
const size_t len = strlen(b);
size_t cmplen = len;
int r;

if (!a || !a->size)
return b ? 0 : -1;

if (len < a->size)
cmplen = a->size;

r = strncmp(a->data, b, cmplen);

if (r) return r;
else if (a->size == len) return 0;
else if (a->size < len) return -1;
else return 1;
}

int
bufprefix(const struct buf *buf, const char *prefix)
{
Expand All @@ -98,42 +46,6 @@ bufprefix(const struct buf *buf, const char *prefix)
return 0;
}


/* bufdup: buffer duplication */
struct buf *
bufdup(const struct buf *src, size_t dupunit)
{
size_t blocks;
struct buf *ret;
if (src == 0)
return 0;

ret = malloc(sizeof (struct buf));
if (ret == 0)
return 0;

ret->unit = dupunit;
ret->size = src->size;
ret->ref = 1;
if (!src->size) {
ret->asize = 0;
ret->data = 0;
return ret;
}

blocks = (src->size + dupunit - 1) / dupunit;
ret->asize = blocks * dupunit;
ret->data = malloc(ret->asize);

if (ret->data == 0) {
free(ret);
return 0;
}

memcpy(ret->data, src->data, src->size);
return ret;
}

/* bufgrow: increasing the allocated size to the given value */
int
bufgrow(struct buf *buf, size_t neosz)
Expand Down Expand Up @@ -170,7 +82,6 @@ bufnew(size_t unit)
if (ret) {
ret->data = 0;
ret->size = ret->asize = 0;
ret->ref = 1;
ret->unit = unit;
}
return ret;
Expand All @@ -184,11 +95,11 @@ bufcstr(struct buf *buf)
return NULL;

if (buf->size < buf->asize && buf->data[buf->size] == 0)
return buf->data;
return (char *)buf->data;

if (buf->size + 1 <= buf->asize || bufgrow(buf, buf->size + 1) == 0) {
buf->data[buf->size] = 0;
return buf->data;
return (char *)buf->data;
}

return NULL;
Expand Down Expand Up @@ -229,9 +140,9 @@ bufputs(struct buf *buf, const char *str)
}


/* bufputc: appends a single char to a buffer */
/* bufputc: appends a single uint8_t to a buffer */
void
bufputc(struct buf *buf, char c)
bufputc(struct buf *buf, int c)
{
if (!buf)
return;
Expand All @@ -250,10 +161,8 @@ bufrelease(struct buf *buf)
if (!buf)
return;

if (--buf->ref == 0) {
free(buf->data);
free(buf);
}
free(buf->data);
free(buf);
}


Expand All @@ -269,20 +178,6 @@ bufreset(struct buf *buf)
buf->size = buf->asize = 0;
}


/* bufset: safely assigns a buffer to another */
void
bufset(struct buf **dest, struct buf *src)
{
if (src) {
if (!src->asize) src = bufdup(src, 1);
else src->ref += 1;
}

bufrelease(*dest);
*dest = src;
}

/* bufslurp: removes a given number of bytes from the head of the array */
void
bufslurp(struct buf *buf, size_t len)
Expand All @@ -308,7 +203,7 @@ vbufprintf(struct buf *buf, const char *fmt, va_list ap)
if (buf == 0 || (buf->size >= buf->asize && bufgrow(buf, buf->size + 1)) < 0)
return;

n = _buf_vsnprintf(buf->data + buf->size, buf->asize - buf->size, fmt, ap);
n = _buf_vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap);

if (n < 0) {
#ifdef _MSC_VER
Expand All @@ -322,7 +217,7 @@ vbufprintf(struct buf *buf, const char *fmt, va_list ap)
if (bufgrow(buf, buf->size + n + 1) < 0)
return;

n = _buf_vsnprintf(buf->data + buf->size, buf->asize - buf->size, fmt, ap);
n = _buf_vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap);
}

if (n < 0)
Expand Down
Loading

0 comments on commit e97de7c

Please sign in to comment.