diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-06-13 03:32:21 -0300 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-06-13 03:32:21 -0300 |
commit | 3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90 (patch) | |
tree | bc7a75a51d2fbf180c9d63ee1164b93ca21b9b6f /src/content-parser.c | |
parent | 168de93a068e489eb96c541172de5e43e13a5873 (diff) | |
download | blogc-3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90.tar.gz blogc-3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90.tar.bz2 blogc-3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90.zip |
content-parser: implemented excerpt, and now for good!
Diffstat (limited to 'src/content-parser.c')
-rw-r--r-- | src/content-parser.c | 41 |
1 files changed, 39 insertions, 2 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); |