aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-03-05 19:35:16 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-03-05 19:35:16 +0100
commit2bfe68f6f9fdd34588b8dde73c1a4e96c5a54b7d (patch)
tree20ae4f90da8c3397161a6d137b953a378022df6f
parentf7034a9c4e26933bceb9b80c6ef492b731df3d73 (diff)
downloadblogc-2bfe68f6f9fdd34588b8dde73c1a4e96c5a54b7d.tar.gz
blogc-2bfe68f6f9fdd34588b8dde73c1a4e96c5a54b7d.tar.bz2
blogc-2bfe68f6f9fdd34588b8dde73c1a4e96c5a54b7d.zip
content-parser: convert -- and --- to &ndash and &mdash
-rw-r--r--src/content-parser.c15
-rw-r--r--tests/check_content_parser.c32
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, "&ndash;");
+ current += 2;
+ }
+ else {
+ sb_string_append(rv, "&mdash;");
+ current += 1;
+ }
+ }
+ break;
+
case '&':
if (state == LINK_CLOSED)
sb_string_append(rv, "&amp;");
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"
+ "&mdash; foo\n"
+ "&ndash; bar</p>\n"
+ "<p>&mdash; asd</p>\n"
+ "<p>&ndash; 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"
+ "&mdash; foo\r\n"
+ "&ndash; bar</p>\r\n"
+ "<p>&mdash; asd</p>\r\n"
+ "<p>&ndash; lol</p>\r\n");
free(html);
}