From 3c5f86c3de72ffe08ce8dde6d2dee38b4f3f13d2 Mon Sep 17 00:00:00 2001 From: swaggboi Date: Fri, 4 Apr 2025 21:49:28 -0400 Subject: [PATCH] Implement preview for markdown and plain text thread --- README.md | 1 + lib/PostText/Controller/Thread.pm | 4 +--- templates/thread/create.html.ep | 8 ++++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8828004..acf174d 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ tests locally: ## TODOs +- Non-markdown posts will need to handle whitespace/newlines with CSS stuff - Do I need `SUM` for `by_id()`? ## AGPL-3.0+ANTIFA compliance diff --git a/lib/PostText/Controller/Thread.pm b/lib/PostText/Controller/Thread.pm index 0c094d2..b1bda04 100644 --- a/lib/PostText/Controller/Thread.pm +++ b/lib/PostText/Controller/Thread.pm @@ -36,8 +36,6 @@ sub create($self) { $self->session(author => $thread_author); - print $self->dumper($v); - unless ($preview) { my $new_thread_id = $self->thread->create( $thread_author, @@ -51,7 +49,7 @@ sub create($self) { ); } - $draft = $thread_body; + $draft = {body => $thread_body, markdown => $markdown}; } } diff --git a/templates/thread/create.html.ep b/templates/thread/create.html.ep index 74664de..07f7824 100644 --- a/templates/thread/create.html.ep +++ b/templates/thread/create.html.ep @@ -11,9 +11,13 @@ % end

<%= title %>

- <% if ($draft) { =%> + <% if (keys %{$draft}) { =%>
- <%== markdown $draft =%> + <% if ($draft->{'markdown'}) { =%> + <%== markdown $draft->{'body'} =%> + <% } else { =%> + <%= $draft->{'body'} =%> + <% } =%>
<% } =%>