Skip to content
This repository was archived by the owner on Oct 9, 2018. It is now read-only.

Update hoedown for math improvements #2

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a6b90a7
Import improvements from Lanli (and more things)
mildsunrise Sep 2, 2014
73d8a11
More fixes
mildsunrise Sep 3, 2014
a715656
Add __builtin_expect fallback for MSVC
mildsunrise Sep 3, 2014
821b349
Keep up to date with master
mildsunrise Sep 4, 2014
30dd50f
Keep code without warnings
mildsunrise Sep 4, 2014
8cc788e
New Python implemented test script
uranusjr Sep 9, 2014
b49d385
Add math test (modified) and tweak runner
uranusjr Sep 9, 2014
8c14212
Use memcmp in hoedown_buffer_eq(...)
mildsunrise Sep 9, 2014
95ab7bb
Enable escape character test
uranusjr Sep 9, 2014
6510aa4
Use difflib to make error friendly
uranusjr Sep 9, 2014
9a2166d
Cleanup
uranusjr Sep 9, 2014
855bc34
Make test script Python 3-compatible
uranusjr Sep 9, 2014
9a0c20d
Add "fail" flag for expected failure
uranusjr Sep 9, 2014
00a5b7a
Cleanup
uranusjr Sep 9, 2014
b92c454
Merge pull request #116 from jmendeth/lanli-import
Sep 13, 2014
d20dd8e
Merge pull request #122 from uranusjr/unittest
Sep 13, 2014
d0759dd
Include strings.h to silence warnings for strncasecmp
fhahn Sep 13, 2014
27e9e03
Merge pull request #123 from fhahn/silence-implicit-delc-warning
Sep 13, 2014
5215172
Don't require spacing around math spans (fix #120)
mildsunrise Sep 14, 2014
5c6ef74
Modify tests accordingly
mildsunrise Sep 14, 2014
8d7bb2e
Merge pull request #125 from jmendeth/lift-math-restrictions
Sep 19, 2014
108ee1a
Remove HTML_SAFELINK and EXT_LAX_SPACING
mildsunrise Sep 19, 2014
ebb1a34
Merge pull request #129 from jmendeth/remove-flags
Sep 19, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CFLAGS = -g -O3 -Wall -Wextra -Wno-unused-parameter -Isrc
CFLAGS = -g -O3 -Wall -Wextra -Wno-unused-parameter -Isrc -std=c99

ifneq ($(OS),Windows_NT)
CFLAGS += -fPIC
Expand Down Expand Up @@ -46,7 +46,7 @@ src/html_blocks.c: html_block_names.gperf
# Testing

test: hoedown
test/runner.sh ./hoedown test/MarkdownTest_1.0.3/Tests
python test/runner.py

