Skip to content

Commit

Permalink
Clean up whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
spladug committed Oct 9, 2012
1 parent b9168b0 commit ccb1308
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 80 deletions.
36 changes: 18 additions & 18 deletions html/houdini_href_e.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* We asume (lazily) that any RESERVED char that
* appears inside an URL is actually meant to
* have its native function (i.e. as an URL
* have its native function (i.e. as an URL
* component/separator) and hence needs no escaping.
*
* There are two exceptions: the chacters & (amp)
Expand All @@ -32,21 +32,21 @@
*
*/
static const char HREF_SAFE[] = {
2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 2, 2, 0, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 2, 2, 0, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};

Expand Down Expand Up @@ -81,7 +81,7 @@ houdini_escape_href(struct buf *ob, const uint8_t *src, size_t size)
switch (src[i]) {
/* amp appears all the time in URLs, but needs
* HTML-entity escaping to be inside an href */
case '&':
case '&':
BUFPUTSL(ob, "&");
break;

Expand All @@ -91,7 +91,7 @@ houdini_escape_href(struct buf *ob, const uint8_t *src, size_t size)
case '\'':
BUFPUTSL(ob, "'");
break;

/* the space can be escaped to %20 or a plus
* sign. we're going with the generic escape
* for now. the plus thing is more commonly seen
Expand Down
26 changes: 13 additions & 13 deletions html/houdini_html_e.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
*
*/
static const char HTML_ESCAPE_TABLE[] = {
7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 7, 7, 0, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 4,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 7, 7, 0, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 4,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};

Expand Down
43 changes: 21 additions & 22 deletions html/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,24 +394,24 @@ rndr_html_tag(struct buf *ob, const struct buf *text, void *opaque,
size_t i, x, z, in_str = 0, seen_equals = 0, done, reset;
struct buf *attr = bufnew(16);
char c;

bufputc(ob, '<');

i = 1 + strlen(tagname);

if(tagtype == HTML_TAG_CLOSE) {
bufputc(ob, '/');
i += 1;
}

bufputs(ob, tagname);

if(tagtype != HTML_TAG_CLOSE) {
for(;i < text->size;i++) {
c = text->data[i];
done = 0;
reset = 0;

switch(c) {
case '>':
if(seen_equals && !in_str) {
Expand Down Expand Up @@ -459,12 +459,12 @@ rndr_html_tag(struct buf *ob, const struct buf *text, void *opaque,
}
}
}

if(done) {
bufputc(ob, ' ');
bufput(ob, attr->data, attr->size);
}

if(reset) {
seen_equals = 0;
in_str = 0;
Expand All @@ -474,11 +474,11 @@ rndr_html_tag(struct buf *ob, const struct buf *text, void *opaque,
}
}
}

bufrelease(attr);

bufputc(ob, '>');

}

static int
Expand All @@ -487,17 +487,16 @@ rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque)
struct html_renderopt *options = opaque;
char** whitelist = options->html_element_whitelist;
int i, tagtype;



/* Items on the whitelist ignore all other flags and just output */
if (((options->flags & HTML_ALLOW_ELEMENT_WHITELIST) != 0) && whitelist) {
for(i = 0; whitelist[i]; i++) {
for (i = 0; whitelist[i]; i++) {
tagtype = sdhtml_is_tag(text->data, text->size, whitelist[i]);
if(tagtype != HTML_TAG_NONE) {
if (tagtype != HTML_TAG_NONE) {
rndr_html_tag(ob, text, opaque,
whitelist[i],
options->html_attr_whitelist,
tagtype);
whitelist[i],
options->html_attr_whitelist,
tagtype);
return 1;
}
}
Expand Down Expand Up @@ -633,11 +632,11 @@ toc_header(struct buf *ob, const struct buf *text, int level, void *opaque)
}

bufprintf(ob, "<a href=\"#");

if (options->toc_id_prefix) {
bufprintf(ob, options->toc_id_prefix);
}

bufprintf(ob, "toc_%d\">", options->toc_data.header_count++);
if (text)
escape_html(ob, text->data, text->size);
Expand All @@ -656,7 +655,7 @@ static void
reset_toc(struct buf *ob, void *opaque)
{
struct html_renderopt *options = opaque;

memset(&(options->toc_data), 0, sizeof(options->toc_data));
}

Expand All @@ -669,7 +668,7 @@ toc_finalize(struct buf *ob, void *opaque)
BUFPUTSL(ob, "</li>\n</ul>\n");
options->toc_data.current_level--;
}

reset_toc(ob, opaque);
}

Expand Down
2 changes: 1 addition & 1 deletion html/html.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct html_renderopt {
char* toc_id_prefix;

unsigned int flags;

char** html_element_whitelist;
char** html_attr_whitelist;

Expand Down
2 changes: 1 addition & 1 deletion html/html_smartypants.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <ctype.h>

#if defined(_WIN32)
#define snprintf _snprintf
#define snprintf _snprintf
#endif

struct smartypants_data {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def c_files_in(directory):
test_suite="test_snudown.test_snudown",
ext_modules=[
Extension(
name='snudown',
name='snudown',
sources=['snudown.c'] + c_files_in('src/') + c_files_in('html/'),
include_dirs=['src', 'html']
)
Expand Down
38 changes: 19 additions & 19 deletions snudown.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct module_state {

static struct snudown_renderer sundown[RENDERER_COUNT];

static char* html_element_whitelist[] = { "tr", "th", "td", "table", "tbody", "thead", "tfoot", "caption", NULL };
static char* html_element_whitelist[] = {"tr", "th", "td", "table", "tbody", "thead", "tfoot", "caption", NULL};
static char* html_attr_whitelist[] = {"colspan", "rowspan", "cellspacing", "cellpadding", "scope", NULL};

static struct module_state usertext_toc_state;
Expand All @@ -52,14 +52,14 @@ static const unsigned int snudown_default_md_flags =
MKDEXT_STRIKETHROUGH |
MKDEXT_TABLES;

static const unsigned int snudown_default_render_flags =
static const unsigned int snudown_default_render_flags =
HTML_SKIP_HTML |
HTML_SKIP_IMAGES |
HTML_SAFELINK |
HTML_ESCAPE |
HTML_USE_XHTML;

static const unsigned int snudown_wiki_render_flags =
static const unsigned int snudown_wiki_render_flags =
HTML_SKIP_HTML |
HTML_SAFELINK |
HTML_ALLOW_ELEMENT_WHITELIST |
Expand Down Expand Up @@ -93,11 +93,11 @@ static struct sd_markdown* custom_render(struct module_state* state,
(struct html_renderopt *)&state->options,
renderflags);
}

state->options.html.link_attributes = &snudown_link_attr;
state->options.html.html_element_whitelist = html_element_whitelist;
state->options.html.html_attr_whitelist = html_attr_whitelist;

return sd_markdown_new(
markdownflags,
16,
Expand Down Expand Up @@ -146,39 +146,39 @@ snudown_md(PyObject *self, PyObject *args, PyObject *kwargs)
&target, &toc_id_prefix, &renderer, &enable_toc)) {
return NULL;
}
if(renderer < 0 || renderer >= RENDERER_COUNT) {

if (renderer < 0 || renderer >= RENDERER_COUNT) {
PyErr_SetString(PyExc_ValueError, "Invalid renderer");
return NULL;
}

_snudown = sundown[renderer];

struct snudown_renderopt *options = &(_snudown.state->options);
options->nofollow = nofollow;
options->target = target;

/* Output buffer */
ob = bufnew(128);

flags = options->html.flags;

if (enable_toc) {
_snudown.toc_state->options.html.toc_id_prefix = toc_id_prefix;
sd_markdown_render(ob, ib.data, ib.size, _snudown.toc_renderer);
_snudown.toc_state->options.html.toc_id_prefix = NULL;

options->html.flags |= HTML_TOC;
}

options->html.toc_id_prefix = toc_id_prefix;

/* do the magic */
sd_markdown_render(ob, ib.data, ib.size, _snudown.main_renderer);

options->html.toc_id_prefix = NULL;
options->html.flags = flags;

/* make a Python string */
result_text = "";
if (ob->data)
Expand All @@ -202,10 +202,10 @@ PyMODINIT_FUNC initsnudown(void)
module = Py_InitModule3("snudown", snudown_methods, snudown_module__doc__);
if (module == NULL)
return;

init_default_render(module);
init_wiki_render(module);

/* Version */
PyModule_AddStringConstant(module, "__version__", SNUDOWN_VERSION);
}
4 changes: 2 additions & 2 deletions src/markdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -1459,12 +1459,12 @@ parse_paragraph(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t

while (i < size) {
for (end = i + 1; end < size && data[end - 1] != '\n'; end++) /* empty */;

if (prefix_quote(data + i, end - i) != 0) {
end = i;
break;
}

if (is_empty(data + i, size - i))
break;

Expand Down
6 changes: 3 additions & 3 deletions test_snudown.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

'Words words /r/test words':
'<p>Words words <a href="/r/test">/r/test</a> words</p>\n',

'/r/':
'<p>/r/</p>\n',

Expand Down Expand Up @@ -141,10 +141,10 @@ def runTest(self):
repr(output))):
if a != b:
io = StringIO.StringIO()
print >> io, "TEST FAILED:"
print >> io, "TEST FAILED:"
print >> io, " input: %s" % repr(self.input)
print >> io, " expected: %s" % repr(self.expected_output)
print >> io, " actual: %s" % repr(output)
print >> io, " actual: %s" % repr(output)
print >> io, " %s" % (' ' * i + '^')
self.fail(io.getvalue())

Expand Down

0 comments on commit ccb1308

Please sign in to comment.