diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-05-06 03:37:51 -0300 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-05-06 03:37:51 -0300 |
commit | 6465244e540966e6639939b41e0290481b54567d (patch) | |
tree | 1bee2a6b95a04a2d298872a757b6e9fbba9a9a9e | |
parent | 927fb000a76a9f70f229b222f89be34af38bd78c (diff) | |
download | blogc-6465244e540966e6639939b41e0290481b54567d.tar.gz blogc-6465244e540966e6639939b41e0290481b54567d.tar.bz2 blogc-6465244e540966e6639939b41e0290481b54567d.zip |
content-parser: do not parse content inside code
-rw-r--r-- | src/content-parser.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/content-parser.c b/src/content-parser.c index 676da8b..23c8647 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -22,9 +22,7 @@ // expected. feel free to improve the parser and and new features. -// TODO: inline elements: links, emphasis, code, images, line breaks -// TODO: automatic scaping of html entities -// TODO: automatic links +// TODO: inline elements: line breaks // TODO: error handling @@ -78,6 +76,7 @@ blogc_content_parse_inline(const char *src) char *tmp = NULL; char *title = NULL; + char *alt = NULL; while (current < src_len) { char c = src[current]; @@ -86,6 +85,10 @@ blogc_content_parse_inline(const char *src) switch (c) { case '*': case '_': + if (open_code || open_code_double) { + b_string_append_c(rv, c); + break; + } if (!is_last && src[current + 1] == c) { current++; if ((c == '*' && open_strong_ast) || @@ -142,6 +145,10 @@ blogc_content_parse_inline(const char *src) break; case '[': + if (open_code || open_code_double) { + b_string_append_c(rv, c); + break; + } if (link_state == 0 && image_state == 0) { tmp = strchr(src + current, ']'); if (tmp != NULL) { @@ -159,6 +166,10 @@ blogc_content_parse_inline(const char *src) break; case '!': + if (open_code || open_code_double) { + b_string_append_c(rv, c); + break; + } if (link_state == 0 && image_state == 0) { if (!is_last && src[current + 1] == '[') { tmp = strchr(src + current + 1, ']'); @@ -178,6 +189,10 @@ blogc_content_parse_inline(const char *src) break; case ']': + if (open_code || open_code_double) { + b_string_append_c(rv, c); + break; + } if (link_state == 1) { link_state = 2; title = b_strndup(src + link_start, current - link_start); @@ -185,13 +200,17 @@ blogc_content_parse_inline(const char *src) } if (image_state == 1) { image_state = 2; - title = b_strndup(src + image_start, current - image_start); + alt = b_strndup(src + image_start, current - image_start); break; } b_string_append_c(rv, c); break; case '(': + if (open_code || open_code_double) { + b_string_append_c(rv, c); + break; + } if (link_state == 2) { link_state = 3; link_start = current + 1; // its safe @@ -206,6 +225,10 @@ blogc_content_parse_inline(const char *src) break; case ')': + if (open_code || open_code_double) { + b_string_append_c(rv, c); + break; + } if (link_state == 3) { link_state = 0; tmp = b_strndup(src + link_start, current - link_start); @@ -219,11 +242,11 @@ blogc_content_parse_inline(const char *src) if (image_state == 3) { image_state = 0; tmp = b_strndup(src + image_start, current - image_start); - b_string_append_printf(rv, "<img src=\"%s\" alt=\"%s\">", tmp, title); + b_string_append_printf(rv, "<img src=\"%s\" alt=\"%s\">", tmp, alt); free(tmp); tmp = NULL; - free(title); - title = NULL; + free(alt); + alt = NULL; break; } b_string_append_c(rv, c); |