diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/blogc/content-parser.c | 9 | ||||
-rw-r--r-- | src/blogc/content-parser.h | 2 | ||||
-rw-r--r-- | src/blogc/source-parser.c | 15 |
3 files changed, 21 insertions, 5 deletions
diff --git a/src/blogc/content-parser.c b/src/blogc/content-parser.c index 23586bb..415e5ee 100644 --- a/src/blogc/content-parser.c +++ b/src/blogc/content-parser.c @@ -674,7 +674,8 @@ blogc_is_ordered_list_item(const char *str, size_t prefix_len) char* -blogc_content_parse(const char *src, size_t *end_excerpt, char **description) +blogc_content_parse(const char *src, size_t *end_excerpt, char **title, + char **description) { // src is always nul-terminated. size_t src_len = strlen(src); @@ -834,6 +835,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) end = is_last && c != '\n' && c != '\r' ? src_len : (real_end != 0 ? real_end : current); tmp = bc_strndup(src + start, end - start); + if (title != NULL && *title == NULL) + *title = bc_strdup(tmp); parsed = blogc_content_parse_inline(tmp); slug = blogc_slugify(tmp); if (slug == NULL) @@ -915,10 +918,10 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) for (bc_slist_t *l = lines; l != NULL; l = l->next) bc_string_append_printf(tmp_str, "%s%s", l->data, line_ending); - // do not propagate description to blockquote parsing, + // do not propagate title and description to blockquote parsing, // because we just want paragraphs from first level of // content. - tmp = blogc_content_parse(tmp_str->str, NULL, NULL); + tmp = blogc_content_parse(tmp_str->str, NULL, NULL, NULL); bc_string_append_printf(rv, "<blockquote>%s</blockquote>%s", tmp, line_ending); free(tmp); diff --git a/src/blogc/content-parser.h b/src/blogc/content-parser.h index 37e38d7..39230c6 100644 --- a/src/blogc/content-parser.h +++ b/src/blogc/content-parser.h @@ -17,7 +17,7 @@ char* blogc_htmlentities(const char *str); char* blogc_fix_description(const char *paragraph); char* blogc_content_parse_inline(const char *src); bool blogc_is_ordered_list_item(const char *str, size_t prefix_len); -char* blogc_content_parse(const char *src, size_t *end_excerpt, +char* blogc_content_parse(const char *src, size_t *end_excerpt, char **title, char **description); #endif /* _CONTENT_PARSER_H */ diff --git a/src/blogc/source-parser.c b/src/blogc/source-parser.c index a3d1e09..f6f3471 100644 --- a/src/blogc/source-parser.c +++ b/src/blogc/source-parser.c @@ -150,8 +150,21 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err) if (current == (src_len - 1)) { tmp = bc_strndup(src + start, src_len - start); bc_trie_insert(rv, "RAW_CONTENT", tmp); + char *title = NULL; char *description = NULL; - content = blogc_content_parse(tmp, &end_excerpt, &description); + content = blogc_content_parse(tmp, &end_excerpt, &title, + &description); + if (title != NULL) { + // do not override source-provided title. + if (NULL == bc_trie_lookup(rv, "TITLE")) { + // no need to free, because we are transfering memory + // ownership to the trie. + bc_trie_insert(rv, "TITLE", title); + } + else { + free(title); + } + } if (description != NULL) { // do not override source-provided description. if (NULL == bc_trie_lookup(rv, "DESCRIPTION")) { |