From 903c8313bc1f8a1ce3d97fc944293d79ccdac76c Mon Sep 17 00:00:00 2001
From: "Rafael G. Martins" guda\n"
- "yay");
+ open_code_double = !open_code_double;
+ }
+ else {
+ if (open_code)
+ b_string_append(rv, "
");
+ else
+ b_string_append(rv, "");
+ open_code = !open_code;
+ }
+ break;
+
+ case '[':
+ if (link_state == 0 && image_state == 0) {
+ tmp = strchr(src + current, ']');
+ if (tmp != NULL) {
+ if (strlen(tmp) > 1 && tmp[1] == '(') {
+ tmp = strchr(tmp, ')');
+ if (tmp != NULL) { // this is a link
+ link_start = current + 1; // its safe
+ link_state = 1;
+ break;
+ }
+ }
+ }
+ b_string_append_c(rv, c);
+ }
+ break;
+
+ case '!':
+ if (link_state == 0 && image_state == 0) {
+ if (!is_last && src[current + 1] == '[') {
+ tmp = strchr(src + current + 1, ']');
+ if (tmp != NULL) {
+ if (strlen(tmp) > 1 && tmp[1] == '(') {
+ tmp = strchr(tmp, ')');
+ if (tmp != NULL) { // this is an image
+ image_start = current + 2; // its safe
+ image_state = 1;
+ break;
+ }
+ }
+ }
+ }
+ b_string_append_c(rv, c);
+ }
+ break;
+
+ case ']':
+ if (link_state == 1) {
+ link_state = 2;
+ title = b_strndup(src + link_start, current - link_start);
+ break;
+ }
+ if (image_state == 1) {
+ image_state = 2;
+ title = b_strndup(src + image_start, current - image_start);
+ break;
+ }
+ b_string_append_c(rv, c);
+ break;
+
+ case '(':
+ if (link_state == 2) {
+ link_state = 3;
+ link_start = current + 1; // its safe
+ break;
+ }
+ if (image_state == 2) {
+ image_state = 3;
+ image_start = current + 1; // its safe
+ break;
+ }
+ b_string_append_c(rv, c);
+ break;
+
+ case ')':
+ if (link_state == 3) {
+ link_state = 0;
+ tmp = b_strndup(src + link_start, current - link_start);
+ b_string_append_printf(rv, "%s", tmp, title);
+ free(tmp);
+ tmp = NULL;
+ free(title);
+ title = NULL;
+ break;
+ }
+ if (image_state == 3) {
+ image_state = 0;
+ tmp = b_strndup(src + image_start, current - image_start);
+ b_string_append_printf(rv, "", tmp, title);
+ free(tmp);
+ tmp = NULL;
+ free(title);
+ title = NULL;
+ break;
+ }
+ b_string_append_c(rv, c);
+ break;
+
+ case '&':
+ b_string_append(rv, "&");
+ break;
+
+ case '<':
+ b_string_append(rv, "<");
+ break;
+
+ case '>':
+ b_string_append(rv, ">");
+ break;
+
+ case '"':
+ b_string_append(rv, """);
+ break;
+
+ case '\'':
+ b_string_append(rv, "'");
+ break;
+
+ case '/':
+ b_string_append(rv, "/");
+ break;
+
+ default:
+ if (link_state == 0 && image_state == 0)
+ b_string_append_c(rv, c);
+ }
+
+ current++;
+ }
+
+ return b_string_free(rv, false);
+}
+
+
char*
blogc_content_parse(const char *src, size_t src_len, blogc_error_t **err)
{
@@ -69,6 +280,7 @@ blogc_content_parse(const char *src, size_t src_len, blogc_error_t **err)
size_t prefix_len = 0;
char *tmp = NULL;
char *tmp2 = NULL;
+ char *parsed = NULL;
char **tmpv = NULL;
char d;
@@ -150,8 +362,11 @@ blogc_content_parse(const char *src, size_t src_len, blogc_error_t **err)
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len : current;
tmp = b_strndup(src + start, end - start);
+ parsed = blogc_content_parse_inline(tmp);
b_string_append_printf(rv, "
**bola**
\n"); free(html); } @@ -319,6 +322,18 @@ test_content_parse_invalid_code(void **state) } +void +test_content_parse_inline(void **state) +{ + char *html = blogc_content_parse_inline("**bola***asd* ``chunda``"); + assert_string_equal(html, "bolaasdchunda
");
+ free(html);
+ html = blogc_content_parse_inline("*bola*");
+ assert_string_equal(html, "bola");
+ free(html);
+}
+
+
int
main(void)
{
@@ -332,6 +347,7 @@ main(void)
unit_test(test_content_parse_invalid_header_empty),
unit_test(test_content_parse_invalid_blockquote),
unit_test(test_content_parse_invalid_code),
+ unit_test(test_content_parse_inline),
};
return run_tests(tests);
}
--
cgit v1.2.3-18-g5258