diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2018-09-11 21:11:43 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2018-09-11 21:11:43 -0700 |
commit | defc7571e7b261a2e8bc63f45b9472ccb81379b7 (patch) | |
tree | 559567abe441d37c133b6cb87d4a9c56eddf0419 /journal.c | |
parent | a88200d28236506be5e38c31872fe8f97a7877ff (diff) | |
download | journal-defc7571e7b261a2e8bc63f45b9472ccb81379b7.tar.gz journal-defc7571e7b261a2e8bc63f45b9472ccb81379b7.tar.xz |
add support for line breaks within paragraphs
Diffstat (limited to 'journal.c')
-rw-r--r-- | journal.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -41,11 +41,18 @@ static void print_entry(char *entry) { strftime(date, sizeof(date), "%Y/%m/%d", localtime(&time)); printf("<div class='entry'><p><span class='date'>%s</span> ", date); - for (int p = getc(f), c = getc(f); p != EOF; p = c, c = getc(f)) { - if (p != '\n') - putchar(p); - else if (c != '\n' && c != EOF) - printf("</p><p>"); + for (int c = getc(f), nl = 0; c != EOF; c = getc(f)) { + if (c == '\n') { + ++nl; + continue; + } + + if (nl > 0) { + printf(nl == 1 ? "<br>" : "<p></p>"); + nl = 0; + } + + putchar(c); } fclose(f); |