]> BookStack Code Mirror - bookstack/commitdiff
MD Exports: Added HTML description conversion
authorDan Brown <redacted>
Mon, 2 Dec 2024 11:46:56 +0000 (11:46 +0000)
committerDan Brown <redacted>
Mon, 2 Dec 2024 11:46:56 +0000 (11:46 +0000)
Also updated tests to cover checking description use/conversion.
Made during review of #5313

app/Entities/Tools/ExportFormatter.php
tests/Entity/ExportTest.php

index e85992a9d70ef0909b1789b06e4b3d10c58102f3..0af68b8db3cfcd3f4f9957c0a949259a2144593b 100644 (file)
@@ -316,8 +316,9 @@ class ExportFormatter
     {
         $text = '# ' . $chapter->name . "\n\n";
 
-        if (!empty($chapter->description)) {
-            $text .= $chapter->description . "\n\n";
+        $description = (new HtmlToMarkdown($chapter->descriptionHtml()))->convert();
+        if ($description) {
+            $text .= $description . "\n\n";
         }
 
         foreach ($chapter->pages as $page) {
@@ -334,9 +335,10 @@ class ExportFormatter
     {
         $bookTree = (new BookContents($book))->getTree(false, true);
         $text = '# ' . $book->name . "\n\n";
-        
-        if (!empty($book->description)) {
-            $text .= $book->description . "\n\n";
+
+        $description = (new HtmlToMarkdown($book->descriptionHtml()))->convert();
+        if ($description) {
+            $text .= $description . "\n\n";
         }
 
         foreach ($bookTree as $bookChild) {
index 7aafa3b79277414cdcca202dfd1c17732b81cb2a..97b1ff1bcfde86883c5bfc99b7dc75cac6d5bf23 100644 (file)
@@ -417,23 +417,35 @@ class ExportTest extends TestCase
     public function test_chapter_markdown_export()
     {
         $chapter = $this->entities->chapter();
+        $chapter->description_html = '<p>My <strong>chapter</strong> description</p>';
+        $chapter->save();
         $page = $chapter->pages()->first();
+
         $resp = $this->asEditor()->get($chapter->getUrl('/export/markdown'));
 
         $resp->assertSee('# ' . $chapter->name);
         $resp->assertSee('# ' . $page->name);
+        $resp->assertSee('My **chapter** description');
     }
 
     public function test_book_markdown_export()
     {
         $book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
+        $book->description_html = '<p>My <strong>book</strong> description</p>';
+        $book->save();
+
         $chapter = $book->chapters()->first();
+        $chapter->description_html = '<p>My <strong>chapter</strong> description</p>';
+        $chapter->save();
+
         $page = $chapter->pages()->first();
         $resp = $this->asEditor()->get($book->getUrl('/export/markdown'));
 
         $resp->assertSee('# ' . $book->name);
         $resp->assertSee('# ' . $chapter->name);
         $resp->assertSee('# ' . $page->name);
+        $resp->assertSee('My **book** description');
+        $resp->assertSee('My **chapter** description');
     }
 
     public function test_book_markdown_export_concats_immediate_pages_with_newlines()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.