diff options
| author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-05-12 19:31:03 -0300 | 
|---|---|---|
| committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-05-12 19:31:03 -0300 | 
| commit | ae6443e44a2a6e242cf97d58e608e6f21dcdc464 (patch) | |
| tree | 9c02e3e5439f6040f34e5c9b61129af2a1d6e691 | |
| parent | f987424ed9954239ec0a730b721700ac58c1bf1a (diff) | |
| download | blogc-ae6443e44a2a6e242cf97d58e608e6f21dcdc464.tar.gz blogc-ae6443e44a2a6e242cf97d58e608e6f21dcdc464.tar.bz2 blogc-ae6443e44a2a6e242cf97d58e608e6f21dcdc464.zip | |
content-parser: implemented line breaks
| -rw-r--r-- | src/content-parser.c | 27 | ||||
| -rw-r--r-- | tests/check_content_parser.c | 4 | 
2 files changed, 25 insertions, 6 deletions
| diff --git a/src/content-parser.c b/src/content-parser.c index f19b800..aa4db79 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -16,14 +16,10 @@  #include "utils/utils.h"  #include "content-parser.h" -  // this is a half ass implementation of a markdown-like syntax. bugs are  // expected. feel free to improve the parser and and new features. -// TODO: inline elements: line breaks - -  typedef enum {      CONTENT_START_LINE = 1,      CONTENT_HEADER, @@ -76,6 +72,7 @@ blogc_content_parse_inline(const char *src)      char *tmp2 = NULL;      unsigned int open_bracket = 0; +    unsigned int spaces = 0;      bool escape = false; @@ -91,6 +88,9 @@ blogc_content_parse_inline(const char *src)              continue;          } +        if (c != ' ' && c != '\n' && c != '\r') +            spaces = 0; +          switch (c) {              case '\\': @@ -244,6 +244,25 @@ blogc_content_parse_inline(const char *src)                      b_string_append_c(rv, c);                  break; +            case ' ': +                if (state == 0) { +                    spaces++; +                    b_string_append_c(rv, c); +                } +                break; + +            case '\n': +            case '\r': +                if (state == 0) { +                    if (spaces >= 2) { +                        b_string_append(rv, "<br />\n"); +                        spaces = 0; +                    } +                    else +                        b_string_append_c(rv, c); +                } +                break; +              case '&':                  if (state == 0)                      b_string_append(rv, "&"); diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 49f07ba..0053051 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -33,7 +33,7 @@ test_content_parse(void **state)          "bola\n"          "chunda\n"          "\n" -        ">  bola\n" +        ">  bola  \n"          ">  guda\n"          ">  buga\n"          ">  \n" @@ -68,7 +68,7 @@ test_content_parse(void **state)          "<h6>seis</h6>\n"          "<p>bola\n"          "chunda</p>\n" -        "<blockquote><p>bola\n" +        "<blockquote><p>bola  <br />\n"          "guda\n"          "buga</p>\n"          "<pre><code>asd</code></pre>\n" | 
