From: Dan Brown Date: Sun, 14 Nov 2021 12:17:22 +0000 (+0000) Subject: Fixed issue where markdown drafts showed as HTML X-Git-Tag: v21.11~1^2~15 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/8e71cd9bacfc12c50d1f9ed9ca379b85beece940 Fixed issue where markdown drafts showed as HTML Markdown content was not being stored, only the sent HTML representation, causing the draft to show as HTML upon next edit. Added test to cover. Fixes #3054 --- diff --git a/app/Entities/Repos/PageRepo.php b/app/Entities/Repos/PageRepo.php index 98fe4ef55..f66f2beb8 100644 --- a/app/Entities/Repos/PageRepo.php +++ b/app/Entities/Repos/PageRepo.php @@ -252,9 +252,7 @@ class PageRepo { // If the page itself is a draft simply update that if ($page->draft) { - if (isset($input['html'])) { - (new PageContent($page))->setNewHTML($input['html']); - } + $this->updateTemplateStatusAndContentFromInput($page, $input); $page->fill($input); $page->save(); diff --git a/tests/Entity/PageDraftTest.php b/tests/Entity/PageDraftTest.php index 9e2ceff51..ec6707bc5 100644 --- a/tests/Entity/PageDraftTest.php +++ b/tests/Entity/PageDraftTest.php @@ -178,4 +178,30 @@ class PageDraftTest extends TestCase 'html' => $page->html, ]); } + + public function test_updating_page_draft_with_markdown_retains_markdown_content() + { + /** @var Book $book */ + $book = Book::query()->first(); + $this->asEditor()->get($book->getUrl('/create-page')); + /** @var Page $draft */ + $draft = Page::query()->where('draft', '=', true)->where('book_id', '=', $book->id)->firstOrFail(); + + $resp = $this->put('/ajax/page/' . $draft->id . '/save-draft', [ + 'name' => 'My updated draft', + 'markdown' => "# My markdown page\n\n[A link](https://example.com)", + 'html' => '

checking markdown takes priority over this

' + ]); + $resp->assertOk(); + + $this->assertDatabaseHas('pages', [ + 'id' => $draft->id, + 'draft' => true, + 'name' => 'My updated draft', + 'markdown' => "# My markdown page\n\n[A link](https://example.com)", + ]); + + $draft->refresh(); + $this->assertStringContainsString('href="https://example.com"', $draft->html); + } }