summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Mendez <jmendeth@gmail.com>2013-09-21 10:12:28 +0200
committerXavier Mendez <jmendeth@gmail.com>2013-09-21 10:12:28 +0200
commite2cfbdc2e9a7345ea0551c5a22eb6b9706076f71 (patch)
tree1aa6bdc177e42ff4749bac06fd99003dee4603d7
parent9503af51fb0988e0299bbd54554ab4a8f6e4cb99 (diff)
parent2508c4b5c77b9525027f7c44a19b88d9eec971f8 (diff)
downloadrust-hoedown-e2cfbdc2e9a7345ea0551c5a22eb6b9706076f71.tar.gz
Merge latest changes from @devinus into misc-reorganize
-rw-r--r--.editorconfig18
-rw-r--r--.travis.yml9
-rw-r--r--Makefile6
-rw-r--r--Makefile.win1
-rw-r--r--README.md2
-rw-r--r--html_block_names.gperf (renamed from html_block_names.txt)3
-rw-r--r--src/escape.c27
-rw-r--r--src/html_blocks.c (renamed from src/html_blocks.h)137
-rw-r--r--src/markdown.c5
-rwxr-xr-xtest/MarkdownTest_1.0.3/MarkdownTest.pl1
10 files changed, 123 insertions, 86 deletions
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..043fbca
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,18 @@
+# EditorConfig is awesome: http://EditorConfig.org
+
+# top-most EditorConfig file
+root = true
+
+# Unix-style newlines with a newline ending every file
+[*]
+end_of_line = lf
+insert_final_newline = true
+
+# Tab indentation (no size specified)
+[*.{c,h}]
+indent_style = tab
+
+# 4 space indentation
+[*.md]
+indent_style = space
+indent_size = 4
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..27c07a9
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,9 @@
+language: c
+compiler:
+ - clang
+ - gcc
+perl:
+ - "5.12"
+before_install:
+ - sudo apt-get install -qq tidy
+script: make test
diff --git a/Makefile b/Makefile
index 77cf0ab..c430e3f 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,7 @@ HOEDOWN_SRC=\
src/buffer.o \
src/escape.o \
src/html.o \
+ src/html_blocks.o \
src/html_smartypants.o \
src/markdown.o \
src/stack.o
@@ -39,10 +40,9 @@ smartypants: examples/smartypants.o $(HOEDOWN_SRC)
$(CC) $(LDFLAGS) $^ -o $@
# perfect hashing
-html_blocks: src/html_blocks.h
-src/html_blocks.h: html_block_names.txt
- gperf -N hoedown_find_block_tag -H hash_block_tag -C -c -E -S 1 --ignore-case $^ > $@
+src/html_blocks.c: html_block_names.gperf
+ gperf -L ANSI-C -N hoedown_find_block_tag -c -C -E -S 1 --ignore-case -m100 $^ > $@
test: hoedown
perl test/MarkdownTest_1.0.3/MarkdownTest.pl \
diff --git a/Makefile.win b/Makefile.win
index 5c6f7cf..59827bd 100644
--- a/Makefile.win
+++ b/Makefile.win
@@ -7,6 +7,7 @@ HOEDOWN_SRC=\
src\buffer.obj \
src\escape.obj \
src\html.obj \
+ src\html_blocks.obj \
src\html_smartpants.obj \
src\markdown.obj \
src\stack.obj
diff --git a/README.md b/README.md
index 76d1816..aa631f0 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,8 @@
Hoedown
=======
+[![Build Status](https://travis-ci.org/devinus/hoedown.png?branch=master)](https://travis-ci.org/devinus/hoedown)
+
`Hoedown` is a revived fork of [Sundown](https://github.com/vmg/sundown),
the Markdown parser based on the original code of the
[Upskirt library](http://fossil.instinctive.eu/libupskirt/index)
diff --git a/html_block_names.txt b/html_block_names.gperf
index a41d7d1..a316d5c 100644
--- a/html_block_names.txt
+++ b/html_block_names.gperf
@@ -1,4 +1,3 @@
-##
p
dl
h1
@@ -15,11 +14,11 @@ ins
pre
form
math
+style
table
figure
iframe
script
-style
fieldset
noscript
blockquote
diff --git a/src/escape.c b/src/escape.c
index db4541d..3db5b7b 100644
--- a/src/escape.c
+++ b/src/escape.c
@@ -57,7 +57,6 @@ hoedown_escape_href(struct hoedown_buffer *ob, const uint8_t *src, size_t size)
size_t i = 0, org;
char hex_str[3];
- hoedown_buffer_grow(ob, ESCAPE_GROW_FACTOR(size));
hex_str[0] = '%';
while (i < size) {
@@ -65,8 +64,18 @@ hoedown_escape_href(struct hoedown_buffer *ob, const uint8_t *src, size_t size)
while (i < size && HREF_SAFE[src[i]] != 0)
i++;
- if (i > org)
+ if (i > org) {
+ if (org == 0) {
+ if (i >= size) {
+ hoedown_buffer_put(ob, src, size);
+ return;
+ }
+
+ hoedown_buffer_grow(ob, ESCAPE_GROW_FACTOR(size));
+ }
+
hoedown_buffer_put(ob, src + org, i - org);
+ }
/* escaping */
if (i >= size)
@@ -152,15 +161,23 @@ hoedown_escape_html(struct hoedown_buffer *ob, const uint8_t *src, size_t size,
{
size_t i = 0, org, esc = 0;
- hoedown_buffer_grow(ob, ESCAPE_GROW_FACTOR(size));
-
while (i < size) {
org = i;
while (i < size && (esc = HTML_ESCAPE_TABLE[src[i]]) == 0)
i++;
- if (i > org)
+ if (i > org) {
+ if (org == 0) {
+ if (i >= size) {
+ hoedown_buffer_put(ob, src, size);
+ return;
+ }
+
+ hoedown_buffer_grow(ob, ESCAPE_GROW_FACTOR(size));
+ }
+
hoedown_buffer_put(ob, src + org, i - org);
+ }
/* escaping */
if (i >= size)
diff --git a/src/html_blocks.h b/src/html_blocks.c
index 584f3ba..f5e9dce 100644
--- a/src/html_blocks.h
+++ b/src/html_blocks.c
@@ -1,5 +1,5 @@
-/* C code produced by gperf version 3.0.3 */
-/* Command-line: gperf -N hoedown_find_block_tag -H hash_block_tag -C -c -E -P -S 1 --ignore-case html_block_names.txt */
+/* ANSI-C code produced by gperf version 3.0.3 */
+/* Command-line: gperf -L ANSI-C -N hoedown_find_block_tag -c -C -E -S 1 --ignore-case -m100 html_block_names.gperf */
/* Computed positions: -k'1-2' */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
@@ -26,10 +26,10 @@
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
/* The character set is not based on ISO-646. */
-error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
+#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
#endif
-/* maximum key range = 37, duplicates = 0 */
+/* maximum key range = 24, duplicates = 0 */
#ifndef GPERF_DOWNCASE
#define GPERF_DOWNCASE 1
@@ -59,10 +59,7 @@ static unsigned char gperf_downcase[256] =
#ifndef GPERF_CASE_STRNCMP
#define GPERF_CASE_STRNCMP 1
static int
-gperf_case_strncmp (s1, s2, n)
- register const char *s1;
- register const char *s2;
- register unsigned int n;
+gperf_case_strncmp (register const char *s1, register const char *s2, register unsigned int n)
{
for (; n > 0;)
{
@@ -87,38 +84,36 @@ inline
#endif
#endif
static unsigned int
-hash_block_tag (str, len)
- register const char *str;
- register unsigned int len;
+hash (register const char *str, register unsigned int len)
{
static const unsigned char asso_values[] =
{
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 8, 30, 25, 20, 15, 10, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 0, 38, 0, 38,
- 5, 5, 5, 15, 0, 38, 38, 0, 15, 10,
- 0, 38, 38, 15, 0, 5, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 0, 38,
- 0, 38, 5, 5, 5, 15, 0, 38, 38, 0,
- 15, 10, 0, 38, 38, 15, 0, 5, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 22, 21, 19, 18, 16, 0, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 1, 25, 0, 25,
+ 1, 0, 0, 13, 0, 25, 25, 11, 2, 1,
+ 0, 25, 25, 5, 0, 2, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 1, 25,
+ 0, 25, 1, 0, 0, 13, 0, 25, 25, 11,
+ 2, 1, 0, 25, 25, 5, 0, 2, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25
};
register int hval = (int)len;
@@ -141,9 +136,7 @@ __attribute__ ((__gnu_inline__))
#endif
#endif
const char *
-hoedown_find_block_tag (str, len)
- register const char *str;
- register unsigned int len;
+hoedown_find_block_tag (register const char *str, register unsigned int len)
{
enum
{
@@ -151,12 +144,12 @@ hoedown_find_block_tag (str, len)
MIN_WORD_LENGTH = 1,
MAX_WORD_LENGTH = 10,
MIN_HASH_VALUE = 1,
- MAX_HASH_VALUE = 37
+ MAX_HASH_VALUE = 24
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
- register int key = hash_block_tag (str, len);
+ register int key = hash (str, len);
if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
{
@@ -168,74 +161,74 @@ hoedown_find_block_tag (str, len)
resword = "p";
goto compare;
case 1:
- resword = "dl";
+ resword = "h6";
goto compare;
case 2:
resword = "div";
goto compare;
case 3:
- resword = "math";
+ resword = "del";
goto compare;
case 4:
+ resword = "form";
+ goto compare;
+ case 5:
resword = "table";
goto compare;
case 6:
- resword = "ul";
+ resword = "figure";
goto compare;
case 7:
- resword = "del";
+ resword = "pre";
goto compare;
case 8:
- resword = "form";
+ resword = "fieldset";
goto compare;
case 9:
- resword = "blockquote";
+ resword = "noscript";
goto compare;
case 10:
- resword = "figure";
+ resword = "script";
goto compare;
case 11:
- resword = "ol";
+ resword = "style";
goto compare;
case 12:
- resword = "fieldset";
+ resword = "dl";
+ goto compare;
+ case 13:
+ resword = "ol";
goto compare;
case 14:
- resword = "h1";
+ resword = "ul";
+ goto compare;
+ case 15:
+ resword = "math";
goto compare;
case 16:
- resword = "h6";
+ resword = "ins";
goto compare;
case 17:
- resword = "pre";
- goto compare;
- case 20:
- resword = "script";
- goto compare;
- case 21:
resword = "h5";
goto compare;
- case 22:
- resword = "noscript";
- goto compare;
- case 24:
- resword = "style";
- goto compare;
- case 25:
+ case 18:
resword = "iframe";
goto compare;
- case 26:
+ case 19:
resword = "h4";
goto compare;
- case 27:
- resword = "ins";
- goto compare;
- case 31:
+ case 20:
resword = "h3";
goto compare;
- case 36:
+ case 21:
+ resword = "blockquote";
+ goto compare;
+ case 22:
resword = "h2";
goto compare;
+ case 23:
+ resword = "h1";
+ goto compare;
}
return 0;
compare:
diff --git a/src/markdown.c b/src/markdown.c
index 60f4e42..99be8f4 100644
--- a/src/markdown.c
+++ b/src/markdown.c
@@ -20,10 +20,7 @@
#define HOEDOWN_LI_END 8 /* internal list flag */
-#define gperf_case_strncmp(s1, s2, n) strncasecmp(s1, s2, n)
-#define GPERF_DOWNCASE 1
-#define GPERF_CASE_STRNCMP 1
-#include "html_blocks.h"
+const char *hoedown_find_block_tag(const char *str, unsigned int len);
/***************
* LOCAL TYPES *
diff --git a/test/MarkdownTest_1.0.3/MarkdownTest.pl b/test/MarkdownTest_1.0.3/MarkdownTest.pl
index 55553d0..c84685c 100755
--- a/test/MarkdownTest_1.0.3/MarkdownTest.pl
+++ b/test/MarkdownTest_1.0.3/MarkdownTest.pl
@@ -102,6 +102,7 @@ my $time_end = new Benchmark;
my $time_diff = timediff($time_end, $time_start);
print "Benchmark: ", timestr($time_diff), "\n";
+exit 1 if $tests_failed;
__END__