test-pl: hoedown
perl test/MarkdownTest_1.0.3/MarkdownTest.pl \
Expand Down
32 changes: 3 additions & 29 deletions bin/hoedown.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ static struct extension_info extensions_info[] = {
{HOEDOWN_EXT_SUPERSCRIPT, "superscript", "Parse super^script."},
{HOEDOWN_EXT_MATH, "math", "Parse TeX $$math$$ syntax, Kramdown style."},

{HOEDOWN_EXT_LAX_SPACING, "lax-spacing", "Don't require a blank line between some blocks."},
{HOEDOWN_EXT_NO_INTRA_EMPHASIS, "disable-intra-emphasis", "Disable emphasis_between_words."},
{HOEDOWN_EXT_SPACE_HEADERS, "space-headers", "Require a space after '#' in headers."},
{HOEDOWN_EXT_MATH_EXPLICIT, "math-explicit", "Instead of guessing by context, parse $inline math$ and $$always block math$$ (requires --math)."},
Expand All @@ -77,7 +76,6 @@ static struct extension_info extensions_info[] = {
static struct html_flag_info html_flags_info[] = {
{HOEDOWN_HTML_SKIP_HTML, "skip-html", "Strip all HTML tags."},
{HOEDOWN_HTML_ESCAPE, "escape", "Escape all HTML."},
{HOEDOWN_HTML_SAFELINK, "safelink", "Only allow links to safe protocols."},
{HOEDOWN_HTML_HARD_WRAP, "hard-wrap", "Render each linebreak as <br>."},
{HOEDOWN_HTML_USE_XHTML, "xhtml", "Render XHTML."},
};
Expand Down Expand Up @@ -401,20 +399,13 @@ main(int argc, char **argv)

/* reading everything */
ib = hoedown_buffer_new(iunit);
if (!ib) {
fprintf(stderr, "Couldn't allocate input buffer.\n");
return 4;
}

while (!feof(in)) {
if (ferror(in)) {
fprintf(stderr, "I/O errors found while reading input.\n");
return 5;
}
if (hoedown_buffer_grow(ib, ib->size + iunit) != HOEDOWN_BUF_OK) {
fprintf(stderr, "Couldn't grow input buffer.\n");
return 4;
}
hoedown_buffer_grow(ib, ib->size + iunit);
ib->size += fread(ib->data + ib->size, 1, iunit, in);
}

Expand All @@ -423,8 +414,8 @@ main(int argc, char **argv)


/* creating the renderer */
hoedown_renderer *renderer;
void (*renderer_free)(hoedown_renderer*);
hoedown_renderer *renderer = NULL;
void (*renderer_free)(hoedown_renderer*) = NULL;

switch (renderer_type) {
case RENDERER_HTML:
Expand All @@ -439,29 +430,12 @@ main(int argc, char **argv)
renderer = null_renderer_new();
renderer_free = null_renderer_free;
break;
default:
renderer = NULL;
renderer_free = NULL;
};

if (!renderer) {
fprintf(stderr, "Couldn't allocate renderer.\n");
return 4;
}


/* performing markdown rendering */
ob = hoedown_buffer_new(ounit);
if (!ob) {
fprintf(stderr, "Couldn't allocate output buffer.\n");
return 4;
}

document = hoedown_document_new(renderer, extensions, max_nesting);
if (!document) {
fprintf(stderr, "Couldn't allocate document parser.\n");
return 4;
}

//clock_gettime(CLOCK_MONOTONIC, &start);
hoedown_document_render(document, ob, ib->data, ib->size);
Expand Down
13 changes: 1 addition & 12 deletions bin/smartypants.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,13 @@ main(int argc, char **argv)

/* reading everything */
ib = hoedown_buffer_new(iunit);
if (!ib) {
fprintf(stderr, "Couldn't allocate input buffer.\n");
return 4;
}

while (!feof(in)) {
if (ferror(in)) {
fprintf(stderr, "I/O errors found while reading input.\n");
return 5;
}
if (hoedown_buffer_grow(ib, ib->size + iunit) != HOEDOWN_BUF_OK) {
fprintf(stderr, "Couldn't grow input buffer.\n");
return 4;
}
hoedown_buffer_grow(ib, ib->size + iunit);
ib->size += fread(ib->data + ib->size, 1, iunit, in);
}

Expand All @@ -206,10 +199,6 @@ main(int argc, char **argv)

/* performing SmartyPants processing */
ob = hoedown_buffer_new(ounit);
if (!ob) {
fprintf(stderr, "Couldn't allocate output buffer.\n");
return 4;
}

//clock_gettime(CLOCK_MONOTONIC, &start);
hoedown_html_smartypants(ob, ib->data, ib->size);
Expand Down
24 changes: 15 additions & 9 deletions hoedown.def
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,36 @@ EXPORTS
hoedown_autolink__www
hoedown_autolink__email
hoedown_autolink__url
hoedown_buffer_grow
hoedown_buffer_init
hoedown_buffer_new
hoedown_buffer_cstr
hoedown_buffer_prefix
hoedown_buffer_reset
hoedown_buffer_grow
hoedown_buffer_put
hoedown_buffer_puts
hoedown_buffer_putc
hoedown_buffer_free
hoedown_buffer_reset
hoedown_buffer_set
hoedown_buffer_sets
hoedown_buffer_eq
hoedown_buffer_eqs
hoedown_buffer_prefix
hoedown_buffer_slurp
hoedown_buffer_cstr
hoedown_buffer_printf
hoedown_buffer_free
hoedown_document_new
hoedown_document_render
hoedown_document_render_inline
hoedown_document_free
hoedown_escape_html
hoedown_escape_href
hoedown_escape_html
hoedown_html_smartypants
hoedown_html_is_tag
hoedown_html_renderer_new
hoedown_html_toc_renderer_new
hoedown_html_renderer_free
hoedown_html_smartypants
hoedown_stack_free
hoedown_stack_init
hoedown_stack_uninit
hoedown_stack_grow
hoedown_stack_new
hoedown_stack_push
hoedown_stack_pop
hoedown_stack_top
Expand Down
21 changes: 11 additions & 10 deletions src/autolink.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
#include <stdio.h>
#include <ctype.h>

#ifdef _MSC_VER
#ifndef _MSC_VER
#include <strings.h>
#else
#define strncasecmp _strnicmp
#endif

int
hoedown_autolink_is_safe(const uint8_t *link, size_t link_len)
hoedown_autolink_is_safe(const uint8_t *data, size_t size)
{
static const size_t valid_uris_count = 6;
static const char *valid_uris[] = {
"#", "/", "http://", "https://", "ftp://", "mailto:"
"http://", "https://", "/", "#", "ftp://", "mailto:"
};
static const size_t valid_uris_size[] = { 7, 8, 1, 1, 6, 7 };

size_t i;

for (i = 0; i < valid_uris_count; ++i) {
size_t len = strlen(valid_uris[i]);
for (size_t i = 0; i < valid_uris_count; ++i) {
size_t len = valid_uris_size[i];

if (link_len > len &&
strncasecmp((char *)link, valid_uris[i], len) == 0 &&
isalnum(link[len]))
if (size > len &&
strncasecmp((char *)data, valid_uris[i], len) == 0 &&
isalnum(data[len]))
return 1;
}

Expand Down
37 changes: 24 additions & 13 deletions src/autolink.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,35 @@
extern "C" {
#endif

enum {

/*************
* CONSTANTS *
*************/

typedef enum hoedown_autolink_flags {
HOEDOWN_AUTOLINK_SHORT_DOMAINS = (1 << 0)
};
} hoedown_autolink_flags;


/*************
* FUNCTIONS *
*************/

/* hoedown_autolink_is_safe: verify that a URL has a safe protocol */
int hoedown_autolink_is_safe(const uint8_t *data, size_t size);

int
hoedown_autolink_is_safe(const uint8_t *link, size_t link_len);
/* hoedown_autolink__www: search for the next www link in data */
size_t hoedown_autolink__www(size_t *rewind_p, hoedown_buffer *link,
uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags);

size_t
hoedown_autolink__www(size_t *rewind_p, hoedown_buffer *link,
uint8_t *data, size_t offset, size_t size, unsigned int flags);
/* hoedown_autolink__email: search for the next email in data */
size_t hoedown_autolink__email(size_t *rewind_p, hoedown_buffer *link,
uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags);

size_t
hoedown_autolink__email(size_t *rewind_p, hoedown_buffer *link,
uint8_t *data, size_t offset, size_t size, unsigned int flags);
/* hoedown_autolink__url: search for the next URL in data */
size_t hoedown_autolink__url(size_t *rewind_p, hoedown_buffer *link,
uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags);

size_t
hoedown_autolink__url(size_t *rewind_p, hoedown_buffer *link,
uint8_t *data, size_t offset, size_t size, unsigned int flags);

#ifdef __cplusplus
}
Expand Down
Loading