summaryrefslogtreecommitdiff
path: root/journal.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2018-09-11 21:11:43 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2018-09-11 21:11:43 -0700
commitdefc7571e7b261a2e8bc63f45b9472ccb81379b7 (patch)
tree559567abe441d37c133b6cb87d4a9c56eddf0419 /journal.c
parenta88200d28236506be5e38c31872fe8f97a7877ff (diff)
downloadjournal-defc7571e7b261a2e8bc63f45b9472ccb81379b7.tar.gz
journal-defc7571e7b261a2e8bc63f45b9472ccb81379b7.tar.xz
add support for line breaks within paragraphs
Diffstat (limited to 'journal.c')
-rw-r--r--journal.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/journal.c b/journal.c
index 7507444..4a07261 100644
--- a/journal.c
+++ b/journal.c
@@ -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>&emsp;", 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);