diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-04-17 04:01:51 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-04-17 04:01:51 +0200 |
commit | 001c16ac605ee65f5688534e42c10395db3f0d5a (patch) | |
tree | 443f20ad78210851147c5484877cfd827164a09a | |
parent | 6a19a55497730354f0545fbaf3ce99b4d942dbb7 (diff) | |
download | blogc-001c16ac605ee65f5688534e42c10395db3f0d5a.tar.gz blogc-001c16ac605ee65f5688534e42c10395db3f0d5a.tar.bz2 blogc-001c16ac605ee65f5688534e42c10395db3f0d5a.zip |
content-parser: do not convert -- and --- to &ndash and &mdash inside code
-rw-r--r-- | src/content-parser.c | 4 | ||||
-rw-r--r-- | tests/check_content_parser.c | 31 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/content-parser.c b/src/content-parser.c index 0a87fcb..782a85d 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -364,7 +364,9 @@ blogc_content_parse_inline(const char *src) case '-': if (state != LINK_CLOSED) break; - if (current < (src_len - 1) && src[current + 1] == '-') { + if ((current < (src_len - 1) && src[current + 1] == '-') && + !(open_code || open_code_double)) + { if (current < (src_len - 2) && src[current + 2] == '-') { sb_string_append(rv, "—"); current += 2; diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index b20f8d0..ea3a9a2 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1751,6 +1751,36 @@ test_content_parse_inline_line_break_crlf(void **state) } +static void +test_content_parse_inline_endash_emdash(void **state) +{ + char *html = blogc_content_parse_inline("foo -- bar"); + assert_non_null(html); + assert_string_equal(html, "foo – bar"); + free(html); + html = blogc_content_parse_inline("foo --- bar"); + assert_non_null(html); + assert_string_equal(html, "foo — bar"); + free(html); + html = blogc_content_parse_inline("`foo -- bar`"); + assert_non_null(html); + assert_string_equal(html, "<code>foo -- bar</code>"); + free(html); + html = blogc_content_parse_inline("`foo --- bar`"); + assert_non_null(html); + assert_string_equal(html, "<code>foo --- bar</code>"); + free(html); + html = blogc_content_parse_inline("``foo -- bar``"); + assert_non_null(html); + assert_string_equal(html, "<code>foo -- bar</code>"); + free(html); + html = blogc_content_parse_inline("``foo --- bar``"); + assert_non_null(html); + assert_string_equal(html, "<code>foo --- bar</code>"); + free(html); +} + + int main(void) { @@ -1793,6 +1823,7 @@ main(void) unit_test(test_content_parse_inline_image), unit_test(test_content_parse_inline_line_break), unit_test(test_content_parse_inline_line_break_crlf), + unit_test(test_content_parse_inline_endash_emdash), }; return run_tests(tests); } |