diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-03-05 19:35:16 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-03-05 19:35:16 +0100 |
commit | 2bfe68f6f9fdd34588b8dde73c1a4e96c5a54b7d (patch) | |
tree | 20ae4f90da8c3397161a6d137b953a378022df6f | |
parent | f7034a9c4e26933bceb9b80c6ef492b731df3d73 (diff) | |
download | blogc-2bfe68f6f9fdd34588b8dde73c1a4e96c5a54b7d.tar.gz blogc-2bfe68f6f9fdd34588b8dde73c1a4e96c5a54b7d.tar.bz2 blogc-2bfe68f6f9fdd34588b8dde73c1a4e96c5a54b7d.zip |
content-parser: convert -- and --- to &ndash and &mdash
-rw-r--r-- | src/content-parser.c | 15 | ||||
-rw-r--r-- | tests/check_content_parser.c | 32 |
2 files changed, 41 insertions, 6 deletions
diff --git a/src/content-parser.c b/src/content-parser.c index 7e2310f..f5e3aec 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -361,6 +361,21 @@ blogc_content_parse_inline(const char *src) } break; + case '-': + if (state != LINK_CLOSED) + break; + if (current < (src_len - 1) && src[current + 1] == '-') { + if (current < (src_len - 2) && src[current + 2] == '-') { + sb_string_append(rv, "–"); + current += 2; + } + else { + sb_string_append(rv, "—"); + current += 1; + } + } + break; + case '&': if (state == LINK_CLOSED) sb_string_append(rv, "&"); diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 03f2213..bc21317 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -106,8 +106,8 @@ test_content_parse(void **state) "1. chunda\n" "3. fuuuu\n" "\n" - "+ chunda2\n" - "+ fuuuu2\n" + "- chunda2\n" + "- fuuuu2\n" "\n" "<style>\n" " chunda\n" @@ -116,7 +116,13 @@ test_content_parse(void **state) "guda\n" "yay\n" "\n" - "**bola**\n", &l); + "**bola**\n" + "-- foo\n" + "--- bar\n" + "\n" + "-- asd\n" + "\n" + "--- lol\n", &l); assert_non_null(html); assert_int_equal(l, 0); assert_string_equal(html, @@ -150,7 +156,11 @@ test_content_parse(void **state) "</style>\n" "<p>guda\n" "yay</p>\n" - "<p><strong>bola</strong></p>\n"); + "<p><strong>bola</strong>\n" + "— foo\n" + "– bar</p>\n" + "<p>— asd</p>\n" + "<p>– lol</p>\n"); free(html); } @@ -194,7 +204,13 @@ test_content_parse_crlf(void **state) "guda\r\n" "yay\r\n" "\r\n" - "**bola**\r\n", &l); + "**bola**\r\n" + "-- foo\r\n" + "--- bar\r\n" + "\r\n" + "-- asd\r\n" + "\r\n" + "--- lol\r\n", &l); assert_non_null(html); assert_int_equal(l, 0); assert_string_equal(html, @@ -228,7 +244,11 @@ test_content_parse_crlf(void **state) "</style>\r\n" "<p>guda\r\n" "yay</p>\r\n" - "<p><strong>bola</strong></p>\r\n"); + "<p><strong>bola</strong>\r\n" + "— foo\r\n" + "– bar</p>\r\n" + "<p>— asd</p>\r\n" + "<p>– lol</p>\r\n"); free(html); } |