aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-06-13 03:32:21 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-06-13 03:32:21 -0300
commit3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90 (patch)
treebc7a75a51d2fbf180c9d63ee1164b93ca21b9b6f /src
parent168de93a068e489eb96c541172de5e43e13a5873 (diff)
downloadblogc-3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90.tar.gz
blogc-3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90.tar.bz2
blogc-3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90.zip
content-parser: implemented excerpt, and now for good!
Diffstat (limited to 'src')
-rw-r--r--src/content-parser.c41
-rw-r--r--src/content-parser.h2
-rw-r--r--src/source-parser.c9
3 files changed, 48 insertions, 4 deletions
diff --git a/src/content-parser.c b/src/content-parser.c
index aa76777..fa17ab8 100644
--- a/src/content-parser.c
+++ b/src/content-parser.c
@@ -22,6 +22,8 @@
typedef enum {
CONTENT_START_LINE = 1,
+ CONTENT_EXCERPT,
+ CONTENT_EXCERPT_END,
CONTENT_HEADER,
CONTENT_HEADER_TITLE_START,
CONTENT_HEADER_TITLE,
@@ -355,7 +357,7 @@ blogc_content_parse_inline(const char *src)
char*
-blogc_content_parse(const char *src)
+blogc_content_parse(const char *src, size_t *end_excerpt)
{
// src is always nul-terminated.
size_t src_len = strlen(src);
@@ -364,6 +366,7 @@ blogc_content_parse(const char *src)
size_t start = 0;
size_t start2 = 0;
size_t end = 0;
+ size_t eend = 0;
unsigned int header_level = 0;
char *prefix = NULL;
@@ -393,6 +396,13 @@ blogc_content_parse(const char *src)
if (c == '\n' || c == '\r' || is_last)
break;
start = current;
+ if (c == '.') {
+ if (end_excerpt != NULL) {
+ eend = rv->len; // fuck it
+ state = CONTENT_EXCERPT;
+ break;
+ }
+ }
if (c == '#') {
header_level = 1;
state = CONTENT_HEADER;
@@ -426,6 +436,33 @@ blogc_content_parse(const char *src)
state = CONTENT_PARAGRAPH;
break;
+ case CONTENT_EXCERPT:
+ if (end_excerpt != NULL) {
+ if (c == '.')
+ break;
+ if (c == '\n' || c == '\r') {
+ //*end_excerpt = eend;
+ //state = CONTENT_START_LINE;
+ state = CONTENT_EXCERPT_END;
+ break;
+ }
+ }
+ eend = 0;
+ state = CONTENT_PARAGRAPH;
+ break;
+
+ case CONTENT_EXCERPT_END:
+ if (end_excerpt != NULL) {
+ if (c == '\n' || c == '\r') {
+ *end_excerpt = eend;
+ state = CONTENT_START_LINE;
+ break;
+ }
+ }
+ eend = 0;
+ state = CONTENT_PARAGRAPH_END;
+ break;
+
case CONTENT_HEADER:
if (c == '#') {
header_level += 1;
@@ -521,7 +558,7 @@ blogc_content_parse(const char *src)
else
b_string_append_printf(tmp_str, "%s\n", l->data);
}
- tmp = blogc_content_parse(tmp_str->str);
+ tmp = blogc_content_parse(tmp_str->str, NULL);
b_string_append_printf(rv, "<blockquote>%s</blockquote>\n",
tmp);
free(tmp);
diff --git a/src/content-parser.h b/src/content-parser.h
index d0a0732..ec441c6 100644
--- a/src/content-parser.h
+++ b/src/content-parser.h
@@ -13,6 +13,6 @@
#include "error.h"
char* blogc_content_parse_inline(const char *src);
-char* blogc_content_parse(const char *src);
+char* blogc_content_parse(const char *src, size_t *end_excerpt);
#endif /* _CONTENT_PARSER_H */
diff --git a/src/source-parser.c b/src/source-parser.c
index f0fca29..050082f 100644
--- a/src/source-parser.c
+++ b/src/source-parser.c
@@ -38,6 +38,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
size_t current = 0;
size_t start = 0;
+ size_t end_excerpt = 0;
char *key = NULL;
char *tmp = NULL;
@@ -148,7 +149,13 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
if (current == (src_len - 1)) {
tmp = b_strndup(src + start, src_len - start);
b_trie_insert(rv, "RAW_CONTENT", tmp);
- b_trie_insert(rv, "CONTENT", blogc_content_parse(tmp));
+ b_trie_insert(rv, "CONTENT", blogc_content_parse(tmp, &end_excerpt));
+ if (end_excerpt != 0)
+ b_trie_insert(rv, "EXCERPT",
+ b_strndup(b_trie_lookup(rv, "CONTENT"), end_excerpt));
+ else
+ b_trie_insert(rv, "EXCERPT",
+ b_strdup(b_trie_lookup(rv, "CONTENT")));
}
break;
